diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-04-19 12:07:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-04-19 12:07:05 +0000 |
commit | b272a833ee57cad630ecbcce1aab366777042dd9 (patch) | |
tree | 9a6057f81afe36db736b4911a85c0b94538c1f53 /src/util | |
parent | 50c4e060fc721dfe2af9115639a4d47e88e04f00 (diff) | |
download | gnunet-b272a833ee57cad630ecbcce1aab366777042dd9.tar.gz gnunet-b272a833ee57cad630ecbcce1aab366777042dd9.zip |
-fixing #2274 -- eliminating GNUNET_SCHEDULER_add_after
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/scheduler.c | 43 | ||||
-rw-r--r-- | src/util/server.c | 3 | ||||
-rw-r--r-- | src/util/test_scheduler.c | 44 |
3 files changed, 19 insertions, 71 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index c54672f5f..8d3106032 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -1107,31 +1107,6 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, | |||
1107 | 1107 | ||
1108 | 1108 | ||
1109 | /** | 1109 | /** |
1110 | * Schedule a new task to be run after the specified prerequisite task | ||
1111 | * has completed. It will be run with the DEFAULT priority. | ||
1112 | * | ||
1113 | * @param prerequisite_task run this task after the task with the given | ||
1114 | * task identifier completes (and any of our other | ||
1115 | * conditions, such as delay, read or write-readiness | ||
1116 | * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency | ||
1117 | * on completion of other tasks (this will cause the task to run as | ||
1118 | * soon as possible). | ||
1119 | * @param task main function of the task | ||
1120 | * @param task_cls closure of task | ||
1121 | * @return unique task identifier for the job | ||
1122 | * only valid until "task" is started! | ||
1123 | */ | ||
1124 | GNUNET_SCHEDULER_TaskIdentifier | ||
1125 | GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | ||
1126 | GNUNET_SCHEDULER_Task task, void *task_cls) | ||
1127 | { | ||
1128 | return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
1129 | prerequisite_task, GNUNET_TIME_UNIT_ZERO, | ||
1130 | NULL, NULL, task, task_cls); | ||
1131 | } | ||
1132 | |||
1133 | |||
1134 | /** | ||
1135 | * Schedule a new task to be run with a specified priority. | 1110 | * Schedule a new task to be run with a specified priority. |
1136 | * | 1111 | * |
1137 | * @param prio how important is the new task? | 1112 | * @param prio how important is the new task? |
@@ -1144,7 +1119,7 @@ GNUNET_SCHEDULER_TaskIdentifier | |||
1144 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | 1119 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, |
1145 | GNUNET_SCHEDULER_Task task, void *task_cls) | 1120 | GNUNET_SCHEDULER_Task task, void *task_cls) |
1146 | { | 1121 | { |
1147 | return GNUNET_SCHEDULER_add_select (prio, GNUNET_SCHEDULER_NO_TASK, | 1122 | return GNUNET_SCHEDULER_add_select (prio, |
1148 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, | 1123 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, |
1149 | task_cls); | 1124 | task_cls); |
1150 | } | 1125 | } |
@@ -1299,7 +1274,6 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | |||
1299 | 1274 | ||
1300 | ret = | 1275 | ret = |
1301 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1276 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1302 | GNUNET_SCHEDULER_NO_TASK, | ||
1303 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, | 1277 | GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, |
1304 | task_cls); | 1278 | task_cls); |
1305 | GNUNET_assert (pending->id == ret); | 1279 | GNUNET_assert (pending->id == ret); |
@@ -1450,7 +1424,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1450 | GNUNET_NETWORK_fdset_set (rs, rfd); | 1424 | GNUNET_NETWORK_fdset_set (rs, rfd); |
1451 | ret = | 1425 | ret = |
1452 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1426 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1453 | GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, | 1427 | delay, rs, NULL, |
1454 | task, task_cls); | 1428 | task, task_cls); |
1455 | GNUNET_NETWORK_fdset_destroy (rs); | 1429 | GNUNET_NETWORK_fdset_destroy (rs); |
1456 | return ret; | 1430 | return ret; |
@@ -1493,7 +1467,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1493 | GNUNET_NETWORK_fdset_set (ws, wfd); | 1467 | GNUNET_NETWORK_fdset_set (ws, wfd); |
1494 | ret = | 1468 | ret = |
1495 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1469 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1496 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, | 1470 | delay, NULL, ws, |
1497 | task, task_cls); | 1471 | task, task_cls); |
1498 | GNUNET_NETWORK_fdset_destroy (ws); | 1472 | GNUNET_NETWORK_fdset_destroy (ws); |
1499 | return ret; | 1473 | return ret; |
@@ -1536,7 +1510,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1536 | GNUNET_NETWORK_fdset_handle_set (rs, rfd); | 1510 | GNUNET_NETWORK_fdset_handle_set (rs, rfd); |
1537 | ret = | 1511 | ret = |
1538 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1512 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1539 | GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, | 1513 | delay, rs, NULL, |
1540 | task, task_cls); | 1514 | task, task_cls); |
1541 | GNUNET_NETWORK_fdset_destroy (rs); | 1515 | GNUNET_NETWORK_fdset_destroy (rs); |
1542 | return ret; | 1516 | return ret; |
@@ -1581,7 +1555,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1581 | GNUNET_NETWORK_fdset_handle_set (ws, wfd); | 1555 | GNUNET_NETWORK_fdset_handle_set (ws, wfd); |
1582 | ret = | 1556 | ret = |
1583 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1557 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1584 | GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, | 1558 | delay, NULL, ws, |
1585 | task, task_cls); | 1559 | task, task_cls); |
1586 | GNUNET_NETWORK_fdset_destroy (ws); | 1560 | GNUNET_NETWORK_fdset_destroy (ws); |
1587 | return ret; | 1561 | return ret; |
@@ -1617,11 +1591,6 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1617 | * </code> | 1591 | * </code> |
1618 | * | 1592 | * |
1619 | * @param prio how important is this task? | 1593 | * @param prio how important is this task? |
1620 | * @param prerequisite_task run this task after the task with the given | ||
1621 | * task identifier completes (and any of our other | ||
1622 | * conditions, such as delay, read or write-readiness | ||
1623 | * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency | ||
1624 | * on completion of other tasks. | ||
1625 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", | 1594 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", |
1626 | * which means that the task will only be run after we receive SIGTERM | 1595 | * which means that the task will only be run after we receive SIGTERM |
1627 | * @param rs set of file descriptors we want to read (can be NULL) | 1596 | * @param rs set of file descriptors we want to read (can be NULL) |
@@ -1633,7 +1602,6 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1633 | */ | 1602 | */ |
1634 | GNUNET_SCHEDULER_TaskIdentifier | 1603 | GNUNET_SCHEDULER_TaskIdentifier |
1635 | GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | 1604 | GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, |
1636 | GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, | ||
1637 | struct GNUNET_TIME_Relative delay, | 1605 | struct GNUNET_TIME_Relative delay, |
1638 | const struct GNUNET_NETWORK_FDSet *rs, | 1606 | const struct GNUNET_NETWORK_FDSet *rs, |
1639 | const struct GNUNET_NETWORK_FDSet *ws, | 1607 | const struct GNUNET_NETWORK_FDSet *ws, |
@@ -1671,7 +1639,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1671 | #if PROFILE_DELAYS | 1639 | #if PROFILE_DELAYS |
1672 | t->start_time = GNUNET_TIME_absolute_get (); | 1640 | t->start_time = GNUNET_TIME_absolute_get (); |
1673 | #endif | 1641 | #endif |
1674 | t->prereq_id = prerequisite_task; | ||
1675 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); | 1642 | t->timeout = GNUNET_TIME_relative_to_absolute (delay); |
1676 | t->priority = | 1643 | t->priority = |
1677 | check_priority ((prio == | 1644 | check_priority ((prio == |
diff --git a/src/util/server.c b/src/util/server.c index ede31b558..fc96db802 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -324,7 +324,6 @@ process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
324 | /* ignore shutdown, someone else will take care of it! */ | 324 | /* ignore shutdown, someone else will take care of it! */ |
325 | server->listen_task = | 325 | server->listen_task = |
326 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 326 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
327 | GNUNET_SCHEDULER_NO_TASK, | ||
328 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, | 327 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
329 | &process_listen_socket, server); | 328 | &process_listen_socket, server); |
330 | GNUNET_NETWORK_fdset_destroy (r); | 329 | GNUNET_NETWORK_fdset_destroy (r); |
@@ -354,7 +353,6 @@ process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
354 | /* listen for more! */ | 353 | /* listen for more! */ |
355 | server->listen_task = | 354 | server->listen_task = |
356 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 355 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
357 | GNUNET_SCHEDULER_NO_TASK, | ||
358 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, | 356 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
359 | &process_listen_socket, server); | 357 | &process_listen_socket, server); |
360 | GNUNET_NETWORK_fdset_destroy (r); | 358 | GNUNET_NETWORK_fdset_destroy (r); |
@@ -498,7 +496,6 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, | |||
498 | GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); | 496 | GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); |
499 | ret->listen_task = | 497 | ret->listen_task = |
500 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 498 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
501 | GNUNET_SCHEDULER_NO_TASK, | ||
502 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, | 499 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
503 | &process_listen_socket, ret); | 500 | &process_listen_socket, ret); |
504 | GNUNET_NETWORK_fdset_destroy (r); | 501 | GNUNET_NETWORK_fdset_destroy (r); |
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c index 01982ee8b..9832ade6f 100644 --- a/src/util/test_scheduler.c +++ b/src/util/test_scheduler.c | |||
@@ -30,37 +30,25 @@ | |||
30 | #define VERBOSE GNUNET_NO | 30 | #define VERBOSE GNUNET_NO |
31 | 31 | ||
32 | static void | 32 | static void |
33 | task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 33 | task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
34 | { | 34 | { |
35 | int *ok = cls; | 35 | int *ok = cls; |
36 | 36 | ||
37 | /* t4 should be ready (albeit with lower priority) */ | 37 | /* t3 should be ready (albeit with lower priority) */ |
38 | GNUNET_assert (1 == | 38 | GNUNET_assert (1 == |
39 | GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); | 39 | GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_COUNT)); |
40 | GNUNET_assert (3 == *ok); | ||
41 | (*ok) = 4; | ||
42 | } | ||
43 | |||
44 | |||
45 | static void | ||
46 | task2 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
47 | { | ||
48 | int *ok = cls; | ||
49 | |||
50 | GNUNET_assert (2 == *ok); | 40 | GNUNET_assert (2 == *ok); |
51 | (*ok) = 3; | 41 | (*ok) = 3; |
52 | /* t3 will go before t4: higher priority */ | ||
53 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task3, | ||
54 | cls); | ||
55 | } | 42 | } |
56 | 43 | ||
44 | |||
57 | static void | 45 | static void |
58 | task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 46 | task3 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
59 | { | 47 | { |
60 | int *ok = cls; | 48 | int *ok = cls; |
61 | 49 | ||
62 | GNUNET_assert (4 == *ok); | 50 | GNUNET_assert (3 == *ok); |
63 | (*ok) = 5; | 51 | (*ok) = 4; |
64 | } | 52 | } |
65 | 53 | ||
66 | struct GNUNET_DISK_PipeHandle *p; | 54 | struct GNUNET_DISK_PipeHandle *p; |
@@ -113,11 +101,11 @@ taskRd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
113 | 101 | ||
114 | 102 | ||
115 | static void | 103 | static void |
116 | task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 104 | task4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
117 | { | 105 | { |
118 | int *ok = cls; | 106 | int *ok = cls; |
119 | 107 | ||
120 | GNUNET_assert (5 == *ok); | 108 | GNUNET_assert (4 == *ok); |
121 | (*ok) = 6; | 109 | (*ok) = 6; |
122 | p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); | 110 | p = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); |
123 | GNUNET_assert (NULL != p); | 111 | GNUNET_assert (NULL != p); |
@@ -134,17 +122,13 @@ static void | |||
134 | task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 122 | task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
135 | { | 123 | { |
136 | int *ok = cls; | 124 | int *ok = cls; |
137 | GNUNET_SCHEDULER_TaskIdentifier t2; | ||
138 | GNUNET_SCHEDULER_TaskIdentifier t4; | ||
139 | 125 | ||
140 | GNUNET_assert (1 == *ok); | 126 | GNUNET_assert (1 == *ok); |
141 | (*ok) = 2; | 127 | (*ok) = 2; |
142 | /* t2 will go first -- prereq for all */ | 128 | GNUNET_SCHEDULER_add_now (&task3, cls); |
143 | t2 = GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_NO_TASK, &task2, cls); | 129 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task2, |
144 | /* t4 will go after t2 ('add after') and after t3 (priority) */ | 130 | cls); |
145 | t4 = GNUNET_SCHEDULER_add_after (t2, &task4, cls); | 131 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &task4, cls); |
146 | /* t5 will go last (after p4) */ | ||
147 | GNUNET_SCHEDULER_add_after (t4, &task5, cls); | ||
148 | } | 132 | } |
149 | 133 | ||
150 | 134 | ||
@@ -225,8 +209,8 @@ taskCancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
225 | 209 | ||
226 | GNUNET_assert (1 == *ok); | 210 | GNUNET_assert (1 == *ok); |
227 | *ok = 0; | 211 | *ok = 0; |
228 | GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_after | 212 | GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now |
229 | (GNUNET_SCHEDULER_NO_TASK, &taskNeverRun, NULL)); | 213 | (&taskNeverRun, NULL)); |
230 | } | 214 | } |
231 | 215 | ||
232 | 216 | ||