X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=sched.h;h=ede5e67ea2ac042c5765a92e6100bc00ab47e103;hb=2391dbc88e15dd54207f289bb4fdbaf0e801b1ca;hp=f89b89ffc012551e17febc9de463882eb5c678b6;hpb=7e0a0badba66c0cdcb0dcbc8cf3d0f5b71001ca3;p=paraslash.git diff --git a/sched.h b/sched.h index f89b89ff..ede5e67e 100644 --- a/sched.h +++ b/sched.h @@ -7,26 +7,30 @@ * Paraslash's scheduler. * * Designed with KISS in mind. It maintains a list of task structures which is - * extended when a new task is registered. Each task may define a pre_select + * extended when a new task is registered. Each task may define a pre_monitor * function which is called from the scheduler main loop before it calls - * select(). Similarly, each task must define a post_select function which is - * called after the select call. + * poll(2). Similarly, each task must define a post_monitor function which is + * called after poll(2) returns. * * \sa select(2), poll(2). */ struct sched { - /** Initial value (in milliseconds) before any pre_select call. */ + /** Initial value (in milliseconds) before any pre_monitor call. */ int default_timeout; - /** The timeout (also in milliseconds) for the next select call. */ + /** The timeout (also in milliseconds) for the next iteration. */ int timeout; - /** fds that should be watched for readability. */ - fd_set rfds; - /** fds that should be watched for writability. */ - fd_set wfds; - /** Highest numbered file descriptor in any of the above fd sets. */ - int max_fileno; - /** If non-NULL, use this function instead of para_select. */ - int (*select_function)(int, fd_set *, fd_set *, int timeout); + /** Passed to poll(2). */ + struct pollfd *pfd; + /** Number of elements in the above array, passed to poll(2). */ + unsigned pfd_array_len; + /** Number of fds registered for montitoring so far. */ + unsigned num_pfds; + /** Maps fds to indices of the pfd array. */ + unsigned *pidx; + /** Mumber of elements in the above pidx array. */ + unsigned pidx_array_len; + /** If non-NULL, use this function instead of \ref xpoll(). */ + int (*poll_function)(struct pollfd *fds, nfds_t nfds, int timeout); /** Tasks which have been registered to the scheduler. */ struct list_head task_list; }; @@ -49,7 +53,7 @@ struct task_info { * * \sa \ref time.c. */ - void (*pre_select)(struct sched *s, void *context); + void (*pre_monitor)(struct sched *s, void *context); /** * Perform I/O on file descriptors which are ready for I/O. * @@ -60,10 +64,10 @@ struct task_info { * If this function returns a negative value, the scheduler unregisters * the task. */ - int (*post_select)(struct sched *s, void *context); + int (*post_monitor)(struct sched *s, void *context); /** * This pointer is saved when the task is registered. It is passed to - * ->pre_select() and ->post_select(). Usually this is a pointer to the + * ->pre_monitor() and ->post_monitor(). Usually this is a pointer to the * struct owned by the caller which contains the task pointer. */ void *context; @@ -93,13 +97,5 @@ int sched_request_barrier(struct timeval *barrier, struct sched *s); int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s); void sched_monitor_readfd(int fd, struct sched *s); void sched_monitor_writefd(int fd, struct sched *s); - -static inline bool sched_read_ok(int fd, const struct sched *s) -{ - return FD_ISSET(fd, &s->rfds); -} - -static inline bool sched_write_ok(int fd, const struct sched *s) -{ - return FD_ISSET(fd, &s->wfds); -} +bool sched_read_ok(int fd, const struct sched *s); +bool sched_write_ok(int fd, const struct sched *s);