2 * Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file sched.h Sched and task structures and exported symbols from sched.c. */
11 * Paraslash's scheduler.
13 * Designed with KISS in mind. It maintains a list of task structures which is
14 * extended when a new task is registered. Each task may define a pre_select
15 * function which is called from the scheduler main loop before it calls
16 * select(). Similarly, each task must define a post_select function which is
17 * called after the select call.
20 /** Initial value before any pre_select call. */
21 struct timeval default_timeout;
22 /** The current timeout for the upcoming select call. */
23 struct timeval select_timeout;
24 /** fds that should be watched for readability. */
26 /** fds that should be watched for writability. */
28 /** Highest numbered file descriptor in any of the above fd sets. */
30 /** If non-NULL, use this function instead of para_select. */
31 int (*select_function)(int, fd_set *, fd_set *, struct timeval *);
32 /** Tasks which have been registered to the scheduler. */
33 struct list_head task_list;
38 /** Information that must be supplied by callers of \ref task_register(). */
40 /** Used for log messages and by \ref get_task_list(). */
43 * The optional pre select method.
45 * Its purpose is to add file descriptors to the fd sets of the
46 * scheduler and to decrease the select timeout if necessary.
48 void (*pre_select)(struct sched *s, void *context);
50 * The mandatory post select method.
52 * Its purpose is to evaluate and act upon the results of the previous
53 * select call. If this function returns a negative value, the
54 * scheduler unregisters the task.
56 int (*post_select)(struct sched *s, void *context);
58 * This pointer is saved when the task is registered. It is passed to
59 * ->pre_select() and ->post_select(). Usually this is a pointer to the
60 * struct owned by the caller which contains the task pointer.
66 * This is set by the scheduler at the beginning of its main loop. It may be
67 * used (read-only) from everywhere. As none of the functions called by the
68 * scheduler are allowed to block, this value should be accurate enough so that
69 * there is no need to call clock_gettime() directly.
71 extern const struct timeval *now;
73 struct task *task_register(struct task_info *info, struct sched *s);
74 int schedule(struct sched *s);
75 void sched_shutdown(struct sched *s);
76 char *get_task_list(struct sched *s);
77 void task_notify(struct task *t, int err);
78 void task_notify_all(struct sched *s, int err);
79 int task_get_notification(const struct task *t);
80 int task_status(const struct task *t);
81 int task_reap(struct task **tptr);
82 void sched_min_delay(struct sched *s);
83 void sched_request_timeout(struct timeval *to, struct sched *s);
84 void sched_request_timeout_ms(long unsigned ms, struct sched *s);
85 int sched_request_barrier(struct timeval *barrier, struct sched *s);
86 int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);