2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
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 manages two lists of tasks. The pre_select
14 * list contains pointers to functions that are called before calling select()
15 * from the main loop. Similarly, \a post_select_list is a list of function
16 * pointers each of which is called after the select call. Tasks add hooks to
17 * these lists by registering themselves to the scheduler.
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 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 /** the return value of the previous select call */
35 * paraslash's task structure
37 * before registering a task to the scheduler, the task structure must be
38 * filled in properly by the caller.
40 * If one of these functions return a negative value via \a t->ret the
41 * (optional) event_handler gets called (it may also be called in case another
42 * event happened). In many cases the only possible event is an error or an eof
43 * condition and the event handler simply unregisters the task from the
49 /** pointer to the struct this task is embedded in */
52 * the pre select hook of \a t
54 * Its purpose is to add file descriptors to the fd sets of the
55 * scheduler and to decrease the select timeout if necessary.
57 void (*pre_select
)(struct sched
*s
, struct task
*t
);
59 * the postselect hook of \a t
61 * evaluate and act upon the results of the previous select call.
63 void (*post_select
)(struct sched
*s
, struct task
*t
);
64 /** gets called if pre_select or post_select returned an error */
65 void (*event_handler
)(struct task
*t
);
66 /** pre_select() and post_select store their return value here */
68 /** position of the task in the pre_select list of the scheduler */
69 struct list_head pre_select_node
;
70 /** position of the task in the post_select list of the scheduler */
71 struct list_head post_select_node
;
72 /** descriptive text and current status of the task */
77 * This is set by the scheduler at the beginning of its main loop. It may be
78 * used (read-only) from everywhere. As none of the functions called by the
79 * scheduler are allowed to block, this value should be accurate enough so that
80 * there is no need to call gettimeofday() directly.
82 extern struct timeval
*now
;
84 void register_task(struct task
*t
);
85 void unregister_task(struct task
*t
);
86 int schedule(struct sched
*s
);
87 char *get_task_list(void);
88 int kill_task(char *id
);