2 * Copyright (C) 2006-2011 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 select_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 /** If non-NULL, use this function instead of para_select. */
31 int (*select_function)(int, fd_set *, fd_set *, struct timeval *);
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 sets \a t->error to a negative value, the
41 * task gets unregistered automatically.
47 * The pre select hook of \a t.
49 * Its purpose is to add file descriptors to the fd sets of the
50 * scheduler and to decrease the select timeout if necessary.
52 void (*pre_select)(struct sched *s, struct task *t);
54 * The postselect hook of \a t.
56 * Evaluate and act upon the results of the previous select call.
58 void (*post_select)(struct sched *s, struct task *t);
59 /** Whether this task is in error state. */
61 /** Position of the task in the pre_select list of the scheduler. */
62 struct list_head pre_select_node;
63 /** Position of the task in the post_select list of the scheduler. */
64 struct list_head post_select_node;
65 /** Descriptive text and current status of the task. */
70 * This is set by the scheduler at the beginning of its main loop. It may be
71 * used (read-only) from everywhere. As none of the functions called by the
72 * scheduler are allowed to block, this value should be accurate enough so that
73 * there is no need to call gettimeofday() directly.
75 extern struct timeval *now;
77 void register_task(struct task *t);
78 int schedule(struct sched *s);
79 char *get_task_list(void);
80 void sched_shutdown(void);
81 void sched_min_delay(struct sched *s);
82 void sched_request_timeout(struct timeval *to, struct sched *s);
83 void sched_request_timeout_ms(long unsigned ms, struct sched *s);
84 int sched_request_barrier(struct timeval *barrier, struct sched *s);
85 int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);