aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-24 01:10:47 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-24 01:10:47 +0000
commitf1f603c7d0b3f03dca46a4f313472288eb080eb1 (patch)
tree3a29966b02dfb83e0a8a8d5c42b3116380209fb0 /src/nse
parent53cd5b8eda2fa8db86b0907a62a39598981d008a (diff)
downloadgnunet-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/nse')
-rw-r--r--src/nse/gnunet-nse-profiler.c6
-rw-r--r--src/nse/gnunet-nse.c4
-rw-r--r--src/nse/gnunet-service-nse.c44
-rw-r--r--src/nse/nse_api.c10
-rw-r--r--src/nse/test_nse_api.c4
5 files changed, 34 insertions, 34 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 3e39056be..bdba7bbaf 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -179,7 +179,7 @@ static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
179/** 179/**
180 * The shutdown task 180 * The shutdown task
181 */ 181 */
182static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id; 182static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
183 183
184/** 184/**
185 * Maximum number of connections to NSE services. 185 * Maximum number of connections to NSE services.
@@ -270,7 +270,7 @@ close_monitor_connections ()
270static void 270static void
271shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 271shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
272{ 272{
273 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; 273 shutdown_task_id = NULL;
274 if (GNUNET_YES == shutting_down) 274 if (GNUNET_YES == shutting_down)
275 return; 275 return;
276 shutting_down = GNUNET_YES; 276 shutting_down = GNUNET_YES;
@@ -298,7 +298,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
298static void 298static void
299shutdown_now () 299shutdown_now ()
300{ 300{
301 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task_id) 301 if (NULL != shutdown_task_id)
302 GNUNET_SCHEDULER_cancel (shutdown_task_id); 302 GNUNET_SCHEDULER_cancel (shutdown_task_id);
303 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 303 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
304} 304}
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
index ec2ad26d3..8fb5afde3 100644
--- a/src/nse/gnunet-nse.c
+++ b/src/nse/gnunet-nse.c
@@ -45,7 +45,7 @@ static struct GNUNET_CLIENT_TestHandle *test;
45/** 45/**
46 * Shutdown task 46 * Shutdown task
47 */ 47 */
48static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 48static struct GNUNET_SCHEDULER_Task * shutdown_task;
49 49
50/** 50/**
51 * The program status; 0 for success. 51 * The program status; 0 for success.
@@ -62,7 +62,7 @@ static int status;
62static void 62static void
63do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 63do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
64{ 64{
65 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 65 shutdown_task = NULL;
66 if (NULL != test) 66 if (NULL != test)
67 GNUNET_CLIENT_service_test_cancel (test); 67 GNUNET_CLIENT_service_test_cancel (test);
68 if (NULL != nse) 68 if (NULL != nse)
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 317750b70..e83e94eb0 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -130,7 +130,7 @@ struct NSEPeerEntry
130 /** 130 /**
131 * Task scheduled to send message to this peer. 131 * Task scheduled to send message to this peer.
132 */ 132 */
133 GNUNET_SCHEDULER_TaskIdentifier transmit_task; 133 struct GNUNET_SCHEDULER_Task * transmit_task;
134 134
135 /** 135 /**
136 * Did we receive or send a message about the previous round 136 * Did we receive or send a message about the previous round
@@ -275,12 +275,12 @@ static unsigned int estimate_count;
275/** 275/**
276 * Task scheduled to update our flood message for the next round. 276 * Task scheduled to update our flood message for the next round.
277 */ 277 */
278static GNUNET_SCHEDULER_TaskIdentifier flood_task; 278static struct GNUNET_SCHEDULER_Task * flood_task;
279 279
280/** 280/**
281 * Task scheduled to compute our proof. 281 * Task scheduled to compute our proof.
282 */ 282 */
283static GNUNET_SCHEDULER_TaskIdentifier proof_task; 283static struct GNUNET_SCHEDULER_Task * proof_task;
284 284
285/** 285/**
286 * Notification context, simplifies client broadcasts. 286 * Notification context, simplifies client broadcasts.
@@ -635,7 +635,7 @@ transmit_ready (void *cls,
635 peer_entry); 635 peer_entry);
636 } 636 }
637 if ((0 == ntohl (size_estimate_messages[idx].hop_count)) && 637 if ((0 == ntohl (size_estimate_messages[idx].hop_count)) &&
638 (GNUNET_SCHEDULER_NO_TASK != proof_task)) 638 (NULL != proof_task))
639 { 639 {
640 GNUNET_STATISTICS_update (stats, 640 GNUNET_STATISTICS_update (stats,
641 "# flood messages not generated (no proof yet)", 641 "# flood messages not generated (no proof yet)",
@@ -681,7 +681,7 @@ transmit_task_cb (void *cls,
681{ 681{
682 struct NSEPeerEntry *peer_entry = cls; 682 struct NSEPeerEntry *peer_entry = cls;
683 683
684 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 684 peer_entry->transmit_task = NULL;
685 685
686 GNUNET_assert (NULL == peer_entry->th); 686 GNUNET_assert (NULL == peer_entry->th);
687 peer_entry->th = 687 peer_entry->th =
@@ -772,7 +772,7 @@ schedule_current_round (void *cls,
772 peer_entry->previous_round = GNUNET_NO; 772 peer_entry->previous_round = GNUNET_NO;
773 return GNUNET_OK; 773 return GNUNET_OK;
774 } 774 }
775 if (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task) 775 if (NULL != peer_entry->transmit_task)
776 { 776 {
777 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 777 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
778 peer_entry->previous_round = GNUNET_NO; 778 peer_entry->previous_round = GNUNET_NO;
@@ -806,7 +806,7 @@ update_flood_message (void *cls,
806 struct GNUNET_TIME_Relative offset; 806 struct GNUNET_TIME_Relative offset;
807 unsigned int i; 807 unsigned int i;
808 808
809 flood_task = GNUNET_SCHEDULER_NO_TASK; 809 flood_task = NULL;
810 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 810 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
811 return; 811 return;
812 offset = GNUNET_TIME_absolute_get_remaining (next_timestamp); 812 offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
@@ -931,7 +931,7 @@ find_proof (void *cls,
931 struct GNUNET_HashCode result; 931 struct GNUNET_HashCode result;
932 unsigned int i; 932 unsigned int i;
933 933
934 proof_task = GNUNET_SCHEDULER_NO_TASK; 934 proof_task = NULL;
935 memcpy (&buf[sizeof (uint64_t)], &my_identity, 935 memcpy (&buf[sizeof (uint64_t)], &my_identity,
936 sizeof (struct GNUNET_PeerIdentity)); 936 sizeof (struct GNUNET_PeerIdentity));
937 i = 0; 937 i = 0;
@@ -1034,17 +1034,17 @@ update_flood_times (void *cls,
1034 { 1034 {
1035 /* still stuck in previous round, no point to update, check that 1035 /* still stuck in previous round, no point to update, check that
1036 * we are active here though... */ 1036 * we are active here though... */
1037 if ( (GNUNET_SCHEDULER_NO_TASK == peer_entry->transmit_task) && 1037 if ( (NULL == peer_entry->transmit_task) &&
1038 (NULL == peer_entry->th) ) 1038 (NULL == peer_entry->th) )
1039 { 1039 {
1040 GNUNET_break (0); 1040 GNUNET_break (0);
1041 } 1041 }
1042 return GNUNET_OK; 1042 return GNUNET_OK;
1043 } 1043 }
1044 if (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task) 1044 if (NULL != peer_entry->transmit_task)
1045 { 1045 {
1046 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 1046 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1047 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 1047 peer_entry->transmit_task = NULL;
1048 } 1048 }
1049 delay = get_transmit_delay (0); 1049 delay = get_transmit_delay (0);
1050 peer_entry->transmit_task = 1050 peer_entry->transmit_task =
@@ -1169,10 +1169,10 @@ handle_p2p_size_estimate (void *cls,
1169 } 1169 }
1170 /* got up-to-date information for current round, cancel transmission to 1170 /* got up-to-date information for current round, cancel transmission to
1171 * this peer altogether */ 1171 * this peer altogether */
1172 if (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task) 1172 if (NULL != peer_entry->transmit_task)
1173 { 1173 {
1174 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 1174 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1175 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 1175 peer_entry->transmit_task = NULL;
1176 } 1176 }
1177 if (NULL != peer_entry->th) 1177 if (NULL != peer_entry->th)
1178 { 1178 {
@@ -1189,7 +1189,7 @@ handle_p2p_size_estimate (void *cls,
1189 /* push back our result now, that peer is spreading bad information... */ 1189 /* push back our result now, that peer is spreading bad information... */
1190 if (NULL == peer_entry->th) 1190 if (NULL == peer_entry->th)
1191 { 1191 {
1192 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) 1192 if (peer_entry->transmit_task != NULL)
1193 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 1193 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1194 peer_entry->transmit_task = 1194 peer_entry->transmit_task =
1195 GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry); 1195 GNUNET_SCHEDULER_add_now (&transmit_task_cb, peer_entry);
@@ -1214,10 +1214,10 @@ handle_p2p_size_estimate (void *cls,
1214 if (idx == estimate_index) 1214 if (idx == estimate_index)
1215 { 1215 {
1216 /* cancel any activity for current round */ 1216 /* cancel any activity for current round */
1217 if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) 1217 if (peer_entry->transmit_task != NULL)
1218 { 1218 {
1219 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); 1219 GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1220 peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; 1220 peer_entry->transmit_task = NULL;
1221 } 1221 }
1222 if (peer_entry->th != NULL) 1222 if (peer_entry->th != NULL)
1223 { 1223 {
@@ -1303,9 +1303,9 @@ handle_core_disconnect (void *cls,
1303 GNUNET_assert (GNUNET_YES == 1303 GNUNET_assert (GNUNET_YES ==
1304 GNUNET_CONTAINER_multipeermap_remove (peers, peer, 1304 GNUNET_CONTAINER_multipeermap_remove (peers, peer,
1305 pos)); 1305 pos));
1306 if (pos->transmit_task != GNUNET_SCHEDULER_NO_TASK) { 1306 if (pos->transmit_task != NULL) {
1307 GNUNET_SCHEDULER_cancel (pos->transmit_task); 1307 GNUNET_SCHEDULER_cancel (pos->transmit_task);
1308 pos->transmit_task = GNUNET_SCHEDULER_NO_TASK; 1308 pos->transmit_task = NULL;
1309 } 1309 }
1310 if (NULL != pos->th) 1310 if (NULL != pos->th)
1311 { 1311 {
@@ -1345,15 +1345,15 @@ static void
1345shutdown_task (void *cls, 1345shutdown_task (void *cls,
1346 const struct GNUNET_SCHEDULER_TaskContext *tc) 1346 const struct GNUNET_SCHEDULER_TaskContext *tc)
1347{ 1347{
1348 if (GNUNET_SCHEDULER_NO_TASK != flood_task) 1348 if (NULL != flood_task)
1349 { 1349 {
1350 GNUNET_SCHEDULER_cancel (flood_task); 1350 GNUNET_SCHEDULER_cancel (flood_task);
1351 flood_task = GNUNET_SCHEDULER_NO_TASK; 1351 flood_task = NULL;
1352 } 1352 }
1353 if (GNUNET_SCHEDULER_NO_TASK != proof_task) 1353 if (NULL != proof_task)
1354 { 1354 {
1355 GNUNET_SCHEDULER_cancel (proof_task); 1355 GNUNET_SCHEDULER_cancel (proof_task);
1356 proof_task = GNUNET_SCHEDULER_NO_TASK; 1356 proof_task = NULL;
1357 write_proof (); /* remember progress */ 1357 write_proof (); /* remember progress */
1358 } 1358 }
1359 if (NULL != nc) 1359 if (NULL != nc)
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index bc927f481..edd05b71a 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -57,7 +57,7 @@ struct GNUNET_NSE_Handle
57 /** 57 /**
58 * Task doing exponential back-off trying to reconnect. 58 * Task doing exponential back-off trying to reconnect.
59 */ 59 */
60 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 60 struct GNUNET_SCHEDULER_Task * reconnect_task;
61 61
62 /** 62 /**
63 * Time for next connect retry. 63 * Time for next connect retry.
@@ -133,7 +133,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
133static void 133static void
134reschedule_connect (struct GNUNET_NSE_Handle *h) 134reschedule_connect (struct GNUNET_NSE_Handle *h)
135{ 135{
136 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 136 GNUNET_assert (h->reconnect_task == NULL);
137 137
138 if (NULL != h->th) 138 if (NULL != h->th)
139 { 139 {
@@ -206,7 +206,7 @@ reconnect (void *cls,
206{ 206{
207 struct GNUNET_NSE_Handle *h = cls; 207 struct GNUNET_NSE_Handle *h = cls;
208 208
209 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 209 h->reconnect_task = NULL;
210 LOG (GNUNET_ERROR_TYPE_DEBUG, 210 LOG (GNUNET_ERROR_TYPE_DEBUG,
211 "Connecting to network size estimation service.\n"); 211 "Connecting to network size estimation service.\n");
212 GNUNET_assert (NULL == h->client); 212 GNUNET_assert (NULL == h->client);
@@ -256,10 +256,10 @@ void
256GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h) 256GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h)
257{ 257{
258 GNUNET_assert (NULL != h); 258 GNUNET_assert (NULL != h);
259 if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 259 if (h->reconnect_task != NULL)
260 { 260 {
261 GNUNET_SCHEDULER_cancel (h->reconnect_task); 261 GNUNET_SCHEDULER_cancel (h->reconnect_task);
262 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 262 h->reconnect_task = NULL;
263 } 263 }
264 if (NULL != h->th) 264 if (NULL != h->th)
265 { 265 {
diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c
index 324d4ff16..5eff16c79 100644
--- a/src/nse/test_nse_api.c
+++ b/src/nse/test_nse_api.c
@@ -29,7 +29,7 @@
29 29
30static struct GNUNET_NSE_Handle *h; 30static struct GNUNET_NSE_Handle *h;
31 31
32static GNUNET_SCHEDULER_TaskIdentifier die_task; 32static struct GNUNET_SCHEDULER_Task * die_task;
33 33
34 34
35/** 35/**
@@ -69,7 +69,7 @@ check_nse_message (void *cls, struct GNUNET_TIME_Absolute timestamp,
69 estimate, std_dev); 69 estimate, std_dev);
70 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */ 70 /* Fantastic check below. Expect NaN, the only thing not equal to itself. */
71 (*ok) = 0; 71 (*ok) = 0;
72 if (die_task != GNUNET_SCHEDULER_NO_TASK) 72 if (die_task != NULL)
73 GNUNET_SCHEDULER_cancel (die_task); 73 GNUNET_SCHEDULER_cancel (die_task);
74 die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL); 74 die_task = GNUNET_SCHEDULER_add_now (&end_test, NULL);
75} 75}