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.h sched and task structures and exported symbols from sched.c */
23 * paraslash's scheduler
25 * desinged with KISS in mind. It manages two lists of tasks. The pre_select
26 * list contains pointers to functions that are called before calling select()
27 * from the main loop. Similarly, \a post_select_list is a list of function
28 * pointers each of which is called after the select call. Tasks add hooks to
29 * these lists by registering themselves to the scheduler.
32 /** initial value before any pre_select call */
33 struct timeval default_timeout;
34 /** the current timeout for the upcoming select call */
35 struct timeval timeout;
36 /** fds that should be watched for readability */
38 /** fds that should be watched for writability */
40 /** highest numbered file descriptor in any of the above fd sets */
42 /** the return value of the previous select call */
47 * paraslash's task structure
49 * before registering a task to the scheduler, the task structure must be
50 * filled in properly by the caller.
52 * If one of these functions return a negative value via \a t->ret the
53 * (optional) event_handler gets called (it may also be called in case another
54 * event happend). In many cases the only possible event is an error or an eof
55 * condition and the event handler simply unregisters the task from the
61 /** pointer to the struct this task is embedded in */
64 * the pre select hook of \a t
66 * Its purpose is to add file descriptors to the fd sets of the
67 * scheduler and to decrease the select timeout if neccessary.
69 void (*pre_select)(struct sched *s, struct task *t);
71 * the postselect hook of \a t
73 * evaluate and act upon the results of the previous select call.
75 void (*post_select)(struct sched *s, struct task *t);
76 /** gets called if pre_select or post_select returned an error */
77 void (*event_handler)(struct task *t);
78 /** pre_select() and post_select store their return value here */
80 /** position of the task in the pre_select list of the scheduler */
81 struct list_head pre_select_node;
82 /** position of the task in the post_select list of the scheduler */
83 struct list_head post_select_node;
84 /** descriptive text and current status of the task */
89 * This is set by the scheduler at the beginning of its main loop. It may be
90 * used (read-only) from everywhere. As none of the functions called by the
91 * scheduler are allowed to block, this value should be accurate enough so that
92 * there is no need to call gettimeofday() directly.
94 extern struct timeval *now;
96 void register_task(struct task *t);
97 void unregister_task(struct task *t);
98 int sched(struct sched *s);
99 char *get_task_list(void);
100 int kill_task(char *id);