1 /****h* silcutil/silcschedule.h
9 * Author: Pekka Riikonen <priikone@silcnet.org>
11 * Copyright (C) 1998 - 2001 Pekka Riikonen
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
25 #ifndef SILCSCHEDULE_H
26 #define SILCSCHEDULE_H
28 /****s* silcutil/SilcScheduleAPI/SilcSchedule
32 * typedef struct SilcScheduleStruct *SilcSchedule;
36 * This context is the actual Scheduler and is allocated by
37 * the silc_schedule_init funtion. The context is given as argument
38 * to all silc_schedule_* functions. It must be freed by the
39 * silc_schedule_uninit function.
42 typedef struct SilcScheduleStruct *SilcSchedule;
46 /****f* silcutil/SilcScheduleAPI/silc_schedule_init
50 * SilcSchedule silc_schedule_init(SilcTaskQueue *fd_queue,
51 * SilcTaskQueue *timeout_queue,
52 * SilcTaskQueue *generic_queue,
57 * Initializes the scheduler. Sets the non-timeout task queue hook and
58 * the timeout task queue hook. This must be called before the scheduler
59 * is able to work. This will allocate the queue pointers if they are
60 * not allocated. Returns the scheduler context that must be freed by
61 * the silc_schedule_uninit function.
64 SilcSchedule silc_schedule_init(SilcTaskQueue *fd_queue,
65 SilcTaskQueue *timeout_queue,
66 SilcTaskQueue *generic_queue,
69 /****f* silcutil/SilcScheduleAPI/silc_schedule_uninit
73 * bool silc_schedule_uninit(SilcSchedule schedule);
77 * Uninitializes the schedule. This is called when the program is ready
78 * to end. This removes all tasks and task queues. Returns FALSE if the
79 * scheduler could not be uninitialized. This happens when the scheduler
80 * is still valid and silc_schedule_stop has not been called.
83 bool silc_schedule_uninit(SilcSchedule schedule);
85 /****f* silcutil/SilcScheduleAPI/silc_schedule_stop
89 * void silc_schedule_stop(SilcSchedule schedule);
93 * Stops the scheduler even if it is not supposed to be stopped yet.
94 * After calling this, one must call silc_schedule_uninit (after the
95 * silc_schedule has returned).
98 void silc_schedule_stop(SilcSchedule schedule);
100 /****f* silcutil/SilcScheduleAPI/silc_schedule_set_listen_fd
104 * void silc_schedule_set_listen_fd(SilcSchedule schedule,
105 * int fd, uint32 iomask);
109 * Sets a file descriptor to be listened by the scheduler. One can
110 * call this directly if wanted. This can be called multiple times for
111 * one file descriptor to set different iomasks.
114 void silc_schedule_set_listen_fd(SilcSchedule schedule, int fd, uint32 iomask);
116 /****f* silcutil/SilcScheduleAPI/silc_schedule_unset_listen_fd
120 * void silc_schedule_unset_listen_fd(SilcSchedule schedule, int fd);
124 * Removes a file descriptor from listen list. The file descriptor
125 * is not listened by the scheduler after this function.
128 void silc_schedule_unset_listen_fd(SilcSchedule schedule, int fd);
130 /****f* silcutil/SilcScheduleAPI/silc_schedule
134 * void silc_schedule(SilcSchedule schedule);
138 * The SILC scheduler. This is actually the main routine in SILC programs.
139 * When this returns the program is to be ended. Before this function can
140 * be called, one must call silc_schedule_init function.
143 void silc_schedule(SilcSchedule schedule);
145 /****f* silcutil/SilcScheduleAPI/silc_schedule
149 * bool silc_schedule_one(SilcSchedule schedule, int block);
153 * Same as the silc_schedule but runs the scheduler only one round
154 * and then returns. This function is handy when the SILC scheduler
155 * is used inside some other external scheduler, for example. If
156 * the `timeout_usecs' is positive a timeout will be added to the
157 * scheduler. The function will not return in this timeout unless
158 * some other event occurs.
161 bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs);