1 /* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file sched.h Sched and task structures and exported symbols from sched.c. */
7 * Paraslash's scheduler.
9 * Designed with KISS in mind. It maintains a list of task structures which is
10 * extended when a new task is registered. Each task may define a pre_select
11 * function which is called from the scheduler main loop before it calls
12 * select(). Similarly, each task must define a post_select function which is
13 * called after the select call.
16 /** Initial value (in milliseconds) before any pre_select call. */
18 /** The timeout (also in milliseconds) for the next select call. */
20 /** fds that should be watched for readability. */
22 /** fds that should be watched for writability. */
24 /** Highest numbered file descriptor in any of the above fd sets. */
26 /** If non-NULL, use this function instead of para_select. */
27 int (*select_function)(int, fd_set *, fd_set *, int timeout);
28 /** Tasks which have been registered to the scheduler. */
29 struct list_head task_list;
34 /** Information that must be supplied by callers of \ref task_register(). */
36 /** Used for log messages and by \ref get_task_list(). */
39 * The optional pre select method.
41 * Its purpose is to add file descriptors to the fd sets of the
42 * scheduler and to decrease the select timeout if necessary.
44 void (*pre_select)(struct sched *s, void *context);
46 * The mandatory post select method.
48 * Its purpose is to evaluate and act upon the results of the previous
49 * select call. If this function returns a negative value, the
50 * scheduler unregisters the task.
52 int (*post_select)(struct sched *s, void *context);
54 * This pointer is saved when the task is registered. It is passed to
55 * ->pre_select() and ->post_select(). Usually this is a pointer to the
56 * struct owned by the caller which contains the task pointer.
62 * This is set by the scheduler at the beginning of its main loop. It may be
63 * used (read-only) from everywhere. As none of the functions called by the
64 * scheduler are allowed to block, this value should be accurate enough so that
65 * there is no need to call clock_gettime() directly.
67 extern const struct timeval *now;
69 struct task *task_register(struct task_info *info, struct sched *s);
70 int schedule(struct sched *s);
71 void sched_shutdown(struct sched *s);
72 char *get_task_list(struct sched *s);
73 void task_notify(struct task *t, int err);
74 void task_notify_all(struct sched *s, int err);
75 int task_get_notification(const struct task *t);
76 int task_status(const struct task *t);
77 int task_reap(struct task **tptr);
78 void sched_min_delay(struct sched *s);
79 void sched_request_timeout(struct timeval *to, struct sched *s);
80 void sched_request_timeout_ms(long unsigned ms, struct sched *s);
81 int sched_request_barrier(struct timeval *barrier, struct sched *s);
82 int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);