Added SILC Thread Queue API
[silc.git] / lib / silcutil / os2 / silcos2schedule.c
1 /*
2
3   silcos2schedule.c 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2002 Pekka Riikonen
8
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.
12
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.
17
18 */
19 /* $Id$ */
20
21 /* XXX TODO */
22
23 #include "silc.h"
24 #include "silcschedule_i.h"
25
26 /* Calls normal select() system call. */
27
28 int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeout)
29 {
30   fd_set in, out;
31   int ret, i, max_fd = 0;
32
33   FD_ZERO(&in);
34   FD_ZERO(&out);
35
36   for (i = 0; i < fds_count; i++) {
37     if (!fds[i].events)
38       continue;
39
40     if (fds[i].fd > max_fd)
41       max_fd = fds[i].fd;
42
43     if (fds[i].events & SILC_TASK_READ)
44       FD_SET(fds[i].fd, &in);
45     if (fds[i].events & SILC_TASK_WRITE)
46       FD_SET(fds[i].fd, &out);
47
48     fds[i].revents = 0;
49   }
50
51   /*  ret = select(max_fd + 1, &in, &out, NULL, timeout); */
52   if (ret <= 0)
53     return ret;
54
55   for (i = 0; i < fds_count; i++) {
56     if (!fds[i].events)
57       continue;
58
59     if (FD_ISSET(fds[i].fd, &in))
60       fds[i].revents |= SILC_TASK_READ;
61     if (FD_ISSET(fds[i].fd, &out))
62       fds[i].revents |= SILC_TASK_WRITE;
63   }
64
65   return ret;
66 }
67
68 #ifdef SILC_THREADS
69
70 /* XXX Do this like it's done in win32/ */
71
72 /* Internal wakeup context. */
73 typedef struct {
74
75 } *SilcOs2Wakeup;
76
77 SILC_TASK_CALLBACK(silc_schedule_wakeup_cb)
78 {
79
80 }
81
82 #endif /* SILC_THREADS */
83
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
89 void *silc_schedule_internal_init(SilcSchedule schedule, void *context)
90 {
91 #ifdef SILC_THREADS
92   return NULL;
93
94 #endif
95   return NULL;
96 }
97
98 /* Uninitializes the platform specific scheduler context. */
99
100 void silc_schedule_internal_uninit(void *context)
101 {
102 #ifdef SILC_THREADS
103
104 #endif
105 }
106
107 /* Wakes up the scheduler */
108
109 void silc_schedule_internal_wakeup(void *context)
110 {
111 #ifdef SILC_THREADS
112
113 #endif
114 }
115
116 /* Register signal */
117
118 void silc_schedule_internal_signal_register(void *context,
119                                             SilcUInt32 signal,
120                                             SilcTaskCallback callback,
121                                             void *callback_context)
122 {
123
124 }
125
126 /* Unregister signal */
127
128 void silc_schedule_internal_signal_unregister(void *context,
129                                               SilcUInt32 signal,
130                                               SilcTaskCallback callback,
131                                               void *callback_context)
132 {
133
134 }
135
136 /* Mark signal to be called later. */
137
138 void silc_schedule_internal_signal_call(void *context, SilcUInt32 signal)
139 {
140
141 }
142
143 /* Call all signals */
144
145 void silc_schedule_internal_signals_call(void *context,
146                                          SilcSchedule schedule)
147 {
148
149 }
150
151 /* Block registered signals in scheduler. */
152
153 void silc_schedule_internal_signals_block(void *context)
154 {
155
156 }
157
158 /* Unblock registered signals in schedule. */
159
160 void silc_schedule_internal_signals_unblock(void *context)
161 {
162
163 }