aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-01 21:12:17 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-01 21:12:17 +0000
commit64c442461b84953230d3dc4e78cb649db6c54abc (patch)
tree49ec875b32ce171aac2bbae1b5fcaad516a94cf6 /src
parent0413c7690e087a0514447a87bc8118b2a244c902 (diff)
downloadgnunet-64c442461b84953230d3dc4e78cb649db6c54abc.tar.gz
gnunet-64c442461b84953230d3dc4e78cb649db6c54abc.zip
changing scheduler priorities to revert to DEFAULT instead of inheriting parent-task priority unless something else is explicitly specified
Diffstat (limited to 'src')
-rw-r--r--src/arm/gnunet-service-arm.c8
-rw-r--r--src/chat/gnunet-chat.c7
-rw-r--r--src/datastore/gnunet-service-datastore.c12
-rw-r--r--src/fs/fs_api.c3
-rw-r--r--src/fs/gnunet-service-fs_cp.c4
-rw-r--r--src/include/gnunet_scheduler_lib.h59
-rw-r--r--src/nse/gnunet-service-nse.c4
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c11
-rw-r--r--src/util/crypto_hash.c9
-rw-r--r--src/util/scheduler.c129
10 files changed, 168 insertions, 78 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index e8e1113f0..4c78e6fe7 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -805,8 +805,9 @@ delayed_restart_task (void *cls,
805 (unsigned long long) lowestRestartDelay.rel_value); 805 (unsigned long long) lowestRestartDelay.rel_value);
806#endif 806#endif
807 child_restart_task = 807 child_restart_task =
808 GNUNET_SCHEDULER_add_delayed (lowestRestartDelay, 808 GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
809 &delayed_restart_task, NULL); 809 GNUNET_SCHEDULER_PRIORITY_IDLE,
810 &delayed_restart_task, NULL);
810 } 811 }
811} 812}
812 813
@@ -922,7 +923,8 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
922 GNUNET_SCHEDULER_cancel (child_restart_task); 923 GNUNET_SCHEDULER_cancel (child_restart_task);
923 child_restart_task = 924 child_restart_task =
924 GNUNET_SCHEDULER_add_with_priority 925 GNUNET_SCHEDULER_add_with_priority
925 (GNUNET_SCHEDULER_PRIORITY_IDLE, &delayed_restart_task, NULL); 926 (GNUNET_SCHEDULER_PRIORITY_IDLE,
927 &delayed_restart_task, NULL);
926 } 928 }
927 else 929 else
928 { 930 {
diff --git a/src/chat/gnunet-chat.c b/src/chat/gnunet-chat.c
index af4eb53f3..4abc58c9f 100644
--- a/src/chat/gnunet-chat.c
+++ b/src/chat/gnunet-chat.c
@@ -572,9 +572,10 @@ handle_command (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
572 572
573next: 573next:
574 handle_cmd_task = 574 handle_cmd_task =
575 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 575 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_multiply
576 (GNUNET_TIME_UNIT_MILLISECONDS, 100), 576 (GNUNET_TIME_UNIT_MILLISECONDS, 100),
577 &handle_command, NULL); 577 GNUNET_SCHEDULER_PRIORITY_UI,
578 &handle_command, NULL);
578 return; 579 return;
579 580
580out: 581out:
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index bf89c1bc2..1d7e8cd2b 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -326,7 +326,9 @@ expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
326 if (key == NULL) 326 if (key == NULL)
327 { 327 {
328 expired_kill_task = 328 expired_kill_task =
329 GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL); 329 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
330 GNUNET_SCHEDULER_PRIORITY_IDLE,
331 &delete_expired, NULL);
330 return GNUNET_SYSERR; 332 return GNUNET_SYSERR;
331 } 333 }
332 now = GNUNET_TIME_absolute_get (); 334 now = GNUNET_TIME_absolute_get ();
@@ -334,7 +336,9 @@ expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
334 { 336 {
335 /* finished processing */ 337 /* finished processing */
336 expired_kill_task = 338 expired_kill_task =
337 GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL); 339 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
340 GNUNET_SCHEDULER_PRIORITY_IDLE,
341 &delete_expired, NULL);
338 return GNUNET_SYSERR; 342 return GNUNET_SYSERR;
339 } 343 }
340#if DEBUG_DATASTORE 344#if DEBUG_DATASTORE
@@ -348,7 +352,9 @@ expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
348 GNUNET_YES); 352 GNUNET_YES);
349 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 353 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
350 expired_kill_task = 354 expired_kill_task =
351 GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL); 355 GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
356 GNUNET_SCHEDULER_PRIORITY_IDLE,
357 &delete_expired, NULL);
352 return GNUNET_NO; 358 return GNUNET_NO;
353} 359}
354 360
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c
index 293638732..2b1e51031 100644
--- a/src/fs/fs_api.c
+++ b/src/fs/fs_api.c
@@ -1356,7 +1356,8 @@ deserialize_publish_file (void *cls, const char *filename)
1356 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 1356 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
1357 pc->upload_task = 1357 pc->upload_task =
1358 GNUNET_SCHEDULER_add_with_priority 1358 GNUNET_SCHEDULER_add_with_priority
1359 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 1359 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1360 &GNUNET_FS_publish_main_, pc);
1360 } 1361 }
1361 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) 1362 if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg))
1362 { 1363 {
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index 164e264c6..4711c09e6 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -1816,7 +1816,9 @@ cron_flush_trust (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1816 return; 1816 return;
1817 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1817 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1818 return; 1818 return;
1819 GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ, &cron_flush_trust, NULL); 1819 GNUNET_SCHEDULER_add_delayed_with_priority (TRUST_FLUSH_FREQ,
1820 GNUNET_SCHEDULER_PRIORITY_HIGH,
1821 &cron_flush_trust, NULL);
1820} 1822}
1821 1823
1822 1824
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index 9b8c57ff3..e16ccc511 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -111,7 +111,9 @@ enum GNUNET_SCHEDULER_Priority
111 111
112 /** 112 /**
113 * Run with the default priority (normal 113 * Run with the default priority (normal
114 * P2P operations). Higher than BACKGROUND. 114 * P2P operations). Any task that is scheduled
115 * without an explicit priority being specified
116 * will run with this priority.
115 */ 117 */
116 GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3, 118 GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3,
117 119
@@ -262,7 +264,7 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p);
262 * * @return reason(s) why the current task is run 264 * * @return reason(s) why the current task is run
263 */ 265 */
264enum GNUNET_SCHEDULER_Reason 266enum GNUNET_SCHEDULER_Reason
265GNUNET_SCHEDULER_get_reason (); 267GNUNET_SCHEDULER_get_reason (void);
266 268
267 269
268/** 270/**
@@ -291,9 +293,24 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
291 293
292 294
293/** 295/**
296 * Continue the current execution with the given function. This is
297 * similar to the other "add" functions except that there is no delay
298 * and the reason code can be specified.
299 *
300 * @param task main function of the task
301 * @param task_cls closure for 'main'
302 * @param reason reason for task invocation
303 * @param priority priority to use for the task
304 */
305void
306GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, void *task_cls,
307 enum GNUNET_SCHEDULER_Reason reason,
308 enum GNUNET_SCHEDULER_Priority priority);
309
310
311/**
294 * Schedule a new task to be run after the specified prerequisite task 312 * Schedule a new task to be run after the specified prerequisite task
295 * has completed. It will be run with the priority of the calling 313 * has completed. It will be run with DEFAULT priority.
296 * task.
297 * 314 *
298 * * @param prerequisite_task run this task after the task with the given 315 * * @param prerequisite_task run this task after the task with the given
299 * task identifier completes (and any of our other 316 * task identifier completes (and any of our other
@@ -327,7 +344,7 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
327 344
328/** 345/**
329 * Schedule a new task to be run as soon as possible. The task 346 * Schedule a new task to be run as soon as possible. The task
330 * will be run with the priority of the calling task. 347 * will be run with the DEFAULT priority.
331 * 348 *
332 * * @param task main function of the task 349 * * @param task main function of the task
333 * @param task_cls closure of task 350 * @param task_cls closure of task
@@ -361,7 +378,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
361/** 378/**
362 * Schedule a new task to be run with a specified delay. The task 379 * Schedule a new task to be run with a specified delay. The task
363 * will be scheduled for execution once the delay has expired. It 380 * will be scheduled for execution once the delay has expired. It
364 * will be run with the priority of the calling task. 381 * will be run with the DEFAULT priority.
365 * 382 *
366 * * @param delay when should this operation time out? Use 383 * * @param delay when should this operation time out? Use
367 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 384 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -376,12 +393,29 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
376 393
377 394
378/** 395/**
396 * Schedule a new task to be run with a specified delay. The task
397 * will be scheduled for execution once the delay has expired.
398 *
399 * @param delay when should this operation time out? Use
400 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
401 * @param priority priority to use for the task
402 * @param task main function of the task
403 * @param task_cls closure of task
404 * @return unique task identifier for the job
405 * only valid until "task" is started!
406 */
407GNUNET_SCHEDULER_TaskIdentifier
408GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
409 enum GNUNET_SCHEDULER_Priority priority,
410 GNUNET_SCHEDULER_Task task, void *task_cls);
411
412
413/**
379 * Schedule a new task to be run with a specified delay or when the 414 * Schedule a new task to be run with a specified delay or when the
380 * specified file descriptor is ready for reading. The delay can be 415 * specified file descriptor is ready for reading. The delay can be
381 * used as a timeout on the socket being ready. The task will be 416 * used as a timeout on the socket being ready. The task will be
382 * scheduled for execution once either the delay has expired or the 417 * scheduled for execution once either the delay has expired or the
383 * socket operation is ready. It will be run with the priority of 418 * socket operation is ready. It will be run with the DEFAULT priority.
384 * the calling task.
385 * 419 *
386 * * @param delay when should this operation time out? Use 420 * * @param delay when should this operation time out? Use
387 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 421 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -402,8 +436,7 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
402 * specified file descriptor is ready for writing. The delay can be 436 * specified file descriptor is ready for writing. The delay can be
403 * used as a timeout on the socket being ready. The task will be 437 * used as a timeout on the socket being ready. The task will be
404 * scheduled for execution once either the delay has expired or the 438 * scheduled for execution once either the delay has expired or the
405 * socket operation is ready. It will be run with the priority of 439 * socket operation is ready. It will be run with the DEFAULT priority.
406 * the calling task.
407 * 440 *
408 * * @param delay when should this operation time out? Use 441 * * @param delay when should this operation time out? Use
409 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 442 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -424,8 +457,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
424 * specified file descriptor is ready for reading. The delay can be 457 * specified file descriptor is ready for reading. The delay can be
425 * used as a timeout on the socket being ready. The task will be 458 * used as a timeout on the socket being ready. The task will be
426 * scheduled for execution once either the delay has expired or the 459 * scheduled for execution once either the delay has expired or the
427 * socket operation is ready. It will be run with the priority of 460 * socket operation is ready. It will be run with the DEFAULT priority.
428 * the calling task.
429 * 461 *
430 * * @param delay when should this operation time out? Use 462 * * @param delay when should this operation time out? Use
431 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 463 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -446,8 +478,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
446 * specified file descriptor is ready for writing. The delay can be 478 * specified file descriptor is ready for writing. The delay can be
447 * used as a timeout on the socket being ready. The task will be 479 * used as a timeout on the socket being ready. The task will be
448 * scheduled for execution once either the delay has expired or the 480 * scheduled for execution once either the delay has expired or the
449 * socket operation is ready. It will be run with the priority of 481 * socket operation is ready. It will be run with the DEFAULT priority.
450 * the calling task.
451 * 482 *
452 * * @param delay when should this operation time out? Use 483 * * @param delay when should this operation time out? Use
453 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 484 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 30493851e..6617fdfea 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -911,7 +911,9 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
911 my_proof = counter; 911 my_proof = counter;
912 } 912 }
913 proof_task = 913 proof_task =
914 GNUNET_SCHEDULER_add_delayed (proof_find_delay, &find_proof, NULL); 914 GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
915 GNUNET_SCHEDULER_PRIORITY_IDLE,
916 &find_proof, NULL);
915} 917}
916 918
917 919
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 799fdc6d8..d6e52d4b4 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -293,8 +293,9 @@ cron_scan_directory_data_hosts (void *cls,
293 count = 0; 293 count = 0;
294 if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) 294 if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
295 { 295 {
296 GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, 296 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
297 &cron_scan_directory_data_hosts, NULL); 297 GNUNET_SCHEDULER_PRIORITY_IDLE,
298 &cron_scan_directory_data_hosts, NULL);
298 return; 299 return;
299 } 300 }
300 GNUNET_DISK_directory_scan (networkIdDirectory, 301 GNUNET_DISK_directory_scan (networkIdDirectory,
@@ -302,8 +303,10 @@ cron_scan_directory_data_hosts (void *cls,
302 if ((0 == count) && (0 == (++retries & 31))) 303 if ((0 == count) && (0 == (++retries & 31)))
303 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
304 _("Still no peers found in `%s'!\n"), networkIdDirectory); 305 _("Still no peers found in `%s'!\n"), networkIdDirectory);
305 GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, &cron_scan_directory_data_hosts, 306 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
306 NULL); 307 GNUNET_SCHEDULER_PRIORITY_IDLE,
308 &cron_scan_directory_data_hosts,
309 NULL);
307} 310}
308 311
309 312
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 2ab682494..9faa213ae 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -106,6 +106,11 @@ struct GNUNET_CRYPTO_FileHashContext
106 GNUNET_SCHEDULER_TaskIdentifier task; 106 GNUNET_SCHEDULER_TaskIdentifier task;
107 107
108 /** 108 /**
109 * Priority we use.
110 */
111 enum GNUNET_SCHEDULER_Priority priority;
112
113 /**
109 * Blocksize. 114 * Blocksize.
110 */ 115 */
111 size_t bsize; 116 size_t bsize;
@@ -162,7 +167,8 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162 file_hash_finish (fhc, res); 167 file_hash_finish (fhc, res);
163 return; 168 return;
164 } 169 }
165 fhc->task = GNUNET_SCHEDULER_add_now (&file_hash_task, fhc); 170 fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority,
171 &file_hash_task, fhc);
166} 172}
167 173
168 174
@@ -213,6 +219,7 @@ GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
213 GNUNET_free (fhc); 219 GNUNET_free (fhc);
214 return NULL; 220 return NULL;
215 } 221 }
222 fhc->priority = priority;
216 fhc->task = 223 fhc->task =
217 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc); 224 GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
218 return fhc; 225 return fhc;
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 1acc9a6d6..5f91ffbbc 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -1054,10 +1054,12 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1054 * @param task main function of the task 1054 * @param task main function of the task
1055 * @param task_cls closure for 'main' 1055 * @param task_cls closure for 'main'
1056 * @param reason reason for task invocation 1056 * @param reason reason for task invocation
1057 * @param priority priority to use for the task
1057 */ 1058 */
1058void 1059void
1059GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, 1060GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, void *task_cls,
1060 enum GNUNET_SCHEDULER_Reason reason) 1061 enum GNUNET_SCHEDULER_Reason reason,
1062 enum GNUNET_SCHEDULER_Priority priority)
1061{ 1063{
1062 struct Task *t; 1064 struct Task *t;
1063 1065
@@ -1083,7 +1085,7 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1083 t->start_time = GNUNET_TIME_absolute_get (); 1085 t->start_time = GNUNET_TIME_absolute_get ();
1084#endif 1086#endif
1085 t->reason = reason; 1087 t->reason = reason;
1086 t->priority = current_priority; 1088 t->priority = priority;
1087 t->lifeness = current_lifeness; 1089 t->lifeness = current_lifeness;
1088#if DEBUG_TASKS 1090#if DEBUG_TASKS
1089 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id, 1091 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id,
@@ -1093,11 +1095,28 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1093} 1095}
1094 1096
1095 1097
1098/**
1099 * Continue the current execution with the given function. This is
1100 * similar to the other "add" functions except that there is no delay
1101 * and the reason code can be specified.
1102 *
1103 * @param task main function of the task
1104 * @param task_cls closure for 'main'
1105 * @param reason reason for task invocation
1106 */
1107void
1108GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1109 enum GNUNET_SCHEDULER_Reason reason)
1110{
1111 GNUNET_SCHEDULER_add_continuation_with_priority (task, task_cls,
1112 reason,
1113 GNUNET_SCHEDULER_PRIORITY_DEFAULT);
1114}
1115
1096 1116
1097/** 1117/**
1098 * Schedule a new task to be run after the specified prerequisite task 1118 * Schedule a new task to be run after the specified prerequisite task
1099 * has completed. It will be run with the priority of the calling 1119 * has completed. It will be run with the DEFAULT priority.
1100 * task.
1101 * 1120 *
1102 * @param prerequisite_task run this task after the task with the given 1121 * @param prerequisite_task run this task after the task with the given
1103 * task identifier completes (and any of our other 1122 * task identifier completes (and any of our other
@@ -1114,7 +1133,7 @@ GNUNET_SCHEDULER_TaskIdentifier
1114GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 1133GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1115 GNUNET_SCHEDULER_Task task, void *task_cls) 1134 GNUNET_SCHEDULER_Task task, void *task_cls)
1116{ 1135{
1117 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1136 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1118 prerequisite_task, GNUNET_TIME_UNIT_ZERO, 1137 prerequisite_task, GNUNET_TIME_UNIT_ZERO,
1119 NULL, NULL, task, task_cls); 1138 NULL, NULL, task, task_cls);
1120} 1139}
@@ -1142,22 +1161,21 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1142 1161
1143/** 1162/**
1144 * Schedule a new task to be run with a specified delay. The task 1163 * Schedule a new task to be run with a specified delay. The task
1145 * will be scheduled for execution once the delay has expired. It 1164 * will be scheduled for execution once the delay has expired.
1146 * will be run with the priority of the calling task.
1147 * 1165 *
1148 * @param delay when should this operation time out? Use 1166 * @param delay when should this operation time out? Use
1149 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1167 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1168 * @param priority priority to use for the task
1150 * @param task main function of the task 1169 * @param task main function of the task
1151 * @param task_cls closure of task 1170 * @param task_cls closure of task
1152 * @return unique task identifier for the job 1171 * @return unique task identifier for the job
1153 * only valid until "task" is started! 1172 * only valid until "task" is started!
1154 */ 1173 */
1155GNUNET_SCHEDULER_TaskIdentifier 1174GNUNET_SCHEDULER_TaskIdentifier
1156GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, 1175GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1157 GNUNET_SCHEDULER_Task task, void *task_cls) 1176 enum GNUNET_SCHEDULER_Priority priority,
1177 GNUNET_SCHEDULER_Task task, void *task_cls)
1158{ 1178{
1159#if 1
1160 /* new, optimized version */
1161 struct Task *t; 1179 struct Task *t;
1162 struct Task *pos; 1180 struct Task *pos;
1163 struct Task *prev; 1181 struct Task *prev;
@@ -1183,7 +1201,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1183 t->start_time = GNUNET_TIME_absolute_get (); 1201 t->start_time = GNUNET_TIME_absolute_get ();
1184#endif 1202#endif
1185 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1203 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1186 t->priority = current_priority; 1204 t->priority = priority;
1187 t->lifeness = current_lifeness; 1205 t->lifeness = current_lifeness;
1188 /* try tail first (optimization in case we are 1206 /* try tail first (optimization in case we are
1189 * appending to a long list of tasks with timeouts) */ 1207 * appending to a long list of tasks with timeouts) */
@@ -1227,20 +1245,34 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1227 t->backtrace_strings[i]); 1245 t->backtrace_strings[i]);
1228#endif 1246#endif
1229 return t->id; 1247 return t->id;
1230
1231#else
1232 /* unoptimized version */
1233 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1234 GNUNET_SCHEDULER_NO_TASK, delay, NULL,
1235 NULL, task, task_cls);
1236#endif
1237} 1248}
1238 1249
1239 1250
1251/**
1252 * Schedule a new task to be run with a specified delay. The task
1253 * will be scheduled for execution once the delay has expired. It
1254 * will be run with the DEFAULT priority.
1255 *
1256 * @param delay when should this operation time out? Use
1257 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1258 * @param task main function of the task
1259 * @param task_cls closure of task
1260 * @return unique task identifier for the job
1261 * only valid until "task" is started!
1262 */
1263GNUNET_SCHEDULER_TaskIdentifier
1264GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1265 GNUNET_SCHEDULER_Task task, void *task_cls)
1266{
1267 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1268 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1269 task, task_cls);
1270}
1271
1240 1272
1241/** 1273/**
1242 * Schedule a new task to be run as soon as possible. The task 1274 * Schedule a new task to be run as soon as possible. The task
1243 * will be run with the priority of the calling task. 1275 * will be run with the DEFAULT priority.
1244 * 1276 *
1245 * @param task main function of the task 1277 * @param task main function of the task
1246 * @param task_cls closure of task 1278 * @param task_cls closure of task
@@ -1250,10 +1282,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1250GNUNET_SCHEDULER_TaskIdentifier 1282GNUNET_SCHEDULER_TaskIdentifier
1251GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) 1283GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
1252{ 1284{
1253 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1285 return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls);
1254 GNUNET_SCHEDULER_NO_TASK,
1255 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1256 task_cls);
1257} 1286}
1258 1287
1259 1288
@@ -1279,7 +1308,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1279 GNUNET_SCHEDULER_TaskIdentifier ret; 1308 GNUNET_SCHEDULER_TaskIdentifier ret;
1280 1309
1281 ret = 1310 ret =
1282 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1311 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1283 GNUNET_SCHEDULER_NO_TASK, 1312 GNUNET_SCHEDULER_NO_TASK,
1284 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, 1313 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1285 task_cls); 1314 task_cls);
@@ -1289,8 +1318,6 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1289} 1318}
1290 1319
1291 1320
1292
1293
1294/** 1321/**
1295 * Schedule a new task to be run with a specified delay or when any of 1322 * Schedule a new task to be run with a specified delay or when any of
1296 * the specified file descriptor sets is ready. The delay can be used 1323 * the specified file descriptor sets is ready. The delay can be used
@@ -1310,6 +1337,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1310 * 1337 *
1311 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", 1338 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever",
1312 * which means that the task will only be run after we receive SIGTERM 1339 * which means that the task will only be run after we receive SIGTERM
1340 * @param priority priority to use
1313 * @param rfd file descriptor we want to read (can be -1) 1341 * @param rfd file descriptor we want to read (can be -1)
1314 * @param wfd file descriptors we want to write (can be -1) 1342 * @param wfd file descriptors we want to write (can be -1)
1315 * @param task main function of the task 1343 * @param task main function of the task
@@ -1319,7 +1347,9 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1319 */ 1347 */
1320#ifndef MINGW 1348#ifndef MINGW
1321static GNUNET_SCHEDULER_TaskIdentifier 1349static GNUNET_SCHEDULER_TaskIdentifier
1322add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, 1350add_without_sets (struct GNUNET_TIME_Relative delay,
1351 enum GNUNET_SCHEDULER_Priority priority,
1352 int rfd, int wfd,
1323 GNUNET_SCHEDULER_Task task, void *task_cls) 1353 GNUNET_SCHEDULER_Task task, void *task_cls)
1324{ 1354{
1325 struct Task *t; 1355 struct Task *t;
@@ -1381,7 +1411,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1381#endif 1411#endif
1382 t->prereq_id = GNUNET_SCHEDULER_NO_TASK; 1412 t->prereq_id = GNUNET_SCHEDULER_NO_TASK;
1383 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1413 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1384 t->priority = check_priority (current_priority); 1414 t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority);
1385 t->lifeness = current_lifeness; 1415 t->lifeness = current_lifeness;
1386 t->next = pending; 1416 t->next = pending;
1387 pending = t; 1417 pending = t;
@@ -1408,8 +1438,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1408 * specified file descriptor is ready for reading. The delay can be 1438 * specified file descriptor is ready for reading. The delay can be
1409 * used as a timeout on the socket being ready. The task will be 1439 * used as a timeout on the socket being ready. The task will be
1410 * scheduled for execution once either the delay has expired or the 1440 * scheduled for execution once either the delay has expired or the
1411 * socket operation is ready. It will be run with the priority of 1441 * socket operation is ready. It will be run with the DEFAULT priority.
1412 * the calling task.
1413 * 1442 *
1414 * @param delay when should this operation time out? Use 1443 * @param delay when should this operation time out? Use
1415 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1444 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -1432,13 +1461,15 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1432 rs = GNUNET_NETWORK_fdset_create (); 1461 rs = GNUNET_NETWORK_fdset_create ();
1433 GNUNET_NETWORK_fdset_set (rs, rfd); 1462 GNUNET_NETWORK_fdset_set (rs, rfd);
1434 ret = 1463 ret =
1435 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1464 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1436 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, 1465 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1437 task, task_cls); 1466 task, task_cls);
1438 GNUNET_NETWORK_fdset_destroy (rs); 1467 GNUNET_NETWORK_fdset_destroy (rs);
1439 return ret; 1468 return ret;
1440#else 1469#else
1441 return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task, 1470 return add_without_sets (delay,
1471 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1472 GNUNET_NETWORK_get_fd (rfd), -1, task,
1442 task_cls); 1473 task_cls);
1443#endif 1474#endif
1444} 1475}
@@ -1473,14 +1504,16 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1473 ws = GNUNET_NETWORK_fdset_create (); 1504 ws = GNUNET_NETWORK_fdset_create ();
1474 GNUNET_NETWORK_fdset_set (ws, wfd); 1505 GNUNET_NETWORK_fdset_set (ws, wfd);
1475 ret = 1506 ret =
1476 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1507 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1477 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, 1508 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1478 task, task_cls); 1509 task, task_cls);
1479 GNUNET_NETWORK_fdset_destroy (ws); 1510 GNUNET_NETWORK_fdset_destroy (ws);
1480 return ret; 1511 return ret;
1481#else 1512#else
1482 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); 1513 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0);
1483 return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task, 1514 return add_without_sets (delay,
1515 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1516 -1, GNUNET_NETWORK_get_fd (wfd), task,
1484 task_cls); 1517 task_cls);
1485#endif 1518#endif
1486} 1519}
@@ -1491,8 +1524,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1491 * specified file descriptor is ready for reading. The delay can be 1524 * specified file descriptor is ready for reading. The delay can be
1492 * used as a timeout on the socket being ready. The task will be 1525 * used as a timeout on the socket being ready. The task will be
1493 * scheduled for execution once either the delay has expired or the 1526 * scheduled for execution once either the delay has expired or the
1494 * socket operation is ready. It will be run with the priority of 1527 * socket operation is ready. It will be run with the DEFAULT priority.
1495 * the calling task.
1496 * 1528 *
1497 * @param delay when should this operation time out? Use 1529 * @param delay when should this operation time out? Use
1498 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1530 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -1515,7 +1547,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1515 rs = GNUNET_NETWORK_fdset_create (); 1547 rs = GNUNET_NETWORK_fdset_create ();
1516 GNUNET_NETWORK_fdset_handle_set (rs, rfd); 1548 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1517 ret = 1549 ret =
1518 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1550 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1519 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, 1551 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1520 task, task_cls); 1552 task, task_cls);
1521 GNUNET_NETWORK_fdset_destroy (rs); 1553 GNUNET_NETWORK_fdset_destroy (rs);
@@ -1524,7 +1556,9 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1524 int fd; 1556 int fd;
1525 1557
1526 GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int)); 1558 GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int));
1527 return add_without_sets (delay, fd, -1, task, task_cls); 1559 return add_without_sets (delay,
1560 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1561 fd, -1, task, task_cls);
1528 1562
1529#endif 1563#endif
1530} 1564}
@@ -1535,8 +1569,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1535 * specified file descriptor is ready for writing. The delay can be 1569 * specified file descriptor is ready for writing. The delay can be
1536 * used as a timeout on the socket being ready. The task will be 1570 * used as a timeout on the socket being ready. The task will be
1537 * scheduled for execution once either the delay has expired or the 1571 * scheduled for execution once either the delay has expired or the
1538 * socket operation is ready. It will be run with the priority of 1572 * socket operation is ready. It will be run with the DEFAULT priority.
1539 * the calling task.
1540 * 1573 *
1541 * @param delay when should this operation time out? Use 1574 * @param delay when should this operation time out? Use
1542 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1575 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -1559,7 +1592,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1559 ws = GNUNET_NETWORK_fdset_create (); 1592 ws = GNUNET_NETWORK_fdset_create ();
1560 GNUNET_NETWORK_fdset_handle_set (ws, wfd); 1593 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
1561 ret = 1594 ret =
1562 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1595 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1563 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, 1596 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1564 task, task_cls); 1597 task, task_cls);
1565 GNUNET_NETWORK_fdset_destroy (ws); 1598 GNUNET_NETWORK_fdset_destroy (ws);
@@ -1569,7 +1602,9 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1569 1602
1570 GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int)); 1603 GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int));
1571 GNUNET_assert (fd >= 0); 1604 GNUNET_assert (fd >= 0);
1572 return add_without_sets (delay, -1, fd, task, task_cls); 1605 return add_without_sets (delay,
1606 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1607 -1, fd, task, task_cls);
1573 1608
1574#endif 1609#endif
1575} 1610}