2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file sched.c Paraslash's task and scheduling functions */
23 * paraslash's scheduler
25 * desinged with KISS in mind. It maintains two lists: The pre_select list
26 * and the post_select list. Tasks add hokks to these lists by registering
27 * themselves to the scheduler.
30 /** initial value before any pre_select call */
31 struct timeval default_timeout
;
32 /** the current timeout for the upcoming select call */
33 struct timeval timeout
;
34 /** fds that should be watched for readability */
36 /** fds that should be watched for writability */
38 /** highest numbered file descriptor in any of the above fd sets */
40 /** the return value of the previous select call */
45 * paraslash's task structure
47 * before registering a task to the scheduler, the task structure must be
48 * filled in properly by the caller.
50 * The pre_select or the post_select pointer, but not both may be NULL. Once
51 * a task is registered, its pre_select and post_select function gets called
52 * from the scheduler's mainloop. The purpose of the pre_select loop is to add
53 * file descriptors to the fd sets of the scheduler and to decrease the select
54 * timeout if neccessary. The post_select function may then evaluate these fd
55 * sets and act upon the results.
57 * If one of these functions return a negative value via \a t->ret the
58 * (optional) event_handler gets called (it may also be called in case another
59 * event happend). In many cases the only possible event is an error or an eof
60 * condition and the event handler simply unregisters the task from the
66 /** pointer to the struct this task is embedded in */
68 /** pre_select hook */
69 void (*pre_select
)(struct sched
*s
, struct task
*t
);
70 /** post_select hook */
71 void (*post_select
)(struct sched
*s
, struct task
*t
);
73 void (*event_handler
)(struct task
*t
);
74 /** pre_select() and post_select store their return value here */
76 /** position of the task in the pre_select list of the scheduler */
77 struct list_head pre_select_node
;
78 /** position of the task in the post_select list of the scheduler */
79 struct list_head post_select_node
;
80 /** descriptive text and current status of the task */
85 * This is set by the scheduler at the beginning of its main loop. It may be
86 * used (read-only) from everywhere. As none of the functions called by the
87 * scheduler are allowed to block, this value should be accurate enough so that
88 * there is no need to call gettimeofday() directly.
90 extern struct timeval
*now
;
92 void *register_task(struct task
*t
);
93 void unregister_task(struct task
*t
);
94 int sched(struct sched
*s
);
95 void init_sched(void);
96 char *get_task_list(void);
97 int kill_task(char *id
);