5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2001 - 2005 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 #ifndef SILCSCHEDULE_I_H
21 #define SILCSCHEDULE_I_H
23 #ifndef SILCSCHEDULE_H
24 #error "Do not include this header directly"
27 #include "silchashtable.h"
31 struct SilcTaskStruct {
32 SilcTaskCallback callback;
34 unsigned int type : 1; /* 0 = fd, 1 = timeout */
35 unsigned int valid : 1; /* Set if task is valid */
39 typedef struct SilcTaskTimeoutStruct {
40 struct SilcTaskStruct header;
41 struct SilcTaskTimeoutStruct *next;
42 struct timeval timeout;
47 struct SilcTaskStruct header;
49 unsigned int events : 16;
50 unsigned int revents : 16;
53 /* Scheduler context */
54 struct SilcScheduleStruct {
56 void *app_context; /* Application specific context */
57 SilcHashTable fd_queue; /* FD task queue */
58 SilcList timeout_queue; /* Timeout queue */
59 SilcMutex lock; /* Scheduler lock */
60 struct timeval timeout; /* Current timeout */
61 unsigned int max_tasks : 28; /* Max FD tasks */
62 unsigned int has_timeout : 1; /* Set if timeout is set */
63 unsigned int valid : 1; /* Set if scheduler is valid */
64 unsigned int is_locked : 1; /* Set if scheduler is locked */
65 unsigned int signal_tasks : 1; /* Set if to dispatch signals */
68 /* Locks. These also blocks signals that we care about and thus guarantee
69 that while we are in scheduler no signals can happen. This way we can
70 synchronise signals with SILC Scheduler. */
71 #define SILC_SCHEDULE_LOCK(schedule) \
73 schedule_ops.signals_block(schedule, schedule->internal); \
74 silc_mutex_lock(schedule->lock); \
76 #define SILC_SCHEDULE_UNLOCK(schedule) \
78 silc_mutex_unlock(schedule->lock); \
79 schedule_ops.signals_unblock(schedule, schedule->internal); \
82 /* Platform specific scheduler operations */
84 /* Initializes the platform specific scheduler. This for example initializes
85 the wakeup mechanism of the scheduler. In multi-threaded environment
86 the scheduler needs to be wakenup when tasks are added or removed from
87 the task queues. Returns context to the platform specific scheduler. */
88 void *(*init)(SilcSchedule schedule, void *app_context);
90 /* Uninitializes the platform specific scheduler context. */
91 void (*uninit)(SilcSchedule schedule, void *context);
93 /* System specific select(). Returns same values as normal select(). */
94 int (*select)(SilcSchedule schedule, void *context);
96 /* Wakes up the scheduler. This is platform specific routine */
97 void (*wakeup)(SilcSchedule schedule, void *context);
100 void (*signal_register)(SilcSchedule schedule, void *context,
101 SilcUInt32 signal, SilcTaskCallback callback,
102 void *callback_context);
104 /* Unregister signal */
105 void (*signal_unregister)(SilcSchedule schedule, void *context,
106 SilcUInt32 signal, SilcTaskCallback callback,
107 void *callback_context);
109 /* Mark signal to be called later. */
110 void (*signal_call)(SilcSchedule schedule, void *context, SilcUInt32 signal);
112 /* Call all signals */
113 void (*signals_call)(SilcSchedule schedule, void *context);
115 /* Block registered signals in scheduler. */
116 void (*signals_block)(SilcSchedule schedule, void *context);
118 /* Unblock registered signals in schedule. */
119 void (*signals_unblock)(SilcSchedule schedule, void *context);
122 #endif /* SILCSCHEDULE_I_H */