5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1998 - 2001 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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
22 #include "silcincludes.h"
24 /* Calls normal select() system call. */
26 int silc_select(int n, fd_set *readfds, fd_set *writefds,
27 fd_set *exceptfds, struct timeval *timeout)
29 return select(n, readfds, writefds, exceptfds, timeout);
34 /* Internal wakeup context. */
40 SILC_TASK_CALLBACK(silc_schedule_wakeup_cb)
42 SilcUnixWakeup wakeup = (SilcUnixWakeup)context;
45 read(wakeup->wakeup_pipe[0], &c, 1);
48 #endif /* SILC_THREADS */
50 /* Initializes the wakeup of the scheduler. In multi-threaded environment
51 the scheduler needs to be wakenup when tasks are added or removed from
52 the task queues. This will initialize the wakeup for the scheduler.
53 Any tasks that needs to be registered must be registered to the `queue'.
54 It is quaranteed that the scheduler will automatically free any
55 registered tasks in this queue. This is system specific routine. */
57 void *silc_schedule_wakeup_init(void *queue)
60 SilcUnixWakeup wakeup;
62 wakeup = silc_calloc(1, sizeof(*wakeup));
64 if (pipe(wakeup->wakeup_pipe)) {
69 wakeup->wakeup_task = silc_task_register(queue, wakeup->wakeup_pipe[0],
70 silc_schedule_wakeup_cb, wakeup,
72 SILC_TASK_PRI_NORMAL);
73 if (!wakeup->wakeup_task) {
74 close(wakeup->wakeup_pipe[0]);
75 close(wakeup->wakeup_pipe[1]);
80 return (void *)wakeup;
85 /* Uninitializes the system specific wakeup. */
87 void silc_schedule_wakeup_uninit(void *context)
90 SilcUnixWakeup wakeup = (SilcUnixWakeup)context;
95 close(wakeup->wakeup_pipe[0]);
96 close(wakeup->wakeup_pipe[1]);
101 /* Wakes up the scheduler */
103 void silc_schedule_wakeup_internal(void *context)
106 SilcUnixWakeup wakeup = (SilcUnixWakeup)context;
111 write(wakeup->wakeup_pipe[1], "!", 1);