aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am2
-rw-r--r--src/util/bandwidth.c8
-rw-r--r--src/util/client.c32
-rw-r--r--src/util/client_manager.c10
-rw-r--r--src/util/connection.c82
-rw-r--r--src/util/crypto_hash.c4
-rw-r--r--src/util/gnunet-scrypt.c4
-rw-r--r--src/util/gnunet-uri.c2
-rw-r--r--src/util/helper.c44
-rw-r--r--src/util/mq.c10
-rw-r--r--src/util/os_priority.c6
-rw-r--r--src/util/resolver_api.c48
-rw-r--r--src/util/scheduler.c621
-rw-r--r--src/util/server.c46
-rw-r--r--src/util/service.c8
-rw-r--r--src/util/speedup.c8
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c10
-rw-r--r--src/util/test_os_start_process.c2
18 files changed, 454 insertions, 493 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 6b671ad2a..a71dd76df 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -123,7 +123,7 @@ libgnunetutil_la_LIBADD = \
123 123
124libgnunetutil_la_LDFLAGS = \ 124libgnunetutil_la_LDFLAGS = \
125 $(GN_LIB_LDFLAGS) \ 125 $(GN_LIB_LDFLAGS) \
126 -version-info 12:0:0 126 -version-info 13:0:0
127 127
128if HAVE_TESTING 128if HAVE_TESTING
129 GNUNET_ECC = gnunet-ecc 129 GNUNET_ECC = gnunet-ecc
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index 18b846869..ceec09b52 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -131,7 +131,7 @@ excess_trigger (void *cls,
131{ 131{
132 struct GNUNET_BANDWIDTH_Tracker *av = cls; 132 struct GNUNET_BANDWIDTH_Tracker *av = cls;
133 133
134 av->excess_task = GNUNET_SCHEDULER_NO_TASK; 134 av->excess_task = NULL;
135 135
136 if (NULL != av->excess_cb) 136 if (NULL != av->excess_cb)
137 av->excess_cb (av->excess_cb_cls); 137 av->excess_cb (av->excess_cb_cls);
@@ -179,7 +179,7 @@ update_excess (struct GNUNET_BANDWIDTH_Tracker *av)
179 delay = GNUNET_TIME_relative_divide (delay, 179 delay = GNUNET_TIME_relative_divide (delay,
180 av->available_bytes_per_s__); 180 av->available_bytes_per_s__);
181 } 181 }
182 if (GNUNET_SCHEDULER_NO_TASK != av->excess_task) 182 if (NULL != av->excess_task)
183 GNUNET_SCHEDULER_cancel (av->excess_task); 183 GNUNET_SCHEDULER_cancel (av->excess_task);
184 av->excess_task = GNUNET_SCHEDULER_add_delayed (delay, 184 av->excess_task = GNUNET_SCHEDULER_add_delayed (delay,
185 &excess_trigger, 185 &excess_trigger,
@@ -273,9 +273,9 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
273void 273void
274GNUNET_BANDWIDTH_tracker_notification_stop (struct GNUNET_BANDWIDTH_Tracker *av) 274GNUNET_BANDWIDTH_tracker_notification_stop (struct GNUNET_BANDWIDTH_Tracker *av)
275{ 275{
276 if (GNUNET_SCHEDULER_NO_TASK != av->excess_task) 276 if (NULL != av->excess_task)
277 GNUNET_SCHEDULER_cancel (av->excess_task); 277 GNUNET_SCHEDULER_cancel (av->excess_task);
278 av->excess_task = GNUNET_SCHEDULER_NO_TASK; 278 av->excess_task = NULL;
279 av->excess_cb = NULL; 279 av->excess_cb = NULL;
280 av->excess_cb_cls = NULL; 280 av->excess_cb_cls = NULL;
281 av->update_cb = NULL; 281 av->update_cb = NULL;
diff --git a/src/util/client.c b/src/util/client.c
index c222a0ff7..7128a2de4 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -70,7 +70,7 @@ struct GNUNET_CLIENT_TransmitHandle
70 * If we are re-trying and are delaying to do so, 70 * If we are re-trying and are delaying to do so,
71 * handle to the scheduled task managing the delay. 71 * handle to the scheduled task managing the delay.
72 */ 72 */
73 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 73 struct GNUNET_SCHEDULER_Task * reconnect_task;
74 74
75 /** 75 /**
76 * Timeout for the operation overall. 76 * Timeout for the operation overall.
@@ -182,7 +182,7 @@ struct GNUNET_CLIENT_Connection
182 * If we are re-trying and are delaying to do so, 182 * If we are re-trying and are delaying to do so,
183 * handle to the scheduled task managing the delay. 183 * handle to the scheduled task managing the delay.
184 */ 184 */
185 GNUNET_SCHEDULER_TaskIdentifier receive_task; 185 struct GNUNET_SCHEDULER_Task * receive_task;
186 186
187 /** 187 /**
188 * Buffer for received message. 188 * Buffer for received message.
@@ -457,10 +457,10 @@ GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *client)
457 GNUNET_CONNECTION_destroy (client->connection); 457 GNUNET_CONNECTION_destroy (client->connection);
458 client->connection = NULL; 458 client->connection = NULL;
459 } 459 }
460 if (GNUNET_SCHEDULER_NO_TASK != client->receive_task) 460 if (NULL != client->receive_task)
461 { 461 {
462 GNUNET_SCHEDULER_cancel (client->receive_task); 462 GNUNET_SCHEDULER_cancel (client->receive_task);
463 client->receive_task = GNUNET_SCHEDULER_NO_TASK; 463 client->receive_task = NULL;
464 } 464 }
465 if (NULL != client->tag) 465 if (NULL != client->tag)
466 { 466 {
@@ -581,7 +581,7 @@ receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
581 ntohs (cmsg->type), 581 ntohs (cmsg->type),
582 msize, 582 msize,
583 client->service_name); 583 client->service_name);
584 client->receive_task = GNUNET_SCHEDULER_NO_TASK; 584 client->receive_task = NULL;
585 GNUNET_assert (GNUNET_YES == client->msg_complete); 585 GNUNET_assert (GNUNET_YES == client->msg_complete);
586 GNUNET_assert (client->received_pos >= msize); 586 GNUNET_assert (client->received_pos >= msize);
587 memcpy (msg, cmsg, msize); 587 memcpy (msg, cmsg, msize);
@@ -623,7 +623,7 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client,
623 client->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); 623 client->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
624 if (GNUNET_YES == client->msg_complete) 624 if (GNUNET_YES == client->msg_complete)
625 { 625 {
626 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->receive_task); 626 GNUNET_assert (NULL == client->receive_task);
627 client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client); 627 client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client);
628 } 628 }
629 else 629 else
@@ -670,7 +670,7 @@ struct GNUNET_CLIENT_TestHandle
670 /** 670 /**
671 * ID of task used for asynchronous operations. 671 * ID of task used for asynchronous operations.
672 */ 672 */
673 GNUNET_SCHEDULER_TaskIdentifier task; 673 struct GNUNET_SCHEDULER_Task * task;
674 674
675 /** 675 /**
676 * Final result to report back (once known). 676 * Final result to report back (once known).
@@ -697,10 +697,10 @@ GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th)
697 GNUNET_CLIENT_disconnect (th->client); 697 GNUNET_CLIENT_disconnect (th->client);
698 th->client = NULL; 698 th->client = NULL;
699 } 699 }
700 if (GNUNET_SCHEDULER_NO_TASK != th->task) 700 if (NULL != th->task)
701 { 701 {
702 GNUNET_SCHEDULER_cancel (th->task); 702 GNUNET_SCHEDULER_cancel (th->task);
703 th->task = GNUNET_SCHEDULER_NO_TASK; 703 th->task = NULL;
704 } 704 }
705 GNUNET_free (th); 705 GNUNET_free (th);
706} 706}
@@ -719,7 +719,7 @@ report_result (void *cls,
719{ 719{
720 struct GNUNET_CLIENT_TestHandle *th = cls; 720 struct GNUNET_CLIENT_TestHandle *th = cls;
721 721
722 th->task = GNUNET_SCHEDULER_NO_TASK; 722 th->task = NULL;
723 th->cb (th->cb_cls, th->result); 723 th->cb (th->cb_cls, th->result);
724 GNUNET_CLIENT_service_test_cancel (th); 724 GNUNET_CLIENT_service_test_cancel (th);
725} 725}
@@ -1053,7 +1053,7 @@ client_delayed_retry (void *cls,
1053 struct GNUNET_CLIENT_TransmitHandle *th = cls; 1053 struct GNUNET_CLIENT_TransmitHandle *th = cls;
1054 struct GNUNET_TIME_Relative delay; 1054 struct GNUNET_TIME_Relative delay;
1055 1055
1056 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 1056 th->reconnect_task = NULL;
1057 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1057 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1058 { 1058 {
1059 /* give up, was shutdown */ 1059 /* give up, was shutdown */
@@ -1077,7 +1077,7 @@ client_delayed_retry (void *cls,
1077 "Transmission failed %u times, trying again in %s.\n", 1077 "Transmission failed %u times, trying again in %s.\n",
1078 MAX_ATTEMPTS - th->attempts_left, 1078 MAX_ATTEMPTS - th->attempts_left,
1079 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1079 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1080 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->reconnect_task); 1080 GNUNET_assert (NULL == th->reconnect_task);
1081 th->reconnect_task = 1081 th->reconnect_task =
1082 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); 1082 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
1083 return; 1083 return;
@@ -1155,7 +1155,7 @@ client_notify (void *cls, size_t size, void *buf)
1155 MAX_ATTEMPTS - th->attempts_left, 1155 MAX_ATTEMPTS - th->attempts_left,
1156 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1156 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1157 client->th = th; 1157 client->th = th;
1158 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->reconnect_task); 1158 GNUNET_assert (NULL == th->reconnect_task);
1159 th->reconnect_task = 1159 th->reconnect_task =
1160 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); 1160 GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
1161 return 0; 1161 return 0;
@@ -1224,7 +1224,7 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client,
1224 client->th = th; 1224 client->th = th;
1225 if (NULL == client->connection) 1225 if (NULL == client->connection)
1226 { 1226 {
1227 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->reconnect_task); 1227 GNUNET_assert (NULL == th->reconnect_task);
1228 th->reconnect_task = 1228 th->reconnect_task =
1229 GNUNET_SCHEDULER_add_delayed (client->back_off, 1229 GNUNET_SCHEDULER_add_delayed (client->back_off,
1230 &client_delayed_retry, 1230 &client_delayed_retry,
@@ -1256,11 +1256,11 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client,
1256void 1256void
1257GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th) 1257GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th)
1258{ 1258{
1259 if (GNUNET_SCHEDULER_NO_TASK != th->reconnect_task) 1259 if (NULL != th->reconnect_task)
1260 { 1260 {
1261 GNUNET_assert (NULL == th->th); 1261 GNUNET_assert (NULL == th->th);
1262 GNUNET_SCHEDULER_cancel (th->reconnect_task); 1262 GNUNET_SCHEDULER_cancel (th->reconnect_task);
1263 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 1263 th->reconnect_task = NULL;
1264 } 1264 }
1265 else 1265 else
1266 { 1266 {
diff --git a/src/util/client_manager.c b/src/util/client_manager.c
index f27c5e392..6a462cad6 100644
--- a/src/util/client_manager.c
+++ b/src/util/client_manager.c
@@ -119,7 +119,7 @@ struct GNUNET_CLIENT_MANAGER_Connection
119 /** 119 /**
120 * Task doing exponential back-off trying to reconnect. 120 * Task doing exponential back-off trying to reconnect.
121 */ 121 */
122 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 122 struct GNUNET_SCHEDULER_Task * reconnect_task;
123 123
124 /** 124 /**
125 * Time for next connect retry. 125 * Time for next connect retry.
@@ -304,7 +304,7 @@ static void
304schedule_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 304schedule_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
305{ 305{
306 struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls; 306 struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
307 mgr->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 307 mgr->reconnect_task = NULL;
308 308
309 LOG (GNUNET_ERROR_TYPE_DEBUG, 309 LOG (GNUNET_ERROR_TYPE_DEBUG,
310 "Connecting to %s service.\n", mgr->service_name); 310 "Connecting to %s service.\n", mgr->service_name);
@@ -382,10 +382,10 @@ GNUNET_CLIENT_MANAGER_disconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
382 GNUNET_CLIENT_MANAGER_drop_queue (mgr); 382 GNUNET_CLIENT_MANAGER_drop_queue (mgr);
383 } 383 }
384 } 384 }
385 if (mgr->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 385 if (mgr->reconnect_task != NULL)
386 { 386 {
387 GNUNET_SCHEDULER_cancel (mgr->reconnect_task); 387 GNUNET_SCHEDULER_cancel (mgr->reconnect_task);
388 mgr->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 388 mgr->reconnect_task = NULL;
389 } 389 }
390 if (NULL != mgr->client_tmit) 390 if (NULL != mgr->client_tmit)
391 { 391 {
@@ -413,7 +413,7 @@ GNUNET_CLIENT_MANAGER_disconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
413void 413void
414GNUNET_CLIENT_MANAGER_reconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr) 414GNUNET_CLIENT_MANAGER_reconnect (struct GNUNET_CLIENT_MANAGER_Connection *mgr)
415{ 415{
416 if (GNUNET_SCHEDULER_NO_TASK != mgr->reconnect_task) 416 if (NULL != mgr->reconnect_task)
417 return; 417 return;
418 418
419 if (NULL != mgr->client_tmit) 419 if (NULL != mgr->client_tmit)
diff --git a/src/util/connection.c b/src/util/connection.c
index 79d1c2d4c..f28beb34c 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -70,7 +70,7 @@ struct GNUNET_CONNECTION_TransmitHandle
70 /** 70 /**
71 * Task called on timeout. 71 * Task called on timeout.
72 */ 72 */
73 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 73 struct GNUNET_SCHEDULER_Task * timeout_task;
74 74
75 /** 75 /**
76 * At what number of bytes available in the 76 * At what number of bytes available in the
@@ -121,7 +121,7 @@ struct AddressProbe
121 /** 121 /**
122 * Task waiting for the connection to finish connecting. 122 * Task waiting for the connection to finish connecting.
123 */ 123 */
124 GNUNET_SCHEDULER_TaskIdentifier task; 124 struct GNUNET_SCHEDULER_Task * task;
125}; 125};
126 126
127 127
@@ -204,12 +204,12 @@ struct GNUNET_CONNECTION_Handle
204 /** 204 /**
205 * Read task that we may need to wait for. 205 * Read task that we may need to wait for.
206 */ 206 */
207 GNUNET_SCHEDULER_TaskIdentifier read_task; 207 struct GNUNET_SCHEDULER_Task * read_task;
208 208
209 /** 209 /**
210 * Write task that we may need to wait for. 210 * Write task that we may need to wait for.
211 */ 211 */
212 GNUNET_SCHEDULER_TaskIdentifier write_task; 212 struct GNUNET_SCHEDULER_Task * write_task;
213 213
214 /** 214 /**
215 * Handle to a pending DNS lookup request. 215 * Handle to a pending DNS lookup request.
@@ -522,13 +522,13 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection,
522 GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); 522 GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR);
523 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); 523 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
524 connection->sock = NULL; 524 connection->sock = NULL;
525 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); 525 GNUNET_assert (NULL == connection->write_task);
526 } 526 }
527 if (GNUNET_SCHEDULER_NO_TASK != connection->read_task) 527 if (NULL != connection->read_task)
528 { 528 {
529 /* send errors trigger read errors... */ 529 /* send errors trigger read errors... */
530 GNUNET_SCHEDULER_cancel (connection->read_task); 530 GNUNET_SCHEDULER_cancel (connection->read_task);
531 connection->read_task = GNUNET_SCHEDULER_NO_TASK; 531 connection->read_task = NULL;
532 signal_receive_timeout (connection); 532 signal_receive_timeout (connection);
533 return; 533 return;
534 } 534 }
@@ -556,7 +556,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
556 GNUNET_break (NULL == connection->ap_tail); 556 GNUNET_break (NULL == connection->ap_tail);
557 GNUNET_break (GNUNET_NO == connection->dns_active); 557 GNUNET_break (GNUNET_NO == connection->dns_active);
558 GNUNET_break (NULL == connection->sock); 558 GNUNET_break (NULL == connection->sock);
559 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); 559 GNUNET_assert (NULL == connection->write_task);
560 560
561 /* signal errors for jobs that used to wait on the connection */ 561 /* signal errors for jobs that used to wait on the connection */
562 connection->destroy_later = 1; 562 connection->destroy_later = 1;
@@ -564,9 +564,9 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
564 signal_receive_error (connection, ECONNREFUSED); 564 signal_receive_error (connection, ECONNREFUSED);
565 if (NULL != connection->nth.notify_ready) 565 if (NULL != connection->nth.notify_ready)
566 { 566 {
567 GNUNET_assert (connection->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); 567 GNUNET_assert (connection->nth.timeout_task != NULL);
568 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); 568 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
569 connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 569 connection->nth.timeout_task = NULL;
570 signal_transmit_error (connection, ECONNREFUSED); 570 signal_transmit_error (connection, ECONNREFUSED);
571 } 571 }
572 if (-1 == connection->destroy_later) 572 if (-1 == connection->destroy_later)
@@ -618,7 +618,7 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
618 LOG (GNUNET_ERROR_TYPE_DEBUG, 618 LOG (GNUNET_ERROR_TYPE_DEBUG,
619 "Connection succeeded, starting with receiving data (%p)\n", 619 "Connection succeeded, starting with receiving data (%p)\n",
620 connection); 620 connection);
621 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->read_task); 621 GNUNET_assert (NULL == connection->read_task);
622 connection->read_task = 622 connection->read_task =
623 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining 623 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
624 (connection->receive_timeout), connection->sock, 624 (connection->receive_timeout), connection->sock,
@@ -629,10 +629,10 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
629 LOG (GNUNET_ERROR_TYPE_DEBUG, 629 LOG (GNUNET_ERROR_TYPE_DEBUG,
630 "Connection succeeded, starting with sending data (%p)\n", 630 "Connection succeeded, starting with sending data (%p)\n",
631 connection); 631 connection);
632 GNUNET_assert (connection->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); 632 GNUNET_assert (connection->nth.timeout_task != NULL);
633 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); 633 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
634 connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 634 connection->nth.timeout_task = NULL;
635 GNUNET_assert (connection->write_task == GNUNET_SCHEDULER_NO_TASK); 635 GNUNET_assert (connection->write_task == NULL);
636 connection->write_task = 636 connection->write_task =
637 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining 637 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
638 (connection->nth.transmit_timeout), connection->sock, 638 (connection->nth.transmit_timeout), connection->sock,
@@ -982,21 +982,21 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
982 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); 982 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection);
983 GNUNET_assert (NULL == connection->nth.notify_ready); 983 GNUNET_assert (NULL == connection->nth.notify_ready);
984 GNUNET_assert (NULL == connection->receiver); 984 GNUNET_assert (NULL == connection->receiver);
985 if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) 985 if (NULL != connection->write_task)
986 { 986 {
987 GNUNET_SCHEDULER_cancel (connection->write_task); 987 GNUNET_SCHEDULER_cancel (connection->write_task);
988 connection->write_task = GNUNET_SCHEDULER_NO_TASK; 988 connection->write_task = NULL;
989 connection->write_buffer_off = 0; 989 connection->write_buffer_off = 0;
990 } 990 }
991 if (GNUNET_SCHEDULER_NO_TASK != connection->read_task) 991 if (NULL != connection->read_task)
992 { 992 {
993 GNUNET_SCHEDULER_cancel (connection->read_task); 993 GNUNET_SCHEDULER_cancel (connection->read_task);
994 connection->read_task = GNUNET_SCHEDULER_NO_TASK; 994 connection->read_task = NULL;
995 } 995 }
996 if (GNUNET_SCHEDULER_NO_TASK != connection->nth.timeout_task) 996 if (NULL != connection->nth.timeout_task)
997 { 997 {
998 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); 998 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
999 connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 999 connection->nth.timeout_task = NULL;
1000 } 1000 }
1001 connection->nth.notify_ready = NULL; 1001 connection->nth.notify_ready = NULL;
1002 if (NULL != connection->dns_active) 1002 if (NULL != connection->dns_active)
@@ -1051,7 +1051,7 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1051 ssize_t ret; 1051 ssize_t ret;
1052 GNUNET_CONNECTION_Receiver receiver; 1052 GNUNET_CONNECTION_Receiver receiver;
1053 1053
1054 connection->read_task = GNUNET_SCHEDULER_NO_TASK; 1054 connection->read_task = NULL;
1055 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1055 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1056 { 1056 {
1057 /* ignore shutdown request, go again immediately */ 1057 /* ignore shutdown request, go again immediately */
@@ -1115,7 +1115,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t m
1115 GNUNET_CONNECTION_Receiver receiver, 1115 GNUNET_CONNECTION_Receiver receiver,
1116 void *receiver_cls) 1116 void *receiver_cls)
1117{ 1117{
1118 GNUNET_assert ((GNUNET_SCHEDULER_NO_TASK == connection->read_task) && 1118 GNUNET_assert ((NULL == connection->read_task) &&
1119 (NULL == connection->receiver)); 1119 (NULL == connection->receiver));
1120 GNUNET_assert (NULL != receiver); 1120 GNUNET_assert (NULL != receiver);
1121 connection->receiver = receiver; 1121 connection->receiver = receiver;
@@ -1150,10 +1150,10 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t m
1150void * 1150void *
1151GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection) 1151GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection)
1152{ 1152{
1153 if (GNUNET_SCHEDULER_NO_TASK != connection->read_task) 1153 if (NULL != connection->read_task)
1154 { 1154 {
1155 GNUNET_assert (connection == GNUNET_SCHEDULER_cancel (connection->read_task)); 1155 GNUNET_assert (connection == GNUNET_SCHEDULER_cancel (connection->read_task));
1156 connection->read_task = GNUNET_SCHEDULER_NO_TASK; 1156 connection->read_task = NULL;
1157 } 1157 }
1158 connection->receiver = NULL; 1158 connection->receiver = NULL;
1159 return connection->receiver_cls; 1159 return connection->receiver_cls;
@@ -1177,7 +1177,7 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection)
1177 1177
1178 LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); 1178 LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n");
1179 1179
1180 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); 1180 GNUNET_assert (NULL == connection->write_task);
1181 if (NULL == (notify = connection->nth.notify_ready)) 1181 if (NULL == (notify = connection->nth.notify_ready))
1182 { 1182 {
1183 LOG (GNUNET_ERROR_TYPE_DEBUG, "Noone to notify\n"); 1183 LOG (GNUNET_ERROR_TYPE_DEBUG, "Noone to notify\n");
@@ -1229,7 +1229,7 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1229 struct GNUNET_CONNECTION_Handle *connection = cls; 1229 struct GNUNET_CONNECTION_Handle *connection = cls;
1230 GNUNET_CONNECTION_TransmitReadyNotify notify; 1230 GNUNET_CONNECTION_TransmitReadyNotify notify;
1231 1231
1232 connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 1232 connection->nth.timeout_task = NULL;
1233 LOG (GNUNET_ERROR_TYPE_DEBUG, 1233 LOG (GNUNET_ERROR_TYPE_DEBUG,
1234 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1234 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1235 connection->hostname, 1235 connection->hostname,
@@ -1259,7 +1259,7 @@ connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1259 LOG (GNUNET_ERROR_TYPE_DEBUG, 1259 LOG (GNUNET_ERROR_TYPE_DEBUG,
1260 "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", 1260 "Transmission request of size %u fails (%s/%u), connection failed (%p).\n",
1261 connection->nth.notify_size, connection->hostname, connection->port, connection); 1261 connection->nth.notify_size, connection->hostname, connection->port, connection);
1262 connection->write_task = GNUNET_SCHEDULER_NO_TASK; 1262 connection->write_task = NULL;
1263 notify = connection->nth.notify_ready; 1263 notify = connection->nth.notify_ready;
1264 connection->nth.notify_ready = NULL; 1264 connection->nth.notify_ready = NULL;
1265 notify (connection->nth.notify_ready_cls, 0, NULL); 1265 notify (connection->nth.notify_ready_cls, 0, NULL);
@@ -1281,9 +1281,9 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1281 size_t have; 1281 size_t have;
1282 1282
1283 LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); 1283 LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection);
1284 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != connection->write_task); 1284 GNUNET_assert (NULL != connection->write_task);
1285 connection->write_task = GNUNET_SCHEDULER_NO_TASK; 1285 connection->write_task = NULL;
1286 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->nth.timeout_task); 1286 GNUNET_assert (NULL == connection->nth.timeout_task);
1287 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1287 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1288 { 1288 {
1289 if (NULL != connection->sock) 1289 if (NULL != connection->sock)
@@ -1320,7 +1320,7 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1320 } 1320 }
1321 if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) 1321 if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
1322 { 1322 {
1323 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); 1323 GNUNET_assert (NULL == connection->write_task);
1324 /* special circumstances (in particular, shutdown): not yet ready 1324 /* special circumstances (in particular, shutdown): not yet ready
1325 * to write, but no "fatal" error either. Hence retry. */ 1325 * to write, but no "fatal" error either. Hence retry. */
1326 goto SCHEDULE_WRITE; 1326 goto SCHEDULE_WRITE;
@@ -1352,10 +1352,10 @@ RETRY:
1352 { 1352 {
1353 if (EINTR == errno) 1353 if (EINTR == errno)
1354 goto RETRY; 1354 goto RETRY;
1355 if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) 1355 if (NULL != connection->write_task)
1356 { 1356 {
1357 GNUNET_SCHEDULER_cancel (connection->write_task); 1357 GNUNET_SCHEDULER_cancel (connection->write_task);
1358 connection->write_task = GNUNET_SCHEDULER_NO_TASK; 1358 connection->write_task = NULL;
1359 } 1359 }
1360 signal_transmit_error (connection, errno); 1360 signal_transmit_error (connection, errno);
1361 return; 1361 return;
@@ -1378,7 +1378,7 @@ SCHEDULE_WRITE:
1378 "Re-scheduling transmit_ready (more to do) (%p).\n", connection); 1378 "Re-scheduling transmit_ready (more to do) (%p).\n", connection);
1379 have = connection->write_buffer_off - connection->write_buffer_pos; 1379 have = connection->write_buffer_off - connection->write_buffer_pos;
1380 GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); 1380 GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
1381 if (GNUNET_SCHEDULER_NO_TASK == connection->write_task) 1381 if (NULL == connection->write_task)
1382 connection->write_task = 1382 connection->write_task =
1383 GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == 1383 GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready ==
1384 NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : 1384 NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
@@ -1424,17 +1424,17 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec
1424 connection->nth.connection = connection; 1424 connection->nth.connection = connection;
1425 connection->nth.notify_size = size; 1425 connection->nth.notify_size = size;
1426 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1426 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1427 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->nth.timeout_task); 1427 GNUNET_assert (NULL == connection->nth.timeout_task);
1428 if ((NULL == connection->sock) && 1428 if ((NULL == connection->sock) &&
1429 (NULL == connection->ap_head) && 1429 (NULL == connection->ap_head) &&
1430 (NULL == connection->dns_active)) 1430 (NULL == connection->dns_active))
1431 { 1431 {
1432 if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) 1432 if (NULL != connection->write_task)
1433 GNUNET_SCHEDULER_cancel (connection->write_task); 1433 GNUNET_SCHEDULER_cancel (connection->write_task);
1434 connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, connection); 1434 connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, connection);
1435 return &connection->nth; 1435 return &connection->nth;
1436 } 1436 }
1437 if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) 1437 if (NULL != connection->write_task)
1438 return &connection->nth; /* previous transmission still in progress */ 1438 return &connection->nth; /* previous transmission still in progress */
1439 if (NULL != connection->sock) 1439 if (NULL != connection->sock)
1440 { 1440 {
@@ -1467,15 +1467,15 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
1467{ 1467{
1468 GNUNET_assert (NULL != th->notify_ready); 1468 GNUNET_assert (NULL != th->notify_ready);
1469 th->notify_ready = NULL; 1469 th->notify_ready = NULL;
1470 if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task) 1470 if (NULL != th->timeout_task)
1471 { 1471 {
1472 GNUNET_SCHEDULER_cancel (th->timeout_task); 1472 GNUNET_SCHEDULER_cancel (th->timeout_task);
1473 th->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1473 th->timeout_task = NULL;
1474 } 1474 }
1475 if (GNUNET_SCHEDULER_NO_TASK != th->connection->write_task) 1475 if (NULL != th->connection->write_task)
1476 { 1476 {
1477 GNUNET_SCHEDULER_cancel (th->connection->write_task); 1477 GNUNET_SCHEDULER_cancel (th->connection->write_task);
1478 th->connection->write_task = GNUNET_SCHEDULER_NO_TASK; 1478 th->connection->write_task = NULL;
1479 } 1479 }
1480} 1480}
1481 1481
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index ac64d68e1..d68e890a7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -98,7 +98,7 @@ struct GNUNET_CRYPTO_FileHashContext
98 /** 98 /**
99 * Current task for hashing. 99 * Current task for hashing.
100 */ 100 */
101 GNUNET_SCHEDULER_TaskIdentifier task; 101 struct GNUNET_SCHEDULER_Task * task;
102 102
103 /** 103 /**
104 * Priority we use. 104 * Priority we use.
@@ -143,7 +143,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
143 struct GNUNET_HashCode *res; 143 struct GNUNET_HashCode *res;
144 size_t delta; 144 size_t delta;
145 145
146 fhc->task = GNUNET_SCHEDULER_NO_TASK; 146 fhc->task = NULL;
147 GNUNET_assert (fhc->offset <= fhc->fsize); 147 GNUNET_assert (fhc->offset <= fhc->fsize);
148 delta = fhc->bsize; 148 delta = fhc->bsize;
149 if (fhc->fsize - fhc->offset < delta) 149 if (fhc->fsize - fhc->offset < delta)
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index b6a9969da..6e3fcd33a 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -40,7 +40,7 @@ static struct GNUNET_CRYPTO_EddsaPublicKey pub;
40 40
41static uint64_t proof; 41static uint64_t proof;
42 42
43static GNUNET_SCHEDULER_TaskIdentifier proof_task; 43static struct GNUNET_SCHEDULER_Task * proof_task;
44 44
45static const struct GNUNET_CONFIGURATION_Handle *cfg; 45static const struct GNUNET_CONFIGURATION_Handle *cfg;
46 46
@@ -128,7 +128,7 @@ find_proof (void *cls,
128 return; 128 return;
129 } 129 }
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got Proof of Work %llu\n", proof); 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got Proof of Work %llu\n", proof);
131 proof_task = GNUNET_SCHEDULER_NO_TASK; 131 proof_task = NULL;
132 memcpy (&buf[sizeof (uint64_t)], &pub, 132 memcpy (&buf[sizeof (uint64_t)], &pub,
133 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); 133 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
134 i = 0; 134 i = 0;
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index 545b78981..8e4930da4 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.c
@@ -77,7 +77,7 @@ run (void *cls, char *const *args, const char *cfgfile,
77 const char *slash; 77 const char *slash;
78 char *subsystem; 78 char *subsystem;
79 char *program; 79 char *program;
80 GNUNET_SCHEDULER_TaskIdentifier rt; 80 struct GNUNET_SCHEDULER_Task * rt;
81 81
82 if (NULL == (uri = args[0])) 82 if (NULL == (uri = args[0]))
83 { 83 {
diff --git a/src/util/helper.c b/src/util/helper.c
index 105ccf057..6dd417a91 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -142,17 +142,17 @@ struct GNUNET_HELPER_Handle
142 /** 142 /**
143 * Task to read from the helper. 143 * Task to read from the helper.
144 */ 144 */
145 GNUNET_SCHEDULER_TaskIdentifier read_task; 145 struct GNUNET_SCHEDULER_Task * read_task;
146 146
147 /** 147 /**
148 * Task to read from the helper. 148 * Task to read from the helper.
149 */ 149 */
150 GNUNET_SCHEDULER_TaskIdentifier write_task; 150 struct GNUNET_SCHEDULER_Task * write_task;
151 151
152 /** 152 /**
153 * Restart task. 153 * Restart task.
154 */ 154 */
155 GNUNET_SCHEDULER_TaskIdentifier restart_task; 155 struct GNUNET_SCHEDULER_Task * restart_task;
156 156
157 /** 157 /**
158 * Does the helper support the use of a control pipe for signalling? 158 * Does the helper support the use of a control pipe for signalling?
@@ -187,15 +187,15 @@ GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
187 sh->cont (sh->cont_cls, GNUNET_NO); 187 sh->cont (sh->cont_cls, GNUNET_NO);
188 GNUNET_free (sh); 188 GNUNET_free (sh);
189 } 189 }
190 if (GNUNET_SCHEDULER_NO_TASK != h->restart_task) 190 if (NULL != h->restart_task)
191 { 191 {
192 GNUNET_SCHEDULER_cancel (h->restart_task); 192 GNUNET_SCHEDULER_cancel (h->restart_task);
193 h->restart_task = GNUNET_SCHEDULER_NO_TASK; 193 h->restart_task = NULL;
194 } 194 }
195 if (GNUNET_SCHEDULER_NO_TASK != h->read_task) 195 if (NULL != h->read_task)
196 { 196 {
197 GNUNET_SCHEDULER_cancel (h->read_task); 197 GNUNET_SCHEDULER_cancel (h->read_task);
198 h->read_task = GNUNET_SCHEDULER_NO_TASK; 198 h->read_task = NULL;
199 } 199 }
200 if (NULL == h->helper_proc) 200 if (NULL == h->helper_proc)
201 return GNUNET_SYSERR; 201 return GNUNET_SYSERR;
@@ -235,15 +235,15 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
235 GNUNET_OS_process_destroy (h->helper_proc); 235 GNUNET_OS_process_destroy (h->helper_proc);
236 h->helper_proc = NULL; 236 h->helper_proc = NULL;
237 } 237 }
238 if (GNUNET_SCHEDULER_NO_TASK != h->read_task) 238 if (NULL != h->read_task)
239 { 239 {
240 GNUNET_SCHEDULER_cancel (h->read_task); 240 GNUNET_SCHEDULER_cancel (h->read_task);
241 h->read_task = GNUNET_SCHEDULER_NO_TASK; 241 h->read_task = NULL;
242 } 242 }
243 if (GNUNET_SCHEDULER_NO_TASK != h->write_task) 243 if (NULL != h->write_task)
244 { 244 {
245 GNUNET_SCHEDULER_cancel (h->write_task); 245 GNUNET_SCHEDULER_cancel (h->write_task);
246 h->write_task = GNUNET_SCHEDULER_NO_TASK; 246 h->write_task = NULL;
247 } 247 }
248 if (NULL != h->helper_in) 248 if (NULL != h->helper_in)
249 { 249 {
@@ -284,10 +284,10 @@ static void
284stop_helper (struct GNUNET_HELPER_Handle *h, 284stop_helper (struct GNUNET_HELPER_Handle *h,
285 int soft_kill) 285 int soft_kill)
286{ 286{
287 if (GNUNET_SCHEDULER_NO_TASK != h->restart_task) 287 if (NULL != h->restart_task)
288 { 288 {
289 GNUNET_SCHEDULER_cancel (h->restart_task); 289 GNUNET_SCHEDULER_cancel (h->restart_task);
290 h->restart_task = GNUNET_SCHEDULER_NO_TASK; 290 h->restart_task = NULL;
291 } 291 }
292 else 292 else
293 { 293 {
@@ -322,7 +322,7 @@ helper_read (void *cls,
322 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN; 322 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
323 ssize_t t; 323 ssize_t t;
324 324
325 h->read_task = GNUNET_SCHEDULER_NO_TASK; 325 h->read_task = NULL;
326 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 326 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
327 { 327 {
328 /* try again */ 328 /* try again */
@@ -460,7 +460,7 @@ restart_task (void *cls,
460{ 460{
461 struct GNUNET_HELPER_Handle*h = cls; 461 struct GNUNET_HELPER_Handle*h = cls;
462 462
463 h->restart_task = GNUNET_SCHEDULER_NO_TASK; 463 h->restart_task = NULL;
464 start_helper (h); 464 start_helper (h);
465} 465}
466 466
@@ -524,13 +524,13 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
524 unsigned int c; 524 unsigned int c;
525 struct GNUNET_HELPER_SendHandle *sh; 525 struct GNUNET_HELPER_SendHandle *sh;
526 526
527 if (GNUNET_SCHEDULER_NO_TASK != h->write_task) 527 if (NULL != h->write_task)
528 { 528 {
529 GNUNET_SCHEDULER_cancel (h->write_task); 529 GNUNET_SCHEDULER_cancel (h->write_task);
530 h->write_task = GNUNET_SCHEDULER_NO_TASK; 530 h->write_task = NULL;
531 } 531 }
532 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->read_task); 532 GNUNET_assert (NULL == h->read_task);
533 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->restart_task); 533 GNUNET_assert (NULL == h->restart_task);
534 while (NULL != (sh = h->sh_head)) 534 while (NULL != (sh = h->sh_head))
535 { 535 {
536 GNUNET_CONTAINER_DLL_remove (h->sh_head, 536 GNUNET_CONTAINER_DLL_remove (h->sh_head,
@@ -582,7 +582,7 @@ helper_write (void *cls,
582 const char *buf; 582 const char *buf;
583 ssize_t t; 583 ssize_t t;
584 584
585 h->write_task = GNUNET_SCHEDULER_NO_TASK; 585 h->write_task = NULL;
586 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 586 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
587 { 587 {
588 /* try again */ 588 /* try again */
@@ -684,7 +684,7 @@ GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
684 GNUNET_CONTAINER_DLL_insert_tail (h->sh_head, 684 GNUNET_CONTAINER_DLL_insert_tail (h->sh_head,
685 h->sh_tail, 685 h->sh_tail,
686 sh); 686 sh);
687 if (GNUNET_SCHEDULER_NO_TASK == h->write_task) 687 if (NULL == h->write_task)
688 h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 688 h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
689 h->fh_to_helper, 689 h->fh_to_helper,
690 &helper_write, 690 &helper_write,
@@ -714,7 +714,7 @@ GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh)
714 if (NULL == h->sh_head) 714 if (NULL == h->sh_head)
715 { 715 {
716 GNUNET_SCHEDULER_cancel (h->write_task); 716 GNUNET_SCHEDULER_cancel (h->write_task);
717 h->write_task = GNUNET_SCHEDULER_NO_TASK; 717 h->write_task = NULL;
718 } 718 }
719 } 719 }
720} 720}
diff --git a/src/util/mq.c b/src/util/mq.c
index d34850b8c..254e5d33e 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -133,7 +133,7 @@ struct GNUNET_MQ_Handle
133 /** 133 /**
134 * Task scheduled during #GNUNET_MQ_impl_send_continue. 134 * Task scheduled during #GNUNET_MQ_impl_send_continue.
135 */ 135 */
136 GNUNET_SCHEDULER_TaskIdentifier continue_task; 136 struct GNUNET_SCHEDULER_Task * continue_task;
137 137
138 /** 138 /**
139 * Next id that should be used for the @e assoc_map, 139 * Next id that should be used for the @e assoc_map,
@@ -310,7 +310,7 @@ impl_send_continue (void *cls,
310 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 310 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
311 return; 311 return;
312 312
313 mq->continue_task = GNUNET_SCHEDULER_NO_TASK; 313 mq->continue_task = NULL;
314 /* call is only valid if we're actually currently sending 314 /* call is only valid if we're actually currently sending
315 * a message */ 315 * a message */
316 current_envelope = mq->current_envelope; 316 current_envelope = mq->current_envelope;
@@ -345,7 +345,7 @@ impl_send_continue (void *cls,
345void 345void
346GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq) 346GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
347{ 347{
348 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == mq->continue_task); 348 GNUNET_assert (NULL == mq->continue_task);
349 mq->continue_task = GNUNET_SCHEDULER_add_now (&impl_send_continue, 349 mq->continue_task = GNUNET_SCHEDULER_add_now (&impl_send_continue,
350 mq); 350 mq);
351} 351}
@@ -776,10 +776,10 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
776 { 776 {
777 mq->destroy_impl (mq, mq->impl_state); 777 mq->destroy_impl (mq, mq->impl_state);
778 } 778 }
779 if (GNUNET_SCHEDULER_NO_TASK != mq->continue_task) 779 if (NULL != mq->continue_task)
780 { 780 {
781 GNUNET_SCHEDULER_cancel (mq->continue_task); 781 GNUNET_SCHEDULER_cancel (mq->continue_task);
782 mq->continue_task = GNUNET_SCHEDULER_NO_TASK; 782 mq->continue_task = NULL;
783 } 783 }
784 while (NULL != mq->envelope_head) 784 while (NULL != mq->envelope_head)
785 { 785 {
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index d3310abb1..a76a5cc4a 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -1693,7 +1693,7 @@ struct GNUNET_OS_CommandHandle
1693 /** 1693 /**
1694 * Task reading from pipe. 1694 * Task reading from pipe.
1695 */ 1695 */
1696 GNUNET_SCHEDULER_TaskIdentifier rtask; 1696 struct GNUNET_SCHEDULER_Task * rtask;
1697 1697
1698 /** 1698 /**
1699 * When to time out. 1699 * When to time out.
@@ -1719,7 +1719,7 @@ GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
1719{ 1719{
1720 if (NULL != cmd->proc) 1720 if (NULL != cmd->proc)
1721 { 1721 {
1722 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cmd->rtask); 1722 GNUNET_assert (NULL != cmd->rtask);
1723 GNUNET_SCHEDULER_cancel (cmd->rtask); 1723 GNUNET_SCHEDULER_cancel (cmd->rtask);
1724 } 1724 }
1725 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL); 1725 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
@@ -1744,7 +1744,7 @@ cmd_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1744 char *end; 1744 char *end;
1745 ssize_t ret; 1745 ssize_t ret;
1746 1746
1747 cmd->rtask = GNUNET_SCHEDULER_NO_TASK; 1747 cmd->rtask = NULL;
1748 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r)) 1748 if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
1749 { 1749 {
1750 /* timeout, shutdown, etc. */ 1750 /* timeout, shutdown, etc. */
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index f3988c7c5..8ddaafa0a 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -78,13 +78,13 @@ static struct GNUNET_TIME_Relative backoff;
78/** 78/**
79 * Task for reconnecting. 79 * Task for reconnecting.
80 */ 80 */
81static GNUNET_SCHEDULER_TaskIdentifier r_task; 81static struct GNUNET_SCHEDULER_Task * r_task;
82 82
83/** 83/**
84 * Task ID of shutdown task; only present while we have a 84 * Task ID of shutdown task; only present while we have a
85 * connection to the resolver service. 85 * connection to the resolver service.
86 */ 86 */
87static GNUNET_SCHEDULER_TaskIdentifier s_task; 87static struct GNUNET_SCHEDULER_Task * s_task;
88 88
89 89
90/** 90/**
@@ -131,7 +131,7 @@ struct GNUNET_RESOLVER_RequestHandle
131 * Task handle for making reply callbacks in numeric lookups 131 * Task handle for making reply callbacks in numeric lookups
132 * asynchronous, and for timeout handling. 132 * asynchronous, and for timeout handling.
133 */ 133 */
134 GNUNET_SCHEDULER_TaskIdentifier task; 134 struct GNUNET_SCHEDULER_Task * task;
135 135
136 /** 136 /**
137 * Desired address family. 137 * Desired address family.
@@ -256,15 +256,15 @@ GNUNET_RESOLVER_disconnect ()
256 GNUNET_CLIENT_disconnect (client); 256 GNUNET_CLIENT_disconnect (client);
257 client = NULL; 257 client = NULL;
258 } 258 }
259 if (GNUNET_SCHEDULER_NO_TASK != r_task) 259 if (NULL != r_task)
260 { 260 {
261 GNUNET_SCHEDULER_cancel (r_task); 261 GNUNET_SCHEDULER_cancel (r_task);
262 r_task = GNUNET_SCHEDULER_NO_TASK; 262 r_task = NULL;
263 } 263 }
264 if (GNUNET_SCHEDULER_NO_TASK != s_task) 264 if (NULL != s_task)
265 { 265 {
266 GNUNET_SCHEDULER_cancel (s_task); 266 GNUNET_SCHEDULER_cancel (s_task);
267 s_task = GNUNET_SCHEDULER_NO_TASK; 267 s_task = NULL;
268 } 268 }
269} 269}
270 270
@@ -381,7 +381,7 @@ handle_response (void *cls,
381 rh->addr_callback (rh->cls, NULL, 0); 381 rh->addr_callback (rh->cls, NULL, 0);
382 } 382 }
383 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 383 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
384 if (GNUNET_SCHEDULER_NO_TASK != rh->task) 384 if (NULL != rh->task)
385 GNUNET_SCHEDULER_cancel (rh->task); 385 GNUNET_SCHEDULER_cancel (rh->task);
386 GNUNET_free (rh); 386 GNUNET_free (rh);
387 GNUNET_CLIENT_disconnect (client); 387 GNUNET_CLIENT_disconnect (client);
@@ -410,7 +410,7 @@ handle_response (void *cls,
410 rh->addr_callback (rh->cls, NULL, 0); 410 rh->addr_callback (rh->cls, NULL, 0);
411 } 411 }
412 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 412 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
413 if (GNUNET_SCHEDULER_NO_TASK != rh->task) 413 if (NULL != rh->task)
414 GNUNET_SCHEDULER_cancel (rh->task); 414 GNUNET_SCHEDULER_cancel (rh->task);
415 GNUNET_free (rh); 415 GNUNET_free (rh);
416 process_requests (); 416 process_requests ();
@@ -428,7 +428,7 @@ handle_response (void *cls,
428 if (GNUNET_SYSERR != rh->was_transmitted) 428 if (GNUNET_SYSERR != rh->was_transmitted)
429 rh->name_callback (rh->cls, NULL); 429 rh->name_callback (rh->cls, NULL);
430 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 430 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
431 if (GNUNET_SCHEDULER_NO_TASK != rh->task) 431 if (NULL != rh->task)
432 GNUNET_SCHEDULER_cancel (rh->task); 432 GNUNET_SCHEDULER_cancel (rh->task);
433 GNUNET_free (rh); 433 GNUNET_free (rh);
434 GNUNET_CLIENT_disconnect (client); 434 GNUNET_CLIENT_disconnect (client);
@@ -485,7 +485,7 @@ handle_response (void *cls,
485 if (GNUNET_SYSERR != rh->was_transmitted) 485 if (GNUNET_SYSERR != rh->was_transmitted)
486 rh->addr_callback (rh->cls, NULL, 0); 486 rh->addr_callback (rh->cls, NULL, 0);
487 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh); 487 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
488 if (GNUNET_SCHEDULER_NO_TASK != rh->task) 488 if (NULL != rh->task)
489 GNUNET_SCHEDULER_cancel (rh->task); 489 GNUNET_SCHEDULER_cancel (rh->task);
490 GNUNET_free (rh); 490 GNUNET_free (rh);
491 GNUNET_CLIENT_disconnect (client); 491 GNUNET_CLIENT_disconnect (client);
@@ -519,7 +519,7 @@ numeric_resolution (void *cls,
519 struct sockaddr_in6 v6; 519 struct sockaddr_in6 v6;
520 const char *hostname; 520 const char *hostname;
521 521
522 rh->task = GNUNET_SCHEDULER_NO_TASK; 522 rh->task = NULL;
523 memset (&v4, 0, sizeof (v4)); 523 memset (&v4, 0, sizeof (v4));
524 v4.sin_family = AF_INET; 524 v4.sin_family = AF_INET;
525#if HAVE_SOCKADDR_IN_SIN_LEN 525#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -582,7 +582,7 @@ loopback_resolution (void *cls,
582 struct sockaddr_in v4; 582 struct sockaddr_in v4;
583 struct sockaddr_in6 v6; 583 struct sockaddr_in6 v6;
584 584
585 rh->task = GNUNET_SCHEDULER_NO_TASK; 585 rh->task = NULL;
586 memset (&v4, 0, sizeof (v4)); 586 memset (&v4, 0, sizeof (v4));
587 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 587 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
588 v4.sin_family = AF_INET; 588 v4.sin_family = AF_INET;
@@ -625,7 +625,7 @@ static void
625shutdown_task (void *cls, 625shutdown_task (void *cls,
626 const struct GNUNET_SCHEDULER_TaskContext *tc) 626 const struct GNUNET_SCHEDULER_TaskContext *tc)
627{ 627{
628 s_task = GNUNET_SCHEDULER_NO_TASK; 628 s_task = NULL;
629 GNUNET_RESOLVER_disconnect (); 629 GNUNET_RESOLVER_disconnect ();
630 backoff = GNUNET_TIME_UNIT_MILLISECONDS; 630 backoff = GNUNET_TIME_UNIT_MILLISECONDS;
631} 631}
@@ -694,7 +694,7 @@ static void
694reconnect_task (void *cls, 694reconnect_task (void *cls,
695 const struct GNUNET_SCHEDULER_TaskContext *tc) 695 const struct GNUNET_SCHEDULER_TaskContext *tc)
696{ 696{
697 r_task = GNUNET_SCHEDULER_NO_TASK; 697 r_task = NULL;
698 if (NULL == req_head) 698 if (NULL == req_head)
699 return; /* no work pending */ 699 return; /* no work pending */
700 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 700 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -721,7 +721,7 @@ reconnect ()
721{ 721{
722 struct GNUNET_RESOLVER_RequestHandle *rh; 722 struct GNUNET_RESOLVER_RequestHandle *rh;
723 723
724 if (GNUNET_SCHEDULER_NO_TASK != r_task) 724 if (NULL != r_task)
725 return; 725 return;
726 GNUNET_assert (NULL == client); 726 GNUNET_assert (NULL == client);
727 if (NULL != (rh = req_head)) 727 if (NULL != (rh = req_head))
@@ -766,7 +766,7 @@ handle_lookup_timeout (void *cls,
766{ 766{
767 struct GNUNET_RESOLVER_RequestHandle *rh = cls; 767 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
768 768
769 rh->task = GNUNET_SCHEDULER_NO_TASK; 769 rh->task = NULL;
770 rh->addr_callback (rh->cls, 770 rh->addr_callback (rh->cls,
771 NULL, 771 NULL,
772 0); 772 0);
@@ -837,10 +837,10 @@ GNUNET_RESOLVER_ip_get (const char *hostname, int af,
837 rh); 837 rh);
838 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); 838 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
839 rh->was_queued = GNUNET_YES; 839 rh->was_queued = GNUNET_YES;
840 if (s_task != GNUNET_SCHEDULER_NO_TASK) 840 if (s_task != NULL)
841 { 841 {
842 GNUNET_SCHEDULER_cancel (s_task); 842 GNUNET_SCHEDULER_cancel (s_task);
843 s_task = GNUNET_SCHEDULER_NO_TASK; 843 s_task = NULL;
844 } 844 }
845 process_requests (); 845 process_requests ();
846 return rh; 846 return rh;
@@ -863,7 +863,7 @@ numeric_reverse (void *cls,
863 struct GNUNET_RESOLVER_RequestHandle *rh = cls; 863 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
864 char *result; 864 char *result;
865 865
866 rh->task = GNUNET_SCHEDULER_NO_TASK; 866 rh->task = NULL;
867 result = no_resolve (rh->af, 867 result = no_resolve (rh->af,
868 &rh[1], 868 &rh[1],
869 rh->data_len); 869 rh->data_len);
@@ -937,10 +937,10 @@ GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
937 req_tail, 937 req_tail,
938 rh); 938 rh);
939 rh->was_queued = GNUNET_YES; 939 rh->was_queued = GNUNET_YES;
940 if (s_task != GNUNET_SCHEDULER_NO_TASK) 940 if (s_task != NULL)
941 { 941 {
942 GNUNET_SCHEDULER_cancel (s_task); 942 GNUNET_SCHEDULER_cancel (s_task);
943 s_task = GNUNET_SCHEDULER_NO_TASK; 943 s_task = NULL;
944 } 944 }
945 process_requests (); 945 process_requests ();
946 return rh; 946 return rh;
@@ -1024,10 +1024,10 @@ GNUNET_RESOLVER_hostname_resolve (int af,
1024void 1024void
1025GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) 1025GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
1026{ 1026{
1027 if (rh->task != GNUNET_SCHEDULER_NO_TASK) 1027 if (rh->task != NULL)
1028 { 1028 {
1029 GNUNET_SCHEDULER_cancel (rh->task); 1029 GNUNET_SCHEDULER_cancel (rh->task);
1030 rh->task = GNUNET_SCHEDULER_NO_TASK; 1030 rh->task = NULL;
1031 } 1031 }
1032 if (GNUNET_NO == rh->was_transmitted) 1032 if (GNUNET_NO == rh->was_transmitted)
1033 { 1033 {
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 87a107dba..ec45889ea 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -71,19 +71,24 @@
71 71
72 72
73/** 73/**
74 * Linked list of pending tasks. 74 * Entry in list of pending tasks.
75 */ 75 */
76struct Task 76struct GNUNET_SCHEDULER_Task
77{ 77{
78 /** 78 /**
79 * This is a linked list. 79 * This is a linked list.
80 */ 80 */
81 struct Task *next; 81 struct GNUNET_SCHEDULER_Task *next;
82
83 /**
84 * This is a linked list.
85 */
86 struct GNUNET_SCHEDULER_Task *prev;
82 87
83 /** 88 /**
84 * Function to run when ready. 89 * Function to run when ready.
85 */ 90 */
86 GNUNET_SCHEDULER_Task callback; 91 GNUNET_SCHEDULER_TaskCallback callback;
87 92
88 /** 93 /**
89 * Closure for the @e callback. 94 * Closure for the @e callback.
@@ -106,13 +111,8 @@ struct Task
106 struct GNUNET_NETWORK_FDSet *write_set; 111 struct GNUNET_NETWORK_FDSet *write_set;
107 112
108 /** 113 /**
109 * Unique task identifier.
110 */
111 GNUNET_SCHEDULER_TaskIdentifier id;
112
113 /**
114 * Absolute timeout value for the task, or 114 * Absolute timeout value for the task, or
115 * GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout". 115 * #GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout".
116 */ 116 */
117 struct GNUNET_TIME_Absolute timeout; 117 struct GNUNET_TIME_Absolute timeout;
118 118
@@ -169,9 +169,14 @@ struct Task
169 169
170 170
171/** 171/**
172 * List of tasks waiting for an event. 172 * Head of list of tasks waiting for an event.
173 */
174static struct GNUNET_SCHEDULER_Task *pending_head;
175
176/**
177 * Tail of list of tasks waiting for an event.
173 */ 178 */
174static struct Task *pending; 179static struct GNUNET_SCHEDULER_Task *pending_tail;
175 180
176/** 181/**
177 * List of tasks waiting ONLY for a timeout event. 182 * List of tasks waiting ONLY for a timeout event.
@@ -180,31 +185,37 @@ static struct Task *pending;
180 * building select sets (we just look at the head 185 * building select sets (we just look at the head
181 * to determine the respective timeout ONCE). 186 * to determine the respective timeout ONCE).
182 */ 187 */
183static struct Task *pending_timeout; 188static struct GNUNET_SCHEDULER_Task *pending_timeout_head;
189
190/**
191 * List of tasks waiting ONLY for a timeout event.
192 * Sorted by timeout (earliest first). Used so that
193 * we do not traverse the list of these tasks when
194 * building select sets (we just look at the head
195 * to determine the respective timeout ONCE).
196 */
197static struct GNUNET_SCHEDULER_Task *pending_timeout_tail;
184 198
185/** 199/**
186 * Last inserted task waiting ONLY for a timeout event. 200 * Last inserted task waiting ONLY for a timeout event.
187 * Used to (heuristically) speed up insertion. 201 * Used to (heuristically) speed up insertion.
188 */ 202 */
189static struct Task *pending_timeout_last; 203static struct GNUNET_SCHEDULER_Task *pending_timeout_last;
190 204
191/** 205/**
192 * ID of the task that is running right now. 206 * ID of the task that is running right now.
193 */ 207 */
194static struct Task *active_task; 208static struct GNUNET_SCHEDULER_Task *active_task;
195 209
196/** 210/**
197 * List of tasks ready to run right now, 211 * Head of list of tasks ready to run right now, grouped by importance.
198 * grouped by importance.
199 */ 212 */
200static struct Task *ready[GNUNET_SCHEDULER_PRIORITY_COUNT]; 213static struct GNUNET_SCHEDULER_Task *ready_head[GNUNET_SCHEDULER_PRIORITY_COUNT];
201 214
202/** 215/**
203 * Identity of the last task queued. Incremented for each task to 216 * Tail of list of tasks ready to run right now, grouped by importance.
204 * generate a unique task ID (it is virtually impossible to start
205 * more than 2^64 tasks during the lifetime of a process).
206 */ 217 */
207static GNUNET_SCHEDULER_TaskIdentifier last_id; 218static struct GNUNET_SCHEDULER_Task *ready_tail[GNUNET_SCHEDULER_PRIORITY_COUNT];
208 219
209/** 220/**
210 * Number of tasks on the ready list. 221 * Number of tasks on the ready list.
@@ -240,10 +251,11 @@ static int current_lifeness;
240static GNUNET_SCHEDULER_select scheduler_select; 251static GNUNET_SCHEDULER_select scheduler_select;
241 252
242/** 253/**
243 * Closure for 'scheduler_select'. 254 * Closure for #scheduler_select.
244 */ 255 */
245static void *scheduler_select_cls; 256static void *scheduler_select_cls;
246 257
258
247/** 259/**
248 * Sets the select function to use in the scheduler (scheduler_select). 260 * Sets the select function to use in the scheduler (scheduler_select).
249 * 261 *
@@ -284,25 +296,25 @@ check_priority (enum GNUNET_SCHEDULER_Priority p)
284 * @param timeout next timeout (updated) 296 * @param timeout next timeout (updated)
285 */ 297 */
286static void 298static void
287update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, 299update_sets (struct GNUNET_NETWORK_FDSet *rs,
300 struct GNUNET_NETWORK_FDSet *ws,
288 struct GNUNET_TIME_Relative *timeout) 301 struct GNUNET_TIME_Relative *timeout)
289{ 302{
290 struct Task *pos; 303 struct GNUNET_SCHEDULER_Task *pos;
291 struct GNUNET_TIME_Absolute now; 304 struct GNUNET_TIME_Absolute now;
292 struct GNUNET_TIME_Relative to; 305 struct GNUNET_TIME_Relative to;
293 306
294 now = GNUNET_TIME_absolute_get (); 307 now = GNUNET_TIME_absolute_get ();
295 pos = pending_timeout; 308 pos = pending_timeout_head;
296 if (NULL != pos) 309 if (NULL != pos)
297 { 310 {
298 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); 311 to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
299 if (timeout->rel_value_us > to.rel_value_us) 312 if (timeout->rel_value_us > to.rel_value_us)
300 *timeout = to; 313 *timeout = to;
301 if (pos->reason != 0) 314 if (0 != pos->reason)
302 *timeout = GNUNET_TIME_UNIT_ZERO; 315 *timeout = GNUNET_TIME_UNIT_ZERO;
303 } 316 }
304 pos = pending; 317 for (pos = pending_head; NULL != pos; pos = pos->next)
305 while (NULL != pos)
306 { 318 {
307 if (pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 319 if (pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
308 { 320 {
@@ -320,7 +332,6 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
320 GNUNET_NETWORK_fdset_add (ws, pos->write_set); 332 GNUNET_NETWORK_fdset_add (ws, pos->write_set);
321 if (0 != pos->reason) 333 if (0 != pos->reason)
322 *timeout = GNUNET_TIME_UNIT_ZERO; 334 *timeout = GNUNET_TIME_UNIT_ZERO;
323 pos = pos->next;
324 } 335 }
325} 336}
326 337
@@ -328,11 +339,11 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws,
328/** 339/**
329 * Check if the ready set overlaps with the set we want to have ready. 340 * Check if the ready set overlaps with the set we want to have ready.
330 * If so, update the want set (set all FDs that are ready). If not, 341 * If so, update the want set (set all FDs that are ready). If not,
331 * return GNUNET_NO. 342 * return #GNUNET_NO.
332 * 343 *
333 * @param ready set that is ready 344 * @param ready set that is ready
334 * @param want set that we want to be ready 345 * @param want set that we want to be ready
335 * @return GNUNET_YES if there was some overlap 346 * @return #GNUNET_YES if there was some overlap
336 */ 347 */
337static int 348static int
338set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, 349set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
@@ -362,7 +373,8 @@ set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
362 * @return #GNUNET_YES if we can run it, #GNUNET_NO if not. 373 * @return #GNUNET_YES if we can run it, #GNUNET_NO if not.
363 */ 374 */
364static int 375static int
365is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, 376is_ready (struct GNUNET_SCHEDULER_Task *task,
377 struct GNUNET_TIME_Absolute now,
366 const struct GNUNET_NETWORK_FDSet *rs, 378 const struct GNUNET_NETWORK_FDSet *rs,
367 const struct GNUNET_NETWORK_FDSet *ws) 379 const struct GNUNET_NETWORK_FDSet *ws)
368{ 380{
@@ -395,14 +407,15 @@ is_ready (struct Task *task, struct GNUNET_TIME_Absolute now,
395 * @param task task ready for execution 407 * @param task task ready for execution
396 */ 408 */
397static void 409static void
398queue_ready_task (struct Task *task) 410queue_ready_task (struct GNUNET_SCHEDULER_Task *task)
399{ 411{
400 enum GNUNET_SCHEDULER_Priority p = task->priority; 412 enum GNUNET_SCHEDULER_Priority p = check_priority (task->priority);
401 413
402 if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 414 if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
403 p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN; 415 p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
404 task->next = ready[check_priority (p)]; 416 GNUNET_CONTAINER_DLL_insert (ready_head[p],
405 ready[check_priority (p)] = task; 417 ready_tail[p],
418 task);
406 ready_count++; 419 ready_count++;
407} 420}
408 421
@@ -418,45 +431,35 @@ static void
418check_ready (const struct GNUNET_NETWORK_FDSet *rs, 431check_ready (const struct GNUNET_NETWORK_FDSet *rs,
419 const struct GNUNET_NETWORK_FDSet *ws) 432 const struct GNUNET_NETWORK_FDSet *ws)
420{ 433{
421 struct Task *pos; 434 struct GNUNET_SCHEDULER_Task *pos;
422 struct Task *prev; 435 struct GNUNET_SCHEDULER_Task *next;
423 struct Task *next;
424 struct GNUNET_TIME_Absolute now; 436 struct GNUNET_TIME_Absolute now;
425 437
426 now = GNUNET_TIME_absolute_get (); 438 now = GNUNET_TIME_absolute_get ();
427 prev = NULL; 439 while (NULL != (pos = pending_timeout_head))
428 pos = pending_timeout;
429 while (NULL != pos)
430 { 440 {
431 next = pos->next;
432 if (now.abs_value_us >= pos->timeout.abs_value_us) 441 if (now.abs_value_us >= pos->timeout.abs_value_us)
433 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT; 442 pos->reason |= GNUNET_SCHEDULER_REASON_TIMEOUT;
434 if (0 == pos->reason) 443 if (0 == pos->reason)
435 break; 444 break;
436 pending_timeout = next; 445 GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
446 pending_timeout_tail,
447 pos);
437 if (pending_timeout_last == pos) 448 if (pending_timeout_last == pos)
438 pending_timeout_last = NULL; 449 pending_timeout_last = NULL;
439 queue_ready_task (pos); 450 queue_ready_task (pos);
440 pos = next;
441 } 451 }
442 pos = pending; 452 pos = pending_head;
443 while (NULL != pos) 453 while (NULL != pos)
444 { 454 {
445 LOG (GNUNET_ERROR_TYPE_DEBUG,
446 "Checking readiness of task: %llu / %p\n",
447 pos->id, pos->callback_cls);
448 next = pos->next; 455 next = pos->next;
449 if (GNUNET_YES == is_ready (pos, now, rs, ws)) 456 if (GNUNET_YES == is_ready (pos, now, rs, ws))
450 { 457 {
451 if (NULL == prev) 458 GNUNET_CONTAINER_DLL_remove (pending_head,
452 pending = next; 459 pending_tail,
453 else 460 pos);
454 prev->next = next;
455 queue_ready_task (pos); 461 queue_ready_task (pos);
456 pos = next;
457 continue;
458 } 462 }
459 prev = pos;
460 pos = next; 463 pos = next;
461 } 464 }
462} 465}
@@ -468,43 +471,24 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs,
468 * cause all tasks to run (as soon as possible, respecting 471 * cause all tasks to run (as soon as possible, respecting
469 * priorities and prerequisite tasks). Note that tasks 472 * priorities and prerequisite tasks). Note that tasks
470 * scheduled AFTER this call may still be delayed arbitrarily. 473 * scheduled AFTER this call may still be delayed arbitrarily.
474 *
475 * Note that we don't move the tasks into the ready queue yet;
476 * check_ready() will do that later, possibly adding additional
477 * readiness-factors
471 */ 478 */
472void 479void
473GNUNET_SCHEDULER_shutdown () 480GNUNET_SCHEDULER_shutdown ()
474{ 481{
475 struct Task *pos; 482 struct GNUNET_SCHEDULER_Task *pos;
476 int i; 483 int i;
477 484
478 pos = pending_timeout; 485 for (pos = pending_timeout_head; NULL != pos; pos = pos->next)
479 while (NULL != pos)
480 {
481 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; 486 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
482 /* we don't move the task into the ready queue yet; check_ready 487 for (pos = pending_head; NULL != pos; pos = pos->next)
483 * will do that later, possibly adding additional
484 * readiness-factors */
485 pos = pos->next;
486 }
487 pos = pending;
488 while (NULL != pos)
489 {
490 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; 488 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
491 /* we don't move the task into the ready queue yet; check_ready
492 * will do that later, possibly adding additional
493 * readiness-factors */
494 pos = pos->next;
495 }
496 for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) 489 for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++)
497 { 490 for (pos = ready_head[i]; NULL != pos; pos = pos->next)
498 pos = ready[i];
499 while (NULL != pos)
500 {
501 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; 491 pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
502 /* we don't move the task into the ready queue yet; check_ready
503 * will do that later, possibly adding additional
504 * readiness-factors */
505 pos = pos->next;
506 }
507 }
508} 492}
509 493
510 494
@@ -514,7 +498,7 @@ GNUNET_SCHEDULER_shutdown ()
514 * @param t task to destroy 498 * @param t task to destroy
515 */ 499 */
516static void 500static void
517destroy_task (struct Task *t) 501destroy_task (struct GNUNET_SCHEDULER_Task *t)
518{ 502{
519 if (NULL != t->read_set) 503 if (NULL != t->read_set)
520 GNUNET_NETWORK_fdset_destroy (t->read_set); 504 GNUNET_NETWORK_fdset_destroy (t->read_set);
@@ -542,7 +526,7 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs,
542 struct GNUNET_NETWORK_FDSet *ws) 526 struct GNUNET_NETWORK_FDSet *ws)
543{ 527{
544 enum GNUNET_SCHEDULER_Priority p; 528 enum GNUNET_SCHEDULER_Priority p;
545 struct Task *pos; 529 struct GNUNET_SCHEDULER_Task *pos;
546 struct GNUNET_SCHEDULER_TaskContext tc; 530 struct GNUNET_SCHEDULER_TaskContext tc;
547 531
548 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; 532 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
@@ -550,17 +534,19 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs,
550 { 534 {
551 if (0 == ready_count) 535 if (0 == ready_count)
552 return; 536 return;
553 GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); 537 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);
554 /* yes, p>0 is correct, 0 is "KEEP" which should 538 /* yes, p>0 is correct, 0 is "KEEP" which should
555 * always be an empty queue (see assertion)! */ 539 * always be an empty queue (see assertion)! */
556 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) 540 for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
557 { 541 {
558 pos = ready[p]; 542 pos = ready_head[p];
559 if (NULL != pos) 543 if (NULL != pos)
560 break; 544 break;
561 } 545 }
562 GNUNET_assert (NULL != pos); /* ready_count wrong? */ 546 GNUNET_assert (NULL != pos); /* ready_count wrong? */
563 ready[p] = pos->next; 547 GNUNET_CONTAINER_DLL_remove (ready_head[p],
548 ready_tail[p],
549 pos);
564 ready_count--; 550 ready_count--;
565 current_priority = pos->priority; 551 current_priority = pos->priority;
566 current_lifeness = pos->lifeness; 552 current_lifeness = pos->lifeness;
@@ -570,35 +556,35 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs,
570 DELAY_THRESHOLD.rel_value_us) 556 DELAY_THRESHOLD.rel_value_us)
571 { 557 {
572 LOG (GNUNET_ERROR_TYPE_DEBUG, 558 LOG (GNUNET_ERROR_TYPE_DEBUG,
573 "Task %llu took %s to be scheduled\n", 559 "Task %p took %s to be scheduled\n",
574 (unsigned long long) pos->id, 560 pos,
575 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), 561 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time),
576 GNUNET_YES)); 562 GNUNET_YES));
577 } 563 }
578#endif 564#endif
579 tc.reason = pos->reason; 565 tc.reason = pos->reason;
580 tc.read_ready = (pos->read_set == NULL) ? rs : pos->read_set; 566 tc.read_ready = (NULL == pos->read_set) ? rs : pos->read_set;
581 if ((pos->read_fd != -1) && 567 if ((-1 != pos->read_fd) &&
582 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY))) 568 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_READ_READY)))
583 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); 569 GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd);
584 tc.write_ready = (pos->write_set == NULL) ? ws : pos->write_set; 570 tc.write_ready = (NULL == pos->write_set) ? ws : pos->write_set;
585 if ((pos->write_fd != -1) && 571 if ((-1 != pos->write_fd) &&
586 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))) 572 (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)))
587 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); 573 GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd);
588 if (((tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY) != 0) && 574 if ((0 != (tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
589 (pos->write_fd != -1) && 575 (-1 != pos->write_fd) &&
590 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) 576 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
591 GNUNET_abort (); // added to ready in previous select loop! 577 GNUNET_abort (); // added to ready in previous select loop!
592 LOG (GNUNET_ERROR_TYPE_DEBUG, 578 LOG (GNUNET_ERROR_TYPE_DEBUG,
593 "Running task: %llu / %p\n", pos->id, 579 "Running task: %p\n",
594 pos->callback_cls); 580 pos);
595 pos->callback (pos->callback_cls, &tc); 581 pos->callback (pos->callback_cls, &tc);
596#if EXECINFO 582#if EXECINFO
597 int i; 583 unsigned int i;
598 584
599 for (i = 0; i < pos->num_backtrace_strings; i++) 585 for (i = 0; i < pos->num_backtrace_strings; i++)
600 LOG (GNUNET_ERROR_TYPE_ERROR, 586 LOG (GNUNET_ERROR_TYPE_ERROR,
601 "Task %llu trace %d: %s\n", 587 "Task %llu trace %u: %s\n",
602 pos->id, 588 pos->id,
603 i, 589 i,
604 pos->backtrace_strings[i]); 590 pos->backtrace_strings[i]);
@@ -607,9 +593,10 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs,
607 destroy_task (pos); 593 destroy_task (pos);
608 tasks_run++; 594 tasks_run++;
609 } 595 }
610 while ((NULL == pending) || (p >= max_priority_added)); 596 while ((NULL == pending_head) || (p >= max_priority_added));
611} 597}
612 598
599
613/** 600/**
614 * Pipe used to communicate shutdown via signal. 601 * Pipe used to communicate shutdown via signal.
615 */ 602 */
@@ -680,17 +667,17 @@ sighandler_shutdown ()
680static int 667static int
681check_lifeness () 668check_lifeness ()
682{ 669{
683 struct Task *t; 670 struct GNUNET_SCHEDULER_Task *t;
684 671
685 if (ready_count > 0) 672 if (ready_count > 0)
686 return GNUNET_OK; 673 return GNUNET_OK;
687 for (t = pending; NULL != t; t = t->next) 674 for (t = pending_head; NULL != t; t = t->next)
688 if (t->lifeness == GNUNET_YES) 675 if (t->lifeness == GNUNET_YES)
689 return GNUNET_OK; 676 return GNUNET_OK;
690 for (t = pending_timeout; NULL != t; t = t->next) 677 for (t = pending_timeout_head; NULL != t; t = t->next)
691 if (t->lifeness == GNUNET_YES) 678 if (t->lifeness == GNUNET_YES)
692 return GNUNET_OK; 679 return GNUNET_OK;
693 if ((NULL != pending) || (NULL != pending_timeout)) 680 if ((NULL != pending_head) || (NULL != pending_timeout_head))
694 { 681 {
695 GNUNET_SCHEDULER_shutdown (); 682 GNUNET_SCHEDULER_shutdown ();
696 return GNUNET_OK; 683 return GNUNET_OK;
@@ -714,7 +701,8 @@ check_lifeness ()
714 * @param task_cls closure of @a task 701 * @param task_cls closure of @a task
715 */ 702 */
716void 703void
717GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) 704GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
705 void *task_cls)
718{ 706{
719 struct GNUNET_NETWORK_FDSet *rs; 707 struct GNUNET_NETWORK_FDSet *rs;
720 struct GNUNET_NETWORK_FDSet *ws; 708 struct GNUNET_NETWORK_FDSet *ws;
@@ -740,13 +728,17 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
740 rs = GNUNET_NETWORK_fdset_create (); 728 rs = GNUNET_NETWORK_fdset_create ();
741 ws = GNUNET_NETWORK_fdset_create (); 729 ws = GNUNET_NETWORK_fdset_create ();
742 GNUNET_assert (NULL == shutdown_pipe_handle); 730 GNUNET_assert (NULL == shutdown_pipe_handle);
743 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); 731 shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO,
732 GNUNET_NO,
733 GNUNET_NO,
734 GNUNET_NO);
744 GNUNET_assert (NULL != shutdown_pipe_handle); 735 GNUNET_assert (NULL != shutdown_pipe_handle);
745 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, 736 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
746 GNUNET_DISK_PIPE_END_READ); 737 GNUNET_DISK_PIPE_END_READ);
747 GNUNET_assert (pr != NULL); 738 GNUNET_assert (NULL != pr);
748 my_pid = getpid (); 739 my_pid = getpid ();
749 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering signal handlers\n"); 740 LOG (GNUNET_ERROR_TYPE_DEBUG,
741 "Registering signal handlers\n");
750 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); 742 shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
751 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); 743 shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
752#if (SIGTERM != GNUNET_TERM_SIG) 744#if (SIGTERM != GNUNET_TERM_SIG)
@@ -759,7 +751,8 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
759#endif 751#endif
760 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 752 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
761 current_lifeness = GNUNET_YES; 753 current_lifeness = GNUNET_YES;
762 GNUNET_SCHEDULER_add_continuation (task, task_cls, 754 GNUNET_SCHEDULER_add_continuation (task,
755 task_cls,
763 GNUNET_SCHEDULER_REASON_STARTUP); 756 GNUNET_SCHEDULER_REASON_STARTUP);
764 active_task = (void *) (long) -1; /* force passing of sanity check */ 757 active_task = (void *) (long) -1; /* force passing of sanity check */
765 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, 758 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
@@ -860,7 +853,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
860enum GNUNET_SCHEDULER_Reason 853enum GNUNET_SCHEDULER_Reason
861GNUNET_SCHEDULER_get_reason () 854GNUNET_SCHEDULER_get_reason ()
862{ 855{
863 GNUNET_assert (active_task != NULL); 856 GNUNET_assert (NULL != active_task);
864 return active_task->reason; 857 return active_task->reason;
865} 858}
866 859
@@ -877,21 +870,17 @@ GNUNET_SCHEDULER_get_reason ()
877unsigned int 870unsigned int
878GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p) 871GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p)
879{ 872{
880 struct Task *pos; 873 struct GNUNET_SCHEDULER_Task *pos;
881 unsigned int ret; 874 unsigned int ret;
882 875
883 GNUNET_assert (active_task != NULL); 876 GNUNET_assert (NULL != active_task);
884 if (p == GNUNET_SCHEDULER_PRIORITY_COUNT) 877 if (p == GNUNET_SCHEDULER_PRIORITY_COUNT)
885 return ready_count; 878 return ready_count;
886 if (p == GNUNET_SCHEDULER_PRIORITY_KEEP) 879 if (p == GNUNET_SCHEDULER_PRIORITY_KEEP)
887 p = current_priority; 880 p = current_priority;
888 ret = 0; 881 ret = 0;
889 pos = ready[check_priority (p)]; 882 for (pos = ready_head[check_priority (p)]; NULL != pos; pos = pos->next)
890 while (NULL != pos)
891 {
892 pos = pos->next;
893 ret++; 883 ret++;
894 }
895 return ret; 884 return ret;
896} 885}
897 886
@@ -904,92 +893,45 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p)
904 * @return original closure of the task 893 * @return original closure of the task
905 */ 894 */
906void * 895void *
907GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) 896GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
908{ 897{
909 struct Task *t;
910 struct Task *prev;
911 enum GNUNET_SCHEDULER_Priority p; 898 enum GNUNET_SCHEDULER_Priority p;
912 int to;
913 void *ret; 899 void *ret;
914 900
915 GNUNET_assert (NULL != active_task); 901 GNUNET_assert (NULL != active_task);
916 to = 0; 902 if (GNUNET_SCHEDULER_REASON_NONE == task->reason)
917 prev = NULL;
918 t = pending;
919 while (NULL != t)
920 {
921 if (t->id == task)
922 break;
923 prev = t;
924 t = t->next;
925 }
926 if (NULL == t)
927 {
928 prev = NULL;
929 to = 1;
930 t = pending_timeout;
931 while (t != NULL)
932 {
933 if (t->id == task)
934 break;
935 prev = t;
936 t = t->next;
937 }
938 if (pending_timeout_last == t)
939 pending_timeout_last = NULL;
940 }
941 p = 0;
942 while (NULL == t)
943 {
944 p++;
945 if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT)
946 {
947 LOG (GNUNET_ERROR_TYPE_ERROR,
948 _("Attempt to cancel dead task %llu!\n"),
949 (unsigned long long) task);
950 GNUNET_assert (0);
951 }
952 prev = NULL;
953 t = ready[p];
954 while (NULL != t)
955 {
956 if (t->id == task)
957 {
958 ready_count--;
959 break;
960 }
961 prev = t;
962 t = t->next;
963 }
964 }
965 if (NULL == prev)
966 { 903 {
967 if (0 == p) 904 if ( (-1 == task->read_fd) &&
905 (-1 == task->write_fd) &&
906 (NULL == task->read_set) &&
907 (NULL == task->write_set) )
968 { 908 {
969 if (0 == to) 909 GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
970 { 910 pending_timeout_tail,
971 pending = t->next; 911 task);
972 } 912 if (task == pending_timeout_last)
973 else 913 pending_timeout_last = NULL;
974 {
975 pending_timeout = t->next;
976 }
977 } 914 }
978 else 915 else
979 { 916 {
980 ready[p] = t->next; 917 GNUNET_CONTAINER_DLL_remove (pending_head,
918 pending_tail,
919 task);
981 } 920 }
982 } 921 }
983 else 922 else
984 { 923 {
985 prev->next = t->next; 924 p = check_priority (task->priority);
925 GNUNET_CONTAINER_DLL_remove (ready_head[p],
926 ready_tail[p],
927 task);
928 ready_count--;
986 } 929 }
987 ret = t->callback_cls; 930 ret = task->callback_cls;
988 LOG (GNUNET_ERROR_TYPE_DEBUG, 931 LOG (GNUNET_ERROR_TYPE_DEBUG,
989 "Canceling task: %llu / %p\n", 932 "Canceling task %p\n",
990 task, 933 task);
991 t->callback_cls); 934 destroy_task (task);
992 destroy_task (t);
993 return ret; 935 return ret;
994} 936}
995 937
@@ -1005,11 +947,12 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1005 * @param priority priority to use for the task 947 * @param priority priority to use for the task
1006 */ 948 */
1007void 949void
1008GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, void *task_cls, 950GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_TaskCallback task,
951 void *task_cls,
1009 enum GNUNET_SCHEDULER_Reason reason, 952 enum GNUNET_SCHEDULER_Reason reason,
1010 enum GNUNET_SCHEDULER_Priority priority) 953 enum GNUNET_SCHEDULER_Priority priority)
1011{ 954{
1012 struct Task *t; 955 struct GNUNET_SCHEDULER_Task *t;
1013 956
1014#if EXECINFO 957#if EXECINFO
1015 void *backtrace_array[50]; 958 void *backtrace_array[50];
@@ -1018,7 +961,7 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi
1018 GNUNET_assert (NULL != task); 961 GNUNET_assert (NULL != task);
1019 GNUNET_assert ((NULL != active_task) || 962 GNUNET_assert ((NULL != active_task) ||
1020 (GNUNET_SCHEDULER_REASON_STARTUP == reason)); 963 (GNUNET_SCHEDULER_REASON_STARTUP == reason));
1021 t = GNUNET_new (struct Task); 964 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1022#if EXECINFO 965#if EXECINFO
1023 t->num_backtrace_strings = backtrace (backtrace_array, 50); 966 t->num_backtrace_strings = backtrace (backtrace_array, 50);
1024 t->backtrace_strings = 967 t->backtrace_strings =
@@ -1028,7 +971,6 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi
1028 t->write_fd = -1; 971 t->write_fd = -1;
1029 t->callback = task; 972 t->callback = task;
1030 t->callback_cls = task_cls; 973 t->callback_cls = task_cls;
1031 t->id = ++last_id;
1032#if PROFILE_DELAYS 974#if PROFILE_DELAYS
1033 t->start_time = GNUNET_TIME_absolute_get (); 975 t->start_time = GNUNET_TIME_absolute_get ();
1034#endif 976#endif
@@ -1036,9 +978,8 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi
1036 t->priority = priority; 978 t->priority = priority;
1037 t->lifeness = current_lifeness; 979 t->lifeness = current_lifeness;
1038 LOG (GNUNET_ERROR_TYPE_DEBUG, 980 LOG (GNUNET_ERROR_TYPE_DEBUG,
1039 "Adding continuation task: %llu / %p\n", 981 "Adding continuation task %p\n",
1040 t->id, 982 t);
1041 t->callback_cls);
1042 queue_ready_task (t); 983 queue_ready_task (t);
1043} 984}
1044 985
@@ -1053,7 +994,7 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi
1053 * @param reason reason for task invocation 994 * @param reason reason for task invocation
1054 */ 995 */
1055void 996void
1056GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, 997GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_TaskCallback task, void *task_cls,
1057 enum GNUNET_SCHEDULER_Reason reason) 998 enum GNUNET_SCHEDULER_Reason reason)
1058{ 999{
1059 GNUNET_SCHEDULER_add_continuation_with_priority (task, task_cls, 1000 GNUNET_SCHEDULER_add_continuation_with_priority (task, task_cls,
@@ -1063,26 +1004,6 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1063 1004
1064 1005
1065/** 1006/**
1066 * Schedule a new task to be run with a specified priority.
1067 *
1068 * @param prio how important is the new task?
1069 * @param task main function of the task
1070 * @param task_cls closure of @a task
1071 * @return unique task identifier for the job
1072 * only valid until @a task is started!
1073 */
1074GNUNET_SCHEDULER_TaskIdentifier
1075GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1076 GNUNET_SCHEDULER_Task task, void *task_cls)
1077{
1078 return GNUNET_SCHEDULER_add_select (prio,
1079 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1080 task_cls);
1081}
1082
1083
1084
1085/**
1086 * Schedule a new task to be run with a specified delay. The task 1007 * Schedule a new task to be run with a specified delay. The task
1087 * will be scheduled for execution once the delay has expired. 1008 * will be scheduled for execution once the delay has expired.
1088 * 1009 *
@@ -1094,14 +1015,15 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1094 * @return unique task identifier for the job 1015 * @return unique task identifier for the job
1095 * only valid until @a task is started! 1016 * only valid until @a task is started!
1096 */ 1017 */
1097GNUNET_SCHEDULER_TaskIdentifier 1018struct GNUNET_SCHEDULER_Task *
1098GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, 1019GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1099 enum GNUNET_SCHEDULER_Priority priority, 1020 enum GNUNET_SCHEDULER_Priority priority,
1100 GNUNET_SCHEDULER_Task task, void *task_cls) 1021 GNUNET_SCHEDULER_TaskCallback task,
1022 void *task_cls)
1101{ 1023{
1102 struct Task *t; 1024 struct GNUNET_SCHEDULER_Task *t;
1103 struct Task *pos; 1025 struct GNUNET_SCHEDULER_Task *pos;
1104 struct Task *prev; 1026 struct GNUNET_SCHEDULER_Task *prev;
1105 1027
1106#if EXECINFO 1028#if EXECINFO
1107 void *backtrace_array[MAX_TRACE_DEPTH]; 1029 void *backtrace_array[MAX_TRACE_DEPTH];
@@ -1109,7 +1031,7 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1109 1031
1110 GNUNET_assert (NULL != active_task); 1032 GNUNET_assert (NULL != active_task);
1111 GNUNET_assert (NULL != task); 1033 GNUNET_assert (NULL != task);
1112 t = GNUNET_new (struct Task); 1034 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1113 t->callback = task; 1035 t->callback = task;
1114 t->callback_cls = task_cls; 1036 t->callback_cls = task_cls;
1115#if EXECINFO 1037#if EXECINFO
@@ -1119,7 +1041,6 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1119#endif 1041#endif
1120 t->read_fd = -1; 1042 t->read_fd = -1;
1121 t->write_fd = -1; 1043 t->write_fd = -1;
1122 t->id = ++last_id;
1123#if PROFILE_DELAYS 1044#if PROFILE_DELAYS
1124 t->start_time = GNUNET_TIME_absolute_get (); 1045 t->start_time = GNUNET_TIME_absolute_get ();
1125#endif 1046#endif
@@ -1128,44 +1049,74 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1128 t->lifeness = current_lifeness; 1049 t->lifeness = current_lifeness;
1129 /* try tail first (optimization in case we are 1050 /* try tail first (optimization in case we are
1130 * appending to a long list of tasks with timeouts) */ 1051 * appending to a long list of tasks with timeouts) */
1131 prev = pending_timeout_last; 1052 if (0 == delay.rel_value_us)
1132 if (prev != NULL)
1133 { 1053 {
1134 if (prev->timeout.abs_value_us > t->timeout.abs_value_us) 1054 GNUNET_CONTAINER_DLL_insert (pending_timeout_head,
1135 prev = NULL; 1055 pending_timeout_tail,
1136 else 1056 t);
1137 pos = prev->next; /* heuristic success! */
1138 }
1139 if (prev == NULL)
1140 {
1141 /* heuristic failed, do traversal of timeout list */
1142 pos = pending_timeout;
1143 } 1057 }
1144 while ((pos != NULL) && 1058 else
1145 ((pos->timeout.abs_value_us <= t->timeout.abs_value_us) ||
1146 (0 != pos->reason)))
1147 { 1059 {
1148 prev = pos; 1060 /* first move from heuristic start backwards to before start time */
1149 pos = pos->next; 1061 prev = pending_timeout_last;
1062 while ( (NULL != prev) &&
1063 (prev->timeout.abs_value_us > t->timeout.abs_value_us) )
1064 prev = prev->prev;
1065 /* now, move from heuristic start (or head of list) forward to insertion point */
1066 if (NULL == prev)
1067 pos = pending_timeout_head;
1068 else
1069 pos = prev->next;
1070 while ( (NULL != pos) &&
1071 ( (pos->timeout.abs_value_us <= t->timeout.abs_value_us) ||
1072 (0 != pos->reason) ) )
1073 {
1074 prev = pos;
1075 pos = pos->next;
1076 }
1077 GNUNET_CONTAINER_DLL_insert_after (pending_timeout_head,
1078 pending_timeout_tail,
1079 prev,
1080 t);
1081 /* finally, update heuristic insertion point to last insertion... */
1082 pending_timeout_last = t;
1150 } 1083 }
1151 if (prev == NULL)
1152 pending_timeout = t;
1153 else
1154 prev->next = t;
1155 t->next = pos;
1156 /* hyper-optimization... */
1157 pending_timeout_last = t;
1158 1084
1159 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, 1085 LOG (GNUNET_ERROR_TYPE_DEBUG,
1160 t->callback_cls); 1086 "Adding task: %p\n",
1087 t);
1161#if EXECINFO 1088#if EXECINFO
1162 int i; 1089 unsigned int i;
1163 1090
1164 for (i = 0; i < t->num_backtrace_strings; i++) 1091 for (i = 0; i < t->num_backtrace_strings; i++)
1165 LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, 1092 LOG (GNUNET_ERROR_TYPE_DEBUG,
1093 "Task %p trace %d: %s\n",
1094 t,
1095 i,
1166 t->backtrace_strings[i]); 1096 t->backtrace_strings[i]);
1167#endif 1097#endif
1168 return t->id; 1098 return t;
1099}
1100
1101
1102/**
1103 * Schedule a new task to be run with a specified priority.
1104 *
1105 * @param prio how important is the new task?
1106 * @param task main function of the task
1107 * @param task_cls closure of @a task
1108 * @return unique task identifier for the job
1109 * only valid until @a task is started!
1110 */
1111struct GNUNET_SCHEDULER_Task *
1112GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1113 GNUNET_SCHEDULER_TaskCallback task,
1114 void *task_cls)
1115{
1116 return GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_ZERO,
1117 prio,
1118 task,
1119 task_cls);
1169} 1120}
1170 1121
1171 1122
@@ -1181,9 +1132,9 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1181 * @return unique task identifier for the job 1132 * @return unique task identifier for the job
1182 * only valid until "task" is started! 1133 * only valid until "task" is started!
1183 */ 1134 */
1184GNUNET_SCHEDULER_TaskIdentifier 1135struct GNUNET_SCHEDULER_Task *
1185GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, 1136GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1186 GNUNET_SCHEDULER_Task task, void *task_cls) 1137 GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
1187{ 1138{
1188 return GNUNET_SCHEDULER_add_delayed_with_priority (delay, 1139 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1189 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1140 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1206,8 +1157,8 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1206 * @return unique task identifier for the job 1157 * @return unique task identifier for the job
1207 * only valid until "task" is started! 1158 * only valid until "task" is started!
1208 */ 1159 */
1209GNUNET_SCHEDULER_TaskIdentifier 1160struct GNUNET_SCHEDULER_Task *
1210GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) 1161GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
1211{ 1162{
1212 return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls); 1163 return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls);
1213} 1164}
@@ -1227,19 +1178,15 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
1227 * @return unique task identifier for the job 1178 * @return unique task identifier for the job
1228 * only valid until @a task is started! 1179 * only valid until @a task is started!
1229 */ 1180 */
1230GNUNET_SCHEDULER_TaskIdentifier 1181struct GNUNET_SCHEDULER_Task *
1231GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, 1182GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1232 GNUNET_SCHEDULER_Task task, 1183 GNUNET_SCHEDULER_TaskCallback task,
1233 void *task_cls) 1184 void *task_cls)
1234{ 1185{
1235 GNUNET_SCHEDULER_TaskIdentifier ret; 1186 struct GNUNET_SCHEDULER_Task *ret;
1236 1187
1237 ret = 1188 ret = GNUNET_SCHEDULER_add_now (task, task_cls);
1238 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1189 ret->lifeness = lifeness;
1239 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1240 task_cls);
1241 GNUNET_assert (pending->id == ret);
1242 pending->lifeness = lifeness;
1243 return ret; 1190 return ret;
1244} 1191}
1245 1192
@@ -1269,16 +1216,18 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1269 * @param task main function of the task 1216 * @param task main function of the task
1270 * @param task_cls closure of @a task 1217 * @param task_cls closure of @a task
1271 * @return unique task identifier for the job 1218 * @return unique task identifier for the job
1272 * only valid until "task" is started! 1219 * only valid until @a task is started!
1273 */ 1220 */
1274#ifndef MINGW 1221#ifndef MINGW
1275static GNUNET_SCHEDULER_TaskIdentifier 1222static struct GNUNET_SCHEDULER_Task *
1276add_without_sets (struct GNUNET_TIME_Relative delay, 1223add_without_sets (struct GNUNET_TIME_Relative delay,
1277 enum GNUNET_SCHEDULER_Priority priority, 1224 enum GNUNET_SCHEDULER_Priority priority,
1278 int rfd, int wfd, 1225 int rfd,
1279 GNUNET_SCHEDULER_Task task, void *task_cls) 1226 int wfd,
1227 GNUNET_SCHEDULER_TaskCallback task,
1228 void *task_cls)
1280{ 1229{
1281 struct Task *t; 1230 struct GNUNET_SCHEDULER_Task *t;
1282 1231
1283#if EXECINFO 1232#if EXECINFO
1284 void *backtrace_array[MAX_TRACE_DEPTH]; 1233 void *backtrace_array[MAX_TRACE_DEPTH];
@@ -1286,7 +1235,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1286 1235
1287 GNUNET_assert (NULL != active_task); 1236 GNUNET_assert (NULL != active_task);
1288 GNUNET_assert (NULL != task); 1237 GNUNET_assert (NULL != task);
1289 t = GNUNET_new (struct Task); 1238 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1290 t->callback = task; 1239 t->callback = task;
1291 t->callback_cls = task_cls; 1240 t->callback_cls = task_cls;
1292#if EXECINFO 1241#if EXECINFO
@@ -1339,36 +1288,35 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1339 t->read_fd = rfd; 1288 t->read_fd = rfd;
1340 GNUNET_assert (wfd >= -1); 1289 GNUNET_assert (wfd >= -1);
1341 t->write_fd = wfd; 1290 t->write_fd = wfd;
1342 t->id = ++last_id;
1343#if PROFILE_DELAYS 1291#if PROFILE_DELAYS
1344 t->start_time = GNUNET_TIME_absolute_get (); 1292 t->start_time = GNUNET_TIME_absolute_get ();
1345#endif 1293#endif
1346 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1294 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1347 t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority); 1295 t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority);
1348 t->lifeness = current_lifeness; 1296 t->lifeness = current_lifeness;
1349 t->next = pending; 1297 GNUNET_CONTAINER_DLL_insert (pending_head,
1350 pending = t; 1298 pending_tail,
1351 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1299 t);
1300 max_priority_added = GNUNET_MAX (max_priority_added,
1301 t->priority);
1352 LOG (GNUNET_ERROR_TYPE_DEBUG, 1302 LOG (GNUNET_ERROR_TYPE_DEBUG,
1353 "Adding task: %llu / %p\n", 1303 "Adding task %p\n",
1354 t->id, 1304 t);
1355 t->callback_cls);
1356#if EXECINFO 1305#if EXECINFO
1357 int i; 1306 unsigned int i;
1358 1307
1359 for (i = 0; i < t->num_backtrace_strings; i++) 1308 for (i = 0; i < t->num_backtrace_strings; i++)
1360 LOG (GNUNET_ERROR_TYPE_DEBUG, 1309 LOG (GNUNET_ERROR_TYPE_DEBUG,
1361 "Task %llu trace %d: %s\n", 1310 "Task %p trace %d: %s\n",
1362 t->id, 1311 t,
1363 i, 1312 i,
1364 t->backtrace_strings[i]); 1313 t->backtrace_strings[i]);
1365#endif 1314#endif
1366 return t->id; 1315 return t;
1367} 1316}
1368#endif 1317#endif
1369 1318
1370 1319
1371
1372/** 1320/**
1373 * Schedule a new task to be run with a specified delay or when the 1321 * Schedule a new task to be run with a specified delay or when the
1374 * specified file descriptor is ready for reading. The delay can be 1322 * specified file descriptor is ready for reading. The delay can be
@@ -1384,10 +1332,11 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1384 * @return unique task identifier for the job 1332 * @return unique task identifier for the job
1385 * only valid until @a task is started! 1333 * only valid until @a task is started!
1386 */ 1334 */
1387GNUNET_SCHEDULER_TaskIdentifier 1335struct GNUNET_SCHEDULER_Task *
1388GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, 1336GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1389 struct GNUNET_NETWORK_Handle *rfd, 1337 struct GNUNET_NETWORK_Handle *rfd,
1390 GNUNET_SCHEDULER_Task task, void *task_cls) 1338 GNUNET_SCHEDULER_TaskCallback task,
1339 void *task_cls)
1391{ 1340{
1392 return GNUNET_SCHEDULER_add_read_net_with_priority (delay, 1341 return GNUNET_SCHEDULER_add_read_net_with_priority (delay,
1393 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1342 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1412,16 +1361,18 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1412 * @return unique task identifier for the job 1361 * @return unique task identifier for the job
1413 * only valid until @a task is started! 1362 * only valid until @a task is started!
1414 */ 1363 */
1415GNUNET_SCHEDULER_TaskIdentifier 1364struct GNUNET_SCHEDULER_Task *
1416GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, 1365GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
1417 enum GNUNET_SCHEDULER_Priority priority, 1366 enum GNUNET_SCHEDULER_Priority priority,
1418 struct GNUNET_NETWORK_Handle *rfd, 1367 struct GNUNET_NETWORK_Handle *rfd,
1419 GNUNET_SCHEDULER_Task task, void *task_cls) 1368 GNUNET_SCHEDULER_TaskCallback task,
1369 void *task_cls)
1420{ 1370{
1421 return GNUNET_SCHEDULER_add_net_with_priority ( 1371 return GNUNET_SCHEDULER_add_net_with_priority (delay, priority,
1422 delay, priority, 1372 rfd,
1423 rfd, GNUNET_YES, GNUNET_NO, 1373 GNUNET_YES,
1424 task, task_cls); 1374 GNUNET_NO,
1375 task, task_cls);
1425} 1376}
1426 1377
1427 1378
@@ -1441,15 +1392,17 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
1441 * @return unique task identifier for the job 1392 * @return unique task identifier for the job
1442 * only valid until @a task is started! 1393 * only valid until @a task is started!
1443 */ 1394 */
1444GNUNET_SCHEDULER_TaskIdentifier 1395struct GNUNET_SCHEDULER_Task *
1445GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, 1396GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1446 struct GNUNET_NETWORK_Handle *wfd, 1397 struct GNUNET_NETWORK_Handle *wfd,
1447 GNUNET_SCHEDULER_Task task, void *task_cls) 1398 GNUNET_SCHEDULER_TaskCallback task,
1399 void *task_cls)
1448{ 1400{
1449 return GNUNET_SCHEDULER_add_net_with_priority ( 1401 return GNUNET_SCHEDULER_add_net_with_priority (delay,
1450 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1402 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1451 wfd, GNUNET_NO, GNUNET_YES, 1403 wfd,
1452 task, task_cls); 1404 GNUNET_NO, GNUNET_YES,
1405 task, task_cls);
1453} 1406}
1454 1407
1455/** 1408/**
@@ -1460,7 +1413,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1460 * socket operation is ready. 1413 * socket operation is ready.
1461 * 1414 *
1462 * @param delay when should this operation time out? Use 1415 * @param delay when should this operation time out? Use
1463 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1416 * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1464 * @param priority priority of the task 1417 * @param priority priority of the task
1465 * @param fd file-descriptor 1418 * @param fd file-descriptor
1466 * @param on_read whether to poll the file-descriptor for readability 1419 * @param on_read whether to poll the file-descriptor for readability
@@ -1470,18 +1423,20 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1470 * @return unique task identifier for the job 1423 * @return unique task identifier for the job
1471 * only valid until "task" is started! 1424 * only valid until "task" is started!
1472 */ 1425 */
1473GNUNET_SCHEDULER_TaskIdentifier 1426struct GNUNET_SCHEDULER_Task *
1474GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay, 1427GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1475 enum GNUNET_SCHEDULER_Priority priority, 1428 enum GNUNET_SCHEDULER_Priority priority,
1476 struct GNUNET_NETWORK_Handle *fd, 1429 struct GNUNET_NETWORK_Handle *fd,
1477 int on_read, int on_write, 1430 int on_read,
1478 GNUNET_SCHEDULER_Task task, void *task_cls) 1431 int on_write,
1432 GNUNET_SCHEDULER_TaskCallback task,
1433 void *task_cls)
1479{ 1434{
1480#if MINGW 1435#if MINGW
1481 struct GNUNET_NETWORK_FDSet *s; 1436 struct GNUNET_NETWORK_FDSet *s;
1482 GNUNET_SCHEDULER_TaskIdentifier ret; 1437 struct GNUNET_SCHEDULER_Task * ret;
1483 1438
1484 GNUNET_assert (fd != NULL); 1439 GNUNET_assert (NULL != fd);
1485 s = GNUNET_NETWORK_fdset_create (); 1440 s = GNUNET_NETWORK_fdset_create ();
1486 GNUNET_NETWORK_fdset_set (s, fd); 1441 GNUNET_NETWORK_fdset_set (s, fd);
1487 ret = GNUNET_SCHEDULER_add_select ( 1442 ret = GNUNET_SCHEDULER_add_select (
@@ -1493,11 +1448,10 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1493 return ret; 1448 return ret;
1494#else 1449#else
1495 GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0); 1450 GNUNET_assert (GNUNET_NETWORK_get_fd (fd) >= 0);
1496 return add_without_sets ( 1451 return add_without_sets (delay, priority,
1497 delay, priority, 1452 on_read ? GNUNET_NETWORK_get_fd (fd) : -1,
1498 on_read ? GNUNET_NETWORK_get_fd (fd) : -1, 1453 on_write ? GNUNET_NETWORK_get_fd (fd) : -1,
1499 on_write ? GNUNET_NETWORK_get_fd (fd) : -1, 1454 task, task_cls);
1500 task, task_cls);
1501#endif 1455#endif
1502} 1456}
1503 1457
@@ -1517,10 +1471,10 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
1517 * @return unique task identifier for the job 1471 * @return unique task identifier for the job
1518 * only valid until @a task is started! 1472 * only valid until @a task is started!
1519 */ 1473 */
1520GNUNET_SCHEDULER_TaskIdentifier 1474struct GNUNET_SCHEDULER_Task *
1521GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, 1475GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1522 const struct GNUNET_DISK_FileHandle *rfd, 1476 const struct GNUNET_DISK_FileHandle *rfd,
1523 GNUNET_SCHEDULER_Task task, void *task_cls) 1477 GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
1524{ 1478{
1525 return GNUNET_SCHEDULER_add_file_with_priority ( 1479 return GNUNET_SCHEDULER_add_file_with_priority (
1526 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1480 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1544,10 +1498,10 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1544 * @return unique task identifier for the job 1498 * @return unique task identifier for the job
1545 * only valid until @a task is started! 1499 * only valid until @a task is started!
1546 */ 1500 */
1547GNUNET_SCHEDULER_TaskIdentifier 1501struct GNUNET_SCHEDULER_Task *
1548GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, 1502GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1549 const struct GNUNET_DISK_FileHandle *wfd, 1503 const struct GNUNET_DISK_FileHandle *wfd,
1550 GNUNET_SCHEDULER_Task task, void *task_cls) 1504 GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
1551{ 1505{
1552 return GNUNET_SCHEDULER_add_file_with_priority ( 1506 return GNUNET_SCHEDULER_add_file_with_priority (
1553 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1507 delay, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
@@ -1574,18 +1528,18 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1574 * @return unique task identifier for the job 1528 * @return unique task identifier for the job
1575 * only valid until @a task is started! 1529 * only valid until @a task is started!
1576 */ 1530 */
1577GNUNET_SCHEDULER_TaskIdentifier 1531struct GNUNET_SCHEDULER_Task *
1578GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay, 1532GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1579 enum GNUNET_SCHEDULER_Priority priority, 1533 enum GNUNET_SCHEDULER_Priority priority,
1580 const struct GNUNET_DISK_FileHandle *fd, 1534 const struct GNUNET_DISK_FileHandle *fd,
1581 int on_read, int on_write, 1535 int on_read, int on_write,
1582 GNUNET_SCHEDULER_Task task, void *task_cls) 1536 GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
1583{ 1537{
1584#if MINGW 1538#if MINGW
1585 struct GNUNET_NETWORK_FDSet *s; 1539 struct GNUNET_NETWORK_FDSet *s;
1586 GNUNET_SCHEDULER_TaskIdentifier ret; 1540 struct GNUNET_SCHEDULER_Task * ret;
1587 1541
1588 GNUNET_assert (fd != NULL); 1542 GNUNET_assert (NULL != fd);
1589 s = GNUNET_NETWORK_fdset_create (); 1543 s = GNUNET_NETWORK_fdset_create ();
1590 GNUNET_NETWORK_fdset_handle_set (s, fd); 1544 GNUNET_NETWORK_fdset_handle_set (s, fd);
1591 ret = GNUNET_SCHEDULER_add_select ( 1545 ret = GNUNET_SCHEDULER_add_select (
@@ -1636,21 +1590,28 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1636 * @return unique task identifier for the job 1590 * @return unique task identifier for the job
1637 * only valid until @a task is started! 1591 * only valid until @a task is started!
1638 */ 1592 */
1639GNUNET_SCHEDULER_TaskIdentifier 1593struct GNUNET_SCHEDULER_Task *
1640GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, 1594GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1641 struct GNUNET_TIME_Relative delay, 1595 struct GNUNET_TIME_Relative delay,
1642 const struct GNUNET_NETWORK_FDSet *rs, 1596 const struct GNUNET_NETWORK_FDSet *rs,
1643 const struct GNUNET_NETWORK_FDSet *ws, 1597 const struct GNUNET_NETWORK_FDSet *ws,
1644 GNUNET_SCHEDULER_Task task, void *task_cls) 1598 GNUNET_SCHEDULER_TaskCallback task,
1599 void *task_cls)
1645{ 1600{
1646 struct Task *t; 1601 struct GNUNET_SCHEDULER_Task *t;
1647#if EXECINFO 1602#if EXECINFO
1648 void *backtrace_array[MAX_TRACE_DEPTH]; 1603 void *backtrace_array[MAX_TRACE_DEPTH];
1649#endif 1604#endif
1650 1605
1606 if ( (NULL == rs) &&
1607 (NULL == ws) )
1608 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1609 prio,
1610 task,
1611 task_cls);
1651 GNUNET_assert (NULL != active_task); 1612 GNUNET_assert (NULL != active_task);
1652 GNUNET_assert (NULL != task); 1613 GNUNET_assert (NULL != task);
1653 t = GNUNET_new (struct Task); 1614 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1654 t->callback = task; 1615 t->callback = task;
1655 t->callback_cls = task_cls; 1616 t->callback_cls = task_cls;
1656#if EXECINFO 1617#if EXECINFO
@@ -1670,7 +1631,6 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1670 t->write_set = GNUNET_NETWORK_fdset_create (); 1631 t->write_set = GNUNET_NETWORK_fdset_create ();
1671 GNUNET_NETWORK_fdset_copy (t->write_set, ws); 1632 GNUNET_NETWORK_fdset_copy (t->write_set, ws);
1672 } 1633 }
1673 t->id = ++last_id;
1674#if PROFILE_DELAYS 1634#if PROFILE_DELAYS
1675 t->start_time = GNUNET_TIME_absolute_get (); 1635 t->start_time = GNUNET_TIME_absolute_get ();
1676#endif 1636#endif
@@ -1680,23 +1640,24 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1680 GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : 1640 GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority :
1681 prio); 1641 prio);
1682 t->lifeness = current_lifeness; 1642 t->lifeness = current_lifeness;
1683 t->next = pending; 1643 GNUNET_CONTAINER_DLL_insert (pending_head,
1684 pending = t; 1644 pending_tail,
1645 t);
1685 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1646 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1686 LOG (GNUNET_ERROR_TYPE_DEBUG, 1647 LOG (GNUNET_ERROR_TYPE_DEBUG,
1687 "Adding task: %llu / %p\n", 1648 "Adding task %p\n",
1688 t->id, 1649 t);
1689 t->callback_cls);
1690#if EXECINFO 1650#if EXECINFO
1691 int i; 1651 int i;
1692 1652
1693 for (i = 0; i < t->num_backtrace_strings; i++) 1653 for (i = 0; i < t->num_backtrace_strings; i++)
1694 LOG (GNUNET_ERROR_TYPE_DEBUG, 1654 LOG (GNUNET_ERROR_TYPE_DEBUG,
1695 "Task %llu trace %d: %s\n", 1655 "Task p trace %d: %s\n",
1696 t->id, i, 1656 t,
1657 i,
1697 t->backtrace_strings[i]); 1658 t->backtrace_strings[i]);
1698#endif 1659#endif
1699 return t->id; 1660 return t;
1700} 1661}
1701 1662
1702/* end of scheduler.c */ 1663/* end of scheduler.c */
diff --git a/src/util/server.c b/src/util/server.c
index b2b590dbd..52f00a08c 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -144,7 +144,7 @@ struct GNUNET_SERVER_Handle
144 /** 144 /**
145 * Task scheduled to do the listening. 145 * Task scheduled to do the listening.
146 */ 146 */
147 GNUNET_SCHEDULER_TaskIdentifier listen_task; 147 struct GNUNET_SCHEDULER_Task * listen_task;
148 148
149 /** 149 /**
150 * Alternative function to create a MST instance. 150 * Alternative function to create a MST instance.
@@ -246,12 +246,12 @@ struct GNUNET_SERVER_Client
246 /** 246 /**
247 * ID of task used to restart processing. 247 * ID of task used to restart processing.
248 */ 248 */
249 GNUNET_SCHEDULER_TaskIdentifier restart_task; 249 struct GNUNET_SCHEDULER_Task * restart_task;
250 250
251 /** 251 /**
252 * Task that warns about missing calls to #GNUNET_SERVER_receive_done. 252 * Task that warns about missing calls to #GNUNET_SERVER_receive_done.
253 */ 253 */
254 GNUNET_SCHEDULER_TaskIdentifier warn_task; 254 struct GNUNET_SCHEDULER_Task * warn_task;
255 255
256 /** 256 /**
257 * Time when the warn task was started. 257 * Time when the warn task was started.
@@ -400,7 +400,7 @@ process_listen_socket (void *cls,
400 struct GNUNET_SERVER_Client *client; 400 struct GNUNET_SERVER_Client *client;
401 unsigned int i; 401 unsigned int i;
402 402
403 server->listen_task = GNUNET_SCHEDULER_NO_TASK; 403 server->listen_task = NULL;
404 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 404 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
405 { 405 {
406 /* ignore shutdown, someone else will take care of it! */ 406 /* ignore shutdown, someone else will take care of it! */
@@ -691,10 +691,10 @@ test_monitor_clients (struct GNUNET_SERVER_Handle *server)
691void 691void
692GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server) 692GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
693{ 693{
694 if (GNUNET_SCHEDULER_NO_TASK != server->listen_task) 694 if (NULL != server->listen_task)
695 { 695 {
696 GNUNET_SCHEDULER_cancel (server->listen_task); 696 GNUNET_SCHEDULER_cancel (server->listen_task);
697 server->listen_task = GNUNET_SCHEDULER_NO_TASK; 697 server->listen_task = NULL;
698 } 698 }
699} 699}
700 700
@@ -750,10 +750,10 @@ GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server)
750 750
751 LOG (GNUNET_ERROR_TYPE_DEBUG, 751 LOG (GNUNET_ERROR_TYPE_DEBUG,
752 "Server in soft shutdown\n"); 752 "Server in soft shutdown\n");
753 if (GNUNET_SCHEDULER_NO_TASK != server->listen_task) 753 if (NULL != server->listen_task)
754 { 754 {
755 GNUNET_SCHEDULER_cancel (server->listen_task); 755 GNUNET_SCHEDULER_cancel (server->listen_task);
756 server->listen_task = GNUNET_SCHEDULER_NO_TASK; 756 server->listen_task = NULL;
757 } 757 }
758 if (NULL != server->listen_sockets) 758 if (NULL != server->listen_sockets)
759 { 759 {
@@ -784,10 +784,10 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server)
784 784
785 LOG (GNUNET_ERROR_TYPE_DEBUG, 785 LOG (GNUNET_ERROR_TYPE_DEBUG,
786 "Server shutting down.\n"); 786 "Server shutting down.\n");
787 if (GNUNET_SCHEDULER_NO_TASK != server->listen_task) 787 if (NULL != server->listen_task)
788 { 788 {
789 GNUNET_SCHEDULER_cancel (server->listen_task); 789 GNUNET_SCHEDULER_cancel (server->listen_task);
790 server->listen_task = GNUNET_SCHEDULER_NO_TASK; 790 server->listen_task = NULL;
791 } 791 }
792 if (NULL != server->listen_sockets) 792 if (NULL != server->listen_sockets)
793 { 793 {
@@ -909,10 +909,10 @@ warn_no_receive_done (void *cls,
909void 909void
910GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) 910GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
911{ 911{
912 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) 912 if (NULL != client->warn_task)
913 { 913 {
914 GNUNET_SCHEDULER_cancel (client->warn_task); 914 GNUNET_SCHEDULER_cancel (client->warn_task);
915 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 915 client->warn_task = NULL;
916 } 916 }
917} 917}
918 918
@@ -975,7 +975,7 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
975 if (NULL != sender) 975 if (NULL != sender)
976 { 976 {
977 if ( (0 == sender->suspended) && 977 if ( (0 == sender->suspended) &&
978 (GNUNET_SCHEDULER_NO_TASK == sender->warn_task) ) 978 (NULL == sender->warn_task) )
979 { 979 {
980 GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */ 980 GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */
981 sender->warn_start = GNUNET_TIME_absolute_get (); 981 sender->warn_start = GNUNET_TIME_absolute_get ();
@@ -1169,7 +1169,7 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1169 struct GNUNET_SERVER_Client *client = cls; 1169 struct GNUNET_SERVER_Client *client = cls;
1170 1170
1171 GNUNET_assert (GNUNET_YES != client->shutdown_now); 1171 GNUNET_assert (GNUNET_YES != client->shutdown_now);
1172 client->restart_task = GNUNET_SCHEDULER_NO_TASK; 1172 client->restart_task = NULL;
1173 if (GNUNET_NO == client->receive_pending) 1173 if (GNUNET_NO == client->receive_pending)
1174 { 1174 {
1175 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); 1175 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
@@ -1479,15 +1479,15 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1479 1479
1480 LOG (GNUNET_ERROR_TYPE_DEBUG, 1480 LOG (GNUNET_ERROR_TYPE_DEBUG,
1481 "Client is being disconnected from the server.\n"); 1481 "Client is being disconnected from the server.\n");
1482 if (GNUNET_SCHEDULER_NO_TASK != client->restart_task) 1482 if (NULL != client->restart_task)
1483 { 1483 {
1484 GNUNET_SCHEDULER_cancel (client->restart_task); 1484 GNUNET_SCHEDULER_cancel (client->restart_task);
1485 client->restart_task = GNUNET_SCHEDULER_NO_TASK; 1485 client->restart_task = NULL;
1486 } 1486 }
1487 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) 1487 if (NULL != client->warn_task)
1488 { 1488 {
1489 GNUNET_SCHEDULER_cancel (client->warn_task); 1489 GNUNET_SCHEDULER_cancel (client->warn_task);
1490 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 1490 client->warn_task = NULL;
1491 } 1491 }
1492 if (GNUNET_YES == client->receive_pending) 1492 if (GNUNET_YES == client->receive_pending)
1493 { 1493 {
@@ -1532,10 +1532,10 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1532 client->connection); 1532 client->connection);
1533 /* need to cancel again, as it might have been re-added 1533 /* need to cancel again, as it might have been re-added
1534 in the meantime (i.e. during callbacks) */ 1534 in the meantime (i.e. during callbacks) */
1535 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) 1535 if (NULL != client->warn_task)
1536 { 1536 {
1537 GNUNET_SCHEDULER_cancel (client->warn_task); 1537 GNUNET_SCHEDULER_cancel (client->warn_task);
1538 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 1538 client->warn_task = NULL;
1539 } 1539 }
1540 if (GNUNET_YES == client->receive_pending) 1540 if (GNUNET_YES == client->receive_pending)
1541 { 1541 {
@@ -1684,10 +1684,10 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
1684 "GNUNET_SERVER_receive_done called, but more clients pending\n"); 1684 "GNUNET_SERVER_receive_done called, but more clients pending\n");
1685 return; 1685 return;
1686 } 1686 }
1687 if (GNUNET_SCHEDULER_NO_TASK != client->warn_task) 1687 if (NULL != client->warn_task)
1688 { 1688 {
1689 GNUNET_SCHEDULER_cancel (client->warn_task); 1689 GNUNET_SCHEDULER_cancel (client->warn_task);
1690 client->warn_task = GNUNET_SCHEDULER_NO_TASK; 1690 client->warn_task = NULL;
1691 } 1691 }
1692 if (GNUNET_YES == client->in_process_client_buffer) 1692 if (GNUNET_YES == client->in_process_client_buffer)
1693 { 1693 {
@@ -1702,7 +1702,7 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
1702 } 1702 }
1703 LOG (GNUNET_ERROR_TYPE_DEBUG, 1703 LOG (GNUNET_ERROR_TYPE_DEBUG,
1704 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); 1704 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1705 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task); 1705 GNUNET_assert (NULL == client->restart_task);
1706 client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client); 1706 client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client);
1707} 1707}
1708 1708
diff --git a/src/util/service.c b/src/util/service.c
index 5be6bc33f..d49ad4f2a 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -187,7 +187,7 @@ struct GNUNET_SERVICE_Context
187 /** 187 /**
188 * Task ID of the shutdown task. 188 * Task ID of the shutdown task.
189 */ 189 */
190 GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 190 struct GNUNET_SCHEDULER_Task * shutdown_task;
191 191
192 /** 192 /**
193 * Idle timeout for server. 193 * Idle timeout for server.
@@ -1134,7 +1134,7 @@ shutdown_task (void *cls,
1134 struct GNUNET_SERVICE_Context *service = cls; 1134 struct GNUNET_SERVICE_Context *service = cls;
1135 struct GNUNET_SERVER_Handle *server = service->server; 1135 struct GNUNET_SERVER_Handle *server = service->server;
1136 1136
1137 service->shutdown_task = GNUNET_SCHEDULER_NO_TASK; 1137 service->shutdown_task = NULL;
1138 if (0 != (service->options & GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN)) 1138 if (0 != (service->options & GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN))
1139 GNUNET_SERVER_stop_listening (server); 1139 GNUNET_SERVER_stop_listening (server);
1140 else 1140 else
@@ -1675,10 +1675,10 @@ GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx)
1675 } 1675 }
1676 } 1676 }
1677#endif 1677#endif
1678 if (GNUNET_SCHEDULER_NO_TASK != sctx->shutdown_task) 1678 if (NULL != sctx->shutdown_task)
1679 { 1679 {
1680 GNUNET_SCHEDULER_cancel (sctx->shutdown_task); 1680 GNUNET_SCHEDULER_cancel (sctx->shutdown_task);
1681 sctx->shutdown_task = GNUNET_SCHEDULER_NO_TASK; 1681 sctx->shutdown_task = NULL;
1682 } 1682 }
1683 if (NULL != sctx->server) 1683 if (NULL != sctx->server)
1684 GNUNET_SERVER_destroy (sctx->server); 1684 GNUNET_SERVER_destroy (sctx->server);
diff --git a/src/util/speedup.c b/src/util/speedup.c
index d71e7c158..544958be9 100644
--- a/src/util/speedup.c
+++ b/src/util/speedup.c
@@ -34,7 +34,7 @@ static struct GNUNET_TIME_Relative interval;
34 34
35static struct GNUNET_TIME_Relative delta; 35static struct GNUNET_TIME_Relative delta;
36 36
37static GNUNET_SCHEDULER_TaskIdentifier speedup_task; 37static struct GNUNET_SCHEDULER_Task * speedup_task;
38 38
39 39
40static void 40static void
@@ -43,7 +43,7 @@ do_speedup (void *cls,
43{ 43{
44 static long long current_offset; 44 static long long current_offset;
45 45
46 speedup_task = GNUNET_SCHEDULER_NO_TASK; 46 speedup_task = NULL;
47 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 47 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
48 return; 48 return;
49 current_offset += delta.rel_value_us; 49 current_offset += delta.rel_value_us;
@@ -97,10 +97,10 @@ GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
97void 97void
98GNUNET_SPEEDUP_stop_ () 98GNUNET_SPEEDUP_stop_ ()
99{ 99{
100 if (GNUNET_SCHEDULER_NO_TASK != speedup_task) 100 if (NULL != speedup_task)
101 { 101 {
102 GNUNET_SCHEDULER_cancel (speedup_task); 102 GNUNET_SCHEDULER_cancel (speedup_task);
103 speedup_task = GNUNET_SCHEDULER_NO_TASK; 103 speedup_task = NULL;
104 } 104 }
105 if ( (0 != interval.rel_value_us) && 105 if ( (0 != interval.rel_value_us) &&
106 (0 != delta.rel_value_us) ) 106 (0 != delta.rel_value_us) )
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 0fe8614d0..42371f33f 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -49,9 +49,9 @@ static struct GNUNET_OS_Process *proc;
49/* Pipe to read from started processes stdout (on read end) */ 49/* Pipe to read from started processes stdout (on read end) */
50static struct GNUNET_DISK_PipeHandle *pipe_stdout; 50static struct GNUNET_DISK_PipeHandle *pipe_stdout;
51 51
52static GNUNET_SCHEDULER_TaskIdentifier die_task; 52static struct GNUNET_SCHEDULER_Task * die_task;
53 53
54static GNUNET_SCHEDULER_TaskIdentifier read_task; 54static struct GNUNET_SCHEDULER_Task * read_task;
55 55
56static void 56static void
57runone (void); 57runone (void);
@@ -72,10 +72,10 @@ end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
72 GNUNET_OS_process_destroy (proc); 72 GNUNET_OS_process_destroy (proc);
73 proc = NULL; 73 proc = NULL;
74 } 74 }
75 if (GNUNET_SCHEDULER_NO_TASK != read_task) 75 if (NULL != read_task)
76 { 76 {
77 GNUNET_SCHEDULER_cancel (read_task); 77 GNUNET_SCHEDULER_cancel (read_task);
78 read_task = GNUNET_SCHEDULER_NO_TASK; 78 read_task = NULL;
79 } 79 }
80 GNUNET_DISK_pipe_close (pipe_stdout); 80 GNUNET_DISK_pipe_close (pipe_stdout);
81 if (ok == 1) 81 if (ok == 1)
@@ -223,7 +223,7 @@ read_call (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
223 long delays[8]; 223 long delays[8];
224 int rd; 224 int rd;
225 225
226 read_task = GNUNET_SCHEDULER_NO_TASK; 226 read_task = NULL;
227 rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr, 227 rd = GNUNET_DISK_file_read (stdout_read_handle, buf_ptr,
228 sizeof (buf) - bytes); 228 sizeof (buf) - bytes);
229 if (rd > 0) 229 if (rd > 0)
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c
index e76ec5bcf..e350c7ea7 100644
--- a/src/util/test_os_start_process.c
+++ b/src/util/test_os_start_process.c
@@ -46,7 +46,7 @@ static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin;
46 */ 46 */
47static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout; 47static struct GNUNET_DISK_PipeHandle *hello_pipe_stdout;
48 48
49static GNUNET_SCHEDULER_TaskIdentifier die_task; 49static struct GNUNET_SCHEDULER_Task * die_task;
50 50
51struct read_context 51struct read_context
52{ 52{