aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_scheduler.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
committerNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
commit75a33a1499cf60ea4364c9aa673816629a6c1413 (patch)
tree0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/util/test_scheduler.c
parent7217c601ad30760872823193d62307e7a335d226 (diff)
downloadgnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz
gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/util/test_scheduler.c')
-rw-r--r--src/util/test_scheduler.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index 0ac186588..f0c908d7d 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -34,8 +34,7 @@ task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
34{ 34{
35 int *ok = cls; 35 int *ok = cls;
36 /* t4 should be ready (albeit with lower priority) */ 36 /* t4 should be ready (albeit with lower priority) */
37 GNUNET_assert (1 == GNUNET_SCHEDULER_get_load (tc->sched, 37 GNUNET_assert (1 == GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT));
38 GNUNET_SCHEDULER_PRIORITY_COUNT));
39 GNUNET_assert (3 == *ok); 38 GNUNET_assert (3 == *ok);
40 (*ok) = 4; 39 (*ok) = 4;
41} 40}
@@ -48,8 +47,7 @@ task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
48 GNUNET_assert (2 == *ok); 47 GNUNET_assert (2 == *ok);
49 (*ok) = 3; 48 (*ok) = 3;
50 /* t3 will go before t4: higher priority */ 49 /* t3 will go before t4: higher priority */
51 GNUNET_SCHEDULER_add_with_priority (tc->sched, 50 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
52 GNUNET_SCHEDULER_PRIORITY_UI,
53 &task3, cls); 51 &task3, cls);
54} 52}
55 53
@@ -101,10 +99,9 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
101 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); 99 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
102 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); 100 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
103 (*ok) = 8; 101 (*ok) = 8;
104 GNUNET_SCHEDULER_add_with_priority (tc->sched, 102 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
105 GNUNET_SCHEDULER_PRIORITY_IDLE,
106 &taskLast, cls); 103 &taskLast, cls);
107 GNUNET_SCHEDULER_shutdown (tc->sched); 104 GNUNET_SCHEDULER_shutdown ();
108} 105}
109 106
110 107
@@ -118,11 +115,9 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 GNUNET_assert (NULL != p); 115 GNUNET_assert (NULL != p);
119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); 116 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); 117 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
121 GNUNET_SCHEDULER_add_read_file (tc->sched, 118 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
122 GNUNET_TIME_UNIT_FOREVER_REL,
123 fds[0], &taskRd, cls); 119 fds[0], &taskRd, cls);
124 GNUNET_SCHEDULER_add_write_file (tc->sched, 120 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
125 GNUNET_TIME_UNIT_FOREVER_REL,
126 fds[1], &taskWrt, cls); 121 fds[1], &taskWrt, cls);
127} 122}
128 123
@@ -137,12 +132,11 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137 GNUNET_assert (1 == *ok); 132 GNUNET_assert (1 == *ok);
138 (*ok) = 2; 133 (*ok) = 2;
139 /* t2 will go first -- prereq for all */ 134 /* t2 will go first -- prereq for all */
140 t2 = GNUNET_SCHEDULER_add_after (tc->sched, 135 t2 = GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK, &task2, cls);
141 GNUNET_SCHEDULER_NO_TASK, &task2, cls);
142 /* t4 will go after t2 ('add after') and after t3 (priority) */ 136 /* t4 will go after t2 ('add after') and after t3 (priority) */
143 t4 = GNUNET_SCHEDULER_add_after (tc->sched, t2, &task4, cls); 137 t4 = GNUNET_SCHEDULER_add_after (t2, &task4, cls);
144 /* t5 will go last (after p4) */ 138 /* t5 will go last (after p4) */
145 GNUNET_SCHEDULER_add_after (tc->sched, t4, &task5, cls); 139 GNUNET_SCHEDULER_add_after (t4, &task5, cls);
146} 140}
147 141
148 142
@@ -168,9 +162,8 @@ taskShutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168 int *ok = cls; 162 int *ok = cls;
169 GNUNET_assert (1 == *ok); 163 GNUNET_assert (1 == *ok);
170 *ok = 8; 164 *ok = 8;
171 GNUNET_SCHEDULER_add_delayed (tc->sched, 165 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
172 GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls); 166 GNUNET_SCHEDULER_shutdown ();
173 GNUNET_SCHEDULER_shutdown (tc->sched);
174} 167}
175 168
176 169
@@ -195,8 +188,7 @@ taskSig (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
195 int *ok = cls; 188 int *ok = cls;
196 GNUNET_assert (1 == *ok); 189 GNUNET_assert (1 == *ok);
197 *ok = 8; 190 *ok = 8;
198 GNUNET_SCHEDULER_add_delayed (tc->sched, 191 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
199 GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
200 GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM)); 192 GNUNET_break (0 == PLIBC_KILL (getpid (), SIGTERM));
201} 193}
202 194
@@ -223,9 +215,7 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
223 215
224 GNUNET_assert (1 == *ok); 216 GNUNET_assert (1 == *ok);
225 *ok = 0; 217 *ok = 0;
226 GNUNET_SCHEDULER_cancel (tc->sched, 218 GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK,
227 GNUNET_SCHEDULER_add_after (tc->sched,
228 GNUNET_SCHEDULER_NO_TASK,
229 &taskNeverRun, NULL)); 219 &taskNeverRun, NULL));
230} 220}
231 221