doxify missing bits
[paraslash.git] / sched.h
1 /*
2  * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 /** \file sched.h sched and task structures and exported symbols from sched.c */
20
21
22 /**
23  * paraslash's scheduler
24  *
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.
28  */
29 struct sched {
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 */
35         fd_set rfds;
36         /** fds that should be watched for writability */
37         fd_set wfds;
38         /** highest numbered file descriptor in any of the above fd sets */
39         int max_fileno;
40         /** the return value of the previous select call */
41         int select_ret;
42 };
43
44 /**
45  * paraslash's task structure
46  *
47  * before registering a task to the scheduler, the task structure must be
48  * filled in properly by the caller.
49  *
50  * If one of these functions return a negative value via \a t->ret the
51  * (optional) event_handler gets called (it may also be called in case another
52  * event happend). In many cases the only possible event is an error or an eof
53  * condition and the event handler simply unregisters the task from the
54  * scheduler.
55  *
56  * \sa struct sched
57  */
58 struct task {
59         /** pointer to the struct this task is embedded in */
60         void *private_data;
61         /**
62          * the pre select hook of \a t
63          *
64          * Its purpose is to add file descriptors to the fd sets of the
65          * scheduler and to decrease the select timeout if neccessary.
66          */
67         void (*pre_select)(struct sched *s, struct task *t);
68         /**
69          * the postselect hook of \a t
70          *
71          * evaluate and act upon the results of the previous select call.
72          */
73         void (*post_select)(struct sched *s, struct task *t);
74         /** gets called if pre_select or post_select returned an error */
75         void (*event_handler)(struct task *t);
76         /** pre_select() and post_select store their return value here */
77         int ret;
78         /** position of the task in the pre_select list of the scheduler */
79         struct list_head pre_select_node;
80         /** position of the task in the post_select list of the scheduler */
81         struct list_head post_select_node;
82         /** descriptive text and current status of the task */
83         char status[MAXLINE];
84 };
85
86 /**
87  * This is set by the scheduler at the beginning of its main loop.  It may be
88  * used (read-only) from everywhere. As none of the functions called by the
89  * scheduler are allowed to block, this value should be accurate enough so that
90  * there is no need to call gettimeofday() directly.
91  */
92 extern struct timeval *now;
93
94 void register_task(struct task *t);
95 void unregister_task(struct task *t);
96 int sched(struct sched *s);
97 void init_sched(void);
98 char *get_task_list(void);
99 int kill_task(char *id);