diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-24 01:10:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-24 01:10:47 +0000 |
commit | f1f603c7d0b3f03dca46a4f313472288eb080eb1 (patch) | |
tree | 3a29966b02dfb83e0a8a8d5c42b3116380209fb0 /src/util/server.c | |
parent | 53cd5b8eda2fa8db86b0907a62a39598981d008a (diff) | |
download | gnunet-f1f603c7d0b3f03dca46a4f313472288eb080eb1.tar.gz gnunet-f1f603c7d0b3f03dca46a4f313472288eb080eb1.zip |
making GNUNET_SCHEDULER_cancel() perform in O(1) instead of O(n) to help or even fully address #3247
Diffstat (limited to 'src/util/server.c')
-rw-r--r-- | src/util/server.c | 46 |
1 files changed, 23 insertions, 23 deletions
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) | |||
691 | void | 691 | void |
692 | GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server) | 692 | GNUNET_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, | |||
909 | void | 909 | void |
910 | GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) | 910 | GNUNET_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 | ||