aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_scheduler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-11-04 14:10:32 +0000
committerChristian Grothoff <christian@grothoff.org>2009-11-04 14:10:32 +0000
commitcf45b8dff29c366d51aa2e6ea6a64b99b514b9c9 (patch)
tree5cb37c041743daff5af528dbbe24f5c563ce702e /src/util/test_scheduler.c
parentb91546a3de767292e6472c6b1927480adba43d88 (diff)
downloadgnunet-cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9.tar.gz
gnunet-cf45b8dff29c366d51aa2e6ea6a64b99b514b9c9.zip
bugfixes and redesigning scheduler API
Diffstat (limited to 'src/util/test_scheduler.c')
-rw-r--r--src/util/test_scheduler.c105
1 files changed, 56 insertions, 49 deletions
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index 98dce6f97..3021dce19 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -30,14 +30,6 @@
30#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
31 31
32static void 32static void
33task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
34{
35 int *ok = cls;
36 GNUNET_assert (2 == *ok);
37 (*ok) = 3;
38}
39
40static void
41task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 33task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
42{ 34{
43 int *ok = cls; 35 int *ok = cls;
@@ -48,6 +40,19 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
48 (*ok) = 4; 40 (*ok) = 4;
49} 41}
50 42
43
44static void
45task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
46{
47 int *ok = cls;
48 GNUNET_assert (2 == *ok);
49 (*ok) = 3;
50 /* t3 will go before t4: higher priority */
51 GNUNET_SCHEDULER_add_with_priority (tc->sched,
52 GNUNET_SCHEDULER_PRIORITY_UI,
53 &task3, cls);
54}
55
51static void 56static void
52task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{ 58{
@@ -96,14 +101,9 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); 101 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
97 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); 102 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
98 (*ok) = 8; 103 (*ok) = 8;
99 GNUNET_SCHEDULER_add_after (tc->sched, 104 GNUNET_SCHEDULER_add_with_priority (tc->sched,
100 GNUNET_NO, 105 GNUNET_SCHEDULER_PRIORITY_IDLE,
101 GNUNET_SCHEDULER_PRIORITY_UI, 106 &taskLast, cls);
102 0, &taskNeverRun, NULL);
103 GNUNET_SCHEDULER_add_after (tc->sched,
104 GNUNET_YES,
105 GNUNET_SCHEDULER_PRIORITY_IDLE,
106 0, &taskLast, cls);
107 GNUNET_SCHEDULER_shutdown (tc->sched); 107 GNUNET_SCHEDULER_shutdown (tc->sched);
108} 108}
109 109
@@ -119,15 +119,9 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); 119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
120 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); 120 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
121 GNUNET_SCHEDULER_add_read_file (tc->sched, 121 GNUNET_SCHEDULER_add_read_file (tc->sched,
122 GNUNET_NO,
123 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
124 GNUNET_SCHEDULER_NO_TASK,
125 GNUNET_TIME_UNIT_FOREVER_REL, 122 GNUNET_TIME_UNIT_FOREVER_REL,
126 fds[0], &taskRd, cls); 123 fds[0], &taskRd, cls);
127 GNUNET_SCHEDULER_add_write_file (tc->sched, 124 GNUNET_SCHEDULER_add_write_file (tc->sched,
128 GNUNET_NO,
129 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
130 GNUNET_SCHEDULER_NO_TASK,
131 GNUNET_TIME_UNIT_FOREVER_REL, 125 GNUNET_TIME_UNIT_FOREVER_REL,
132 fds[1], &taskWrt, cls); 126 fds[1], &taskWrt, cls);
133} 127}
@@ -144,24 +138,13 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
144 (*ok) = 2; 138 (*ok) = 2;
145 /* t2 will go first -- prereq for all */ 139 /* t2 will go first -- prereq for all */
146 t2 = GNUNET_SCHEDULER_add_after (tc->sched, 140 t2 = GNUNET_SCHEDULER_add_after (tc->sched,
147 GNUNET_NO,
148 GNUNET_SCHEDULER_PRIORITY_IDLE,
149 GNUNET_SCHEDULER_NO_TASK, &task2, cls); 141 GNUNET_SCHEDULER_NO_TASK, &task2, cls);
150 /* t3 will go before t4: higher priority */ 142 /* t4 will go after t2 ('add after') and after t3 (priority) */
151 t4 = GNUNET_SCHEDULER_add_after (tc->sched, 143 t4 = GNUNET_SCHEDULER_add_after (tc->sched,
152 GNUNET_NO,
153 GNUNET_SCHEDULER_PRIORITY_IDLE,
154 t2, &task4, cls); 144 t2, &task4, cls);
155 GNUNET_SCHEDULER_add_delayed (tc->sched, 145 /* t5 will go last (after p4) */
156 GNUNET_NO,
157 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
158 t2,
159 GNUNET_TIME_relative_get_zero (),
160 &task3, cls);
161 /* t4 will go first: lower prio, but prereq! */
162 GNUNET_SCHEDULER_add_after (tc->sched, 146 GNUNET_SCHEDULER_add_after (tc->sched,
163 GNUNET_NO, 147 t4, &task5, cls);
164 GNUNET_SCHEDULER_PRIORITY_UI, t4, &task5, cls);
165} 148}
166 149
167 150
@@ -182,20 +165,47 @@ check ()
182 165
183 166
184static void 167static void
168taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169{
170 int *ok = cls;
171 GNUNET_assert (1 == *ok);
172 *ok = 8;
173 GNUNET_SCHEDULER_add_delayed (tc->sched,
174 GNUNET_TIME_UNIT_FOREVER_REL,
175 &taskLast, cls);
176 GNUNET_SCHEDULER_shutdown (tc->sched);
177}
178
179
180/**
181 * Main method, starts scheduler with task1,
182 * checks that "ok" is correct at the end.
183 */
184static int
185checkShutdown ()
186{
187 int ok;
188
189 ok = 1;
190 GNUNET_SCHEDULER_run (&taskShutdown, &ok);
191 return ok;
192}
193
194
195static void
185taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 196taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
186{ 197{
187 int *ok = cls; 198 int *ok = cls;
188 GNUNET_assert (1 == *ok); 199 GNUNET_assert (1 == *ok);
189 *ok = 8; 200 *ok = 8;
190 GNUNET_SCHEDULER_add_after (tc->sched, 201 GNUNET_SCHEDULER_add_delayed (tc->sched,
191 GNUNET_NO, 202 GNUNET_TIME_UNIT_FOREVER_REL,
192 GNUNET_SCHEDULER_PRIORITY_UI, 203 &taskLast, cls);
193 0, &taskNeverRun, NULL); 204#ifndef MINGW
194 GNUNET_SCHEDULER_add_after (tc->sched,
195 GNUNET_YES,
196 GNUNET_SCHEDULER_PRIORITY_UI,
197 0, &taskLast, cls);
198 GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM)); 205 GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM));
206#else
207 GNUNET_SCHEDULER_shutdown (tc->sched);
208#endif
199} 209}
200 210
201 211
@@ -214,8 +224,6 @@ checkSignal ()
214} 224}
215 225
216 226
217
218
219static void 227static void
220taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 228taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
221{ 229{
@@ -225,9 +233,7 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
225 *ok = 0; 233 *ok = 0;
226 GNUNET_SCHEDULER_cancel (tc->sched, 234 GNUNET_SCHEDULER_cancel (tc->sched,
227 GNUNET_SCHEDULER_add_after (tc->sched, 235 GNUNET_SCHEDULER_add_after (tc->sched,
228 GNUNET_NO, 236 GNUNET_SCHEDULER_NO_TASK,
229 GNUNET_SCHEDULER_PRIORITY_UI,
230 0,
231 &taskNeverRun, NULL)); 237 &taskNeverRun, NULL));
232} 238}
233 239
@@ -256,6 +262,7 @@ main (int argc, char *argv[])
256 GNUNET_log_setup ("test_scheduler", "WARNING", NULL); 262 GNUNET_log_setup ("test_scheduler", "WARNING", NULL);
257 ret += check (); 263 ret += check ();
258 ret += checkSignal (); 264 ret += checkSignal ();
265 ret += checkShutdown ();
259 ret += checkCancel (); 266 ret += checkCancel ();
260 GNUNET_DISK_pipe_close (p); 267 GNUNET_DISK_pipe_close (p);
261 268