server: Update status items on file renames.
[paraslash.git] / sched.h
1 /* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2
3 /** \file sched.h Sched and task structures and exported symbols from sched.c. */
4
5
6 /**
7 * Paraslash's scheduler.
8 *
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.
14 */
15 struct sched {
16 /** Initial value before any pre_select call. */
17 struct timeval default_timeout;
18 /** The current timeout for the upcoming select call. */
19 struct timeval select_timeout;
20 /** fds that should be watched for readability. */
21 fd_set rfds;
22 /** fds that should be watched for writability. */
23 fd_set wfds;
24 /** Highest numbered file descriptor in any of the above fd sets. */
25 int max_fileno;
26 /** If non-NULL, use this function instead of para_select. */
27 int (*select_function)(int, fd_set *, fd_set *, struct timeval *);
28 /** Tasks which have been registered to the scheduler. */
29 struct list_head task_list;
30 };
31
32 struct task;
33
34 /** Information that must be supplied by callers of \ref task_register(). */
35 struct task_info {
36 /** Used for log messages and by \ref get_task_list(). */
37 const char *name;
38 /**
39 * The optional pre select method.
40 *
41 * Its purpose is to add file descriptors to the fd sets of the
42 * scheduler and to decrease the select timeout if necessary.
43 */
44 void (*pre_select)(struct sched *s, void *context);
45 /**
46 * The mandatory post select method.
47 *
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.
51 */
52 int (*post_select)(struct sched *s, void *context);
53 /**
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.
57 */
58 void *context;
59 };
60
61 /**
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.
66 */
67 extern const struct timeval *now;
68
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);