-#include "silcincludes.h"
-#include "silcschedule_i.h"
-
-/* Forward declarations */
-typedef struct SilcTaskQueueStruct *SilcTaskQueue;
-
-/* System specific routines. Implemented under unix/, win32/ and such. */
-
-/* System specific select(). Returns same values as normal select(). */
-int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count,
- struct timeval *timeout);
-
-/* Initializes the platform specific scheduler. This for example initializes
- the wakeup mechanism of the scheduler. In multi-threaded environment
- the scheduler needs to be wakenup when tasks are added or removed from
- the task queues. Returns context to the platform specific scheduler. */
-void *silc_schedule_internal_init(SilcSchedule schedule);
-
-/* Uninitializes the platform specific scheduler context. */
-void silc_schedule_internal_uninit(void *context);
-
-/* Wakes up the scheduler. This is platform specific routine */
-void silc_schedule_internal_wakeup(void *context);
-
-/* Register signal */
-void silc_schedule_internal_signal_register(void *context,
- SilcUInt32 signal);
-
-/* Unregister signal */
-void silc_schedule_internal_signal_unregister(void *context,
- SilcUInt32 signal);
-
-/* Block registered signals in scheduler. */
-void silc_schedule_internal_signals_block(void *context);
-
-/* Unblock registered signals in schedule. */
-void silc_schedule_internal_signals_unblock(void *context);
-
-/* Internal task management routines. */
-
-static void silc_task_queue_alloc(SilcTaskQueue *queue);
-static void silc_task_queue_free(SilcTaskQueue queue);
-static SilcTask silc_task_find(SilcTaskQueue queue, SilcUInt32 fd);
-static SilcTask silc_task_add(SilcTaskQueue queue, SilcTask newtask,
- SilcTaskPriority priority);
-static SilcTask silc_task_get_first(SilcTaskQueue queue, SilcTask first);
-static SilcTask silc_task_add_timeout(SilcTaskQueue queue, SilcTask newtask,
- SilcTaskPriority priority);
-static int silc_schedule_task_remove(SilcTaskQueue queue, SilcTask task);
-static int silc_schedule_task_timeout_compare(struct timeval *smaller,
- struct timeval *bigger);
-static void silc_task_del_by_context(SilcTaskQueue queue, void *context);
-static void silc_task_del_by_callback(SilcTaskQueue queue,
- SilcTaskCallback callback);
-static void silc_task_del_by_fd(SilcTaskQueue queue, SilcUInt32 fd);
-
-/* Returns the task queue by task type */
-#define SILC_SCHEDULE_GET_QUEUE(type) \
- (type == SILC_TASK_FD ? schedule->fd_queue : \
- type == SILC_TASK_TIMEOUT ? schedule->timeout_queue : \
- schedule->generic_queue)
-
-/* Locks. These also blocks signals that we care about and thus guarantee
- that while we are in scheduler no signals can happen. This way we can
- synchronise signals with SILC Scheduler. */
-#define SILC_SCHEDULE_LOCK(schedule) \
-do { \
- silc_schedule_internal_signals_block(schedule->internal); \
- silc_mutex_lock(schedule->lock); \
-} while (0)
-#define SILC_SCHEDULE_UNLOCK(schedule) \
-do { \
- silc_mutex_unlock(schedule->lock); \
- silc_schedule_internal_signals_unblock(schedule->internal); \
-} while (0)
-
-/* SILC Task object. Represents one task in the scheduler. */
-struct SilcTaskStruct {
- SilcUInt32 fd;
- struct timeval timeout;
- SilcTaskCallback callback;