diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-07 22:57:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-07 22:57:34 +0000 |
commit | 4a25afcbc1cd57637f340a5b5369b999429b79f9 (patch) | |
tree | 531547e5772bc98d8c6251e38549d5264b1ec25f /src/util | |
parent | e78d610f4f9bb6f8f04d585309c8e0befda4918e (diff) | |
download | gnunet-4a25afcbc1cd57637f340a5b5369b999429b79f9.tar.gz gnunet-4a25afcbc1cd57637f340a5b5369b999429b79f9.zip |
-doxygen and style fixes
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/scheduler.c | 225 |
1 files changed, 127 insertions, 98 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index e08adad75..7f7246ec0 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -86,7 +86,7 @@ struct Task | |||
86 | GNUNET_SCHEDULER_Task callback; | 86 | GNUNET_SCHEDULER_Task callback; |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * Closure for the callback. | 89 | * Closure for the @e callback. |
90 | */ | 90 | */ |
91 | void *callback_cls; | 91 | void *callback_cls; |
92 | 92 | ||
@@ -293,7 +293,7 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, | |||
293 | 293 | ||
294 | now = GNUNET_TIME_absolute_get (); | 294 | now = GNUNET_TIME_absolute_get (); |
295 | pos = pending_timeout; | 295 | pos = pending_timeout; |
296 | if (pos != NULL) | 296 | if (NULL != pos) |
297 | { | 297 | { |
298 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); | 298 | to = GNUNET_TIME_absolute_get_difference (now, pos->timeout); |
299 | if (timeout->rel_value_us > to.rel_value_us) | 299 | if (timeout->rel_value_us > to.rel_value_us) |
@@ -302,7 +302,7 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, | |||
302 | *timeout = GNUNET_TIME_UNIT_ZERO; | 302 | *timeout = GNUNET_TIME_UNIT_ZERO; |
303 | } | 303 | } |
304 | pos = pending; | 304 | pos = pending; |
305 | while (pos != NULL) | 305 | while (NULL != pos) |
306 | { | 306 | { |
307 | if (pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 307 | if (pos->timeout.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
308 | { | 308 | { |
@@ -310,15 +310,15 @@ update_sets (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws, | |||
310 | if (timeout->rel_value_us > to.rel_value_us) | 310 | if (timeout->rel_value_us > to.rel_value_us) |
311 | *timeout = to; | 311 | *timeout = to; |
312 | } | 312 | } |
313 | if (pos->read_fd != -1) | 313 | if (-1 != pos->read_fd) |
314 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); | 314 | GNUNET_NETWORK_fdset_set_native (rs, pos->read_fd); |
315 | if (pos->write_fd != -1) | 315 | if (-1 != pos->write_fd) |
316 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); | 316 | GNUNET_NETWORK_fdset_set_native (ws, pos->write_fd); |
317 | if (pos->read_set != NULL) | 317 | if (NULL != pos->read_set) |
318 | GNUNET_NETWORK_fdset_add (rs, pos->read_set); | 318 | GNUNET_NETWORK_fdset_add (rs, pos->read_set); |
319 | if (pos->write_set != NULL) | 319 | if (NULL != pos->write_set) |
320 | GNUNET_NETWORK_fdset_add (ws, pos->write_set); | 320 | GNUNET_NETWORK_fdset_add (ws, pos->write_set); |
321 | if (pos->reason != 0) | 321 | if (0 != pos->reason) |
322 | *timeout = GNUNET_TIME_UNIT_ZERO; | 322 | *timeout = GNUNET_TIME_UNIT_ZERO; |
323 | pos = pos->next; | 323 | pos = pos->next; |
324 | } | 324 | } |
@@ -381,7 +381,7 @@ is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, | |||
381 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) | 381 | (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, task->write_fd))) |
382 | || (set_overlaps (ws, task->write_set)))) | 382 | || (set_overlaps (ws, task->write_set)))) |
383 | reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; | 383 | reason |= GNUNET_SCHEDULER_REASON_WRITE_READY; |
384 | if (reason == 0) | 384 | if (0 == reason) |
385 | return GNUNET_NO; /* not ready */ | 385 | return GNUNET_NO; /* not ready */ |
386 | reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; | 386 | reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE; |
387 | task->reason = reason; | 387 | task->reason = reason; |
@@ -426,7 +426,7 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, | |||
426 | now = GNUNET_TIME_absolute_get (); | 426 | now = GNUNET_TIME_absolute_get (); |
427 | prev = NULL; | 427 | prev = NULL; |
428 | pos = pending_timeout; | 428 | pos = pending_timeout; |
429 | while (pos != NULL) | 429 | while (NULL != pos) |
430 | { | 430 | { |
431 | next = pos->next; | 431 | next = pos->next; |
432 | if (now.abs_value_us >= pos->timeout.abs_value_us) | 432 | if (now.abs_value_us >= pos->timeout.abs_value_us) |
@@ -440,7 +440,7 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, | |||
440 | pos = next; | 440 | pos = next; |
441 | } | 441 | } |
442 | pos = pending; | 442 | pos = pending; |
443 | while (pos != NULL) | 443 | while (NULL != pos) |
444 | { | 444 | { |
445 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 445 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
446 | "Checking readiness of task: %llu / %p\n", | 446 | "Checking readiness of task: %llu / %p\n", |
@@ -448,7 +448,7 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs, | |||
448 | next = pos->next; | 448 | next = pos->next; |
449 | if (GNUNET_YES == is_ready (pos, now, rs, ws)) | 449 | if (GNUNET_YES == is_ready (pos, now, rs, ws)) |
450 | { | 450 | { |
451 | if (prev == NULL) | 451 | if (NULL == prev) |
452 | pending = next; | 452 | pending = next; |
453 | else | 453 | else |
454 | prev->next = next; | 454 | prev->next = next; |
@@ -476,7 +476,7 @@ GNUNET_SCHEDULER_shutdown () | |||
476 | int i; | 476 | int i; |
477 | 477 | ||
478 | pos = pending_timeout; | 478 | pos = pending_timeout; |
479 | while (pos != NULL) | 479 | while (NULL != pos) |
480 | { | 480 | { |
481 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 481 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
482 | /* we don't move the task into the ready queue yet; check_ready | 482 | /* we don't move the task into the ready queue yet; check_ready |
@@ -485,7 +485,7 @@ GNUNET_SCHEDULER_shutdown () | |||
485 | pos = pos->next; | 485 | pos = pos->next; |
486 | } | 486 | } |
487 | pos = pending; | 487 | pos = pending; |
488 | while (pos != NULL) | 488 | while (NULL != pos) |
489 | { | 489 | { |
490 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 490 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
491 | /* we don't move the task into the ready queue yet; check_ready | 491 | /* we don't move the task into the ready queue yet; check_ready |
@@ -496,7 +496,7 @@ GNUNET_SCHEDULER_shutdown () | |||
496 | for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) | 496 | for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++) |
497 | { | 497 | { |
498 | pos = ready[i]; | 498 | pos = ready[i]; |
499 | while (pos != NULL) | 499 | while (NULL != pos) |
500 | { | 500 | { |
501 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; | 501 | pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN; |
502 | /* we don't move the task into the ready queue yet; check_ready | 502 | /* we don't move the task into the ready queue yet; check_ready |
@@ -538,7 +538,8 @@ destroy_task (struct Task *t) | |||
538 | * @param ws FDs ready for writing | 538 | * @param ws FDs ready for writing |
539 | */ | 539 | */ |
540 | static void | 540 | static void |
541 | run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) | 541 | run_ready (struct GNUNET_NETWORK_FDSet *rs, |
542 | struct GNUNET_NETWORK_FDSet *ws) | ||
542 | { | 543 | { |
543 | enum GNUNET_SCHEDULER_Priority p; | 544 | enum GNUNET_SCHEDULER_Priority p; |
544 | struct Task *pos; | 545 | struct Task *pos; |
@@ -547,7 +548,7 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) | |||
547 | max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; | 548 | max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; |
548 | do | 549 | do |
549 | { | 550 | { |
550 | if (ready_count == 0) | 551 | if (0 == ready_count) |
551 | return; | 552 | return; |
552 | GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); | 553 | GNUNET_assert (ready[GNUNET_SCHEDULER_PRIORITY_KEEP] == NULL); |
553 | /* yes, p>0 is correct, 0 is "KEEP" which should | 554 | /* yes, p>0 is correct, 0 is "KEEP" which should |
@@ -555,10 +556,10 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) | |||
555 | for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) | 556 | for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--) |
556 | { | 557 | { |
557 | pos = ready[p]; | 558 | pos = ready[p]; |
558 | if (pos != NULL) | 559 | if (NULL != pos) |
559 | break; | 560 | break; |
560 | } | 561 | } |
561 | GNUNET_assert (pos != NULL); /* ready_count wrong? */ | 562 | GNUNET_assert (NULL != pos); /* ready_count wrong? */ |
562 | ready[p] = pos->next; | 563 | ready[p] = pos->next; |
563 | ready_count--; | 564 | ready_count--; |
564 | current_priority = pos->priority; | 565 | current_priority = pos->priority; |
@@ -571,7 +572,8 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) | |||
571 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 572 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
572 | "Task %llu took %s to be scheduled\n", | 573 | "Task %llu took %s to be scheduled\n", |
573 | (unsigned long long) pos->id, | 574 | (unsigned long long) pos->id, |
574 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), GNUNET_YES)); | 575 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), |
576 | GNUNET_YES)); | ||
575 | } | 577 | } |
576 | #endif | 578 | #endif |
577 | tc.reason = pos->reason; | 579 | tc.reason = pos->reason; |
@@ -595,14 +597,17 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws) | |||
595 | int i; | 597 | int i; |
596 | 598 | ||
597 | for (i = 0; i < pos->num_backtrace_strings; i++) | 599 | for (i = 0; i < pos->num_backtrace_strings; i++) |
598 | LOG (GNUNET_ERROR_TYPE_ERROR, "Task %llu trace %d: %s\n", pos->id, i, | 600 | LOG (GNUNET_ERROR_TYPE_ERROR, |
601 | "Task %llu trace %d: %s\n", | ||
602 | pos->id, | ||
603 | i, | ||
599 | pos->backtrace_strings[i]); | 604 | pos->backtrace_strings[i]); |
600 | #endif | 605 | #endif |
601 | active_task = NULL; | 606 | active_task = NULL; |
602 | destroy_task (pos); | 607 | destroy_task (pos); |
603 | tasks_run++; | 608 | tasks_run++; |
604 | } | 609 | } |
605 | while ((pending == NULL) || (p >= max_priority_added)); | 610 | while ((NULL == pending) || (p >= max_priority_added)); |
606 | } | 611 | } |
607 | 612 | ||
608 | /** | 613 | /** |
@@ -697,16 +702,16 @@ check_lifeness () | |||
697 | /** | 702 | /** |
698 | * Initialize and run scheduler. This function will return when all | 703 | * Initialize and run scheduler. This function will return when all |
699 | * tasks have completed. On systems with signals, receiving a SIGTERM | 704 | * tasks have completed. On systems with signals, receiving a SIGTERM |
700 | * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown" | 705 | * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown() |
701 | * to be run after the active task is complete. As a result, SIGTERM | 706 | * to be run after the active task is complete. As a result, SIGTERM |
702 | * causes all active tasks to be scheduled with reason | 707 | * causes all active tasks to be scheduled with reason |
703 | * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added | 708 | * #GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added |
704 | * afterwards will execute normally!). Note that any particular signal | 709 | * afterwards will execute normally!). Note that any particular signal |
705 | * will only shut down one scheduler; applications should always only | 710 | * will only shut down one scheduler; applications should always only |
706 | * create a single scheduler. | 711 | * create a single scheduler. |
707 | * | 712 | * |
708 | * @param task task to run immediately | 713 | * @param task task to run immediately |
709 | * @param task_cls closure of task | 714 | * @param task_cls closure of @a task |
710 | */ | 715 | */ |
711 | void | 716 | void |
712 | GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | 717 | GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) |
@@ -717,7 +722,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
717 | int ret; | 722 | int ret; |
718 | struct GNUNET_SIGNAL_Context *shc_int; | 723 | struct GNUNET_SIGNAL_Context *shc_int; |
719 | struct GNUNET_SIGNAL_Context *shc_term; | 724 | struct GNUNET_SIGNAL_Context *shc_term; |
720 | #if (SIGTERM != GNUNET_TERM_SIG) | 725 | #if (SIGTERM != GNUNET_TERM_SIG) |
721 | struct GNUNET_SIGNAL_Context *shc_gterm; | 726 | struct GNUNET_SIGNAL_Context *shc_gterm; |
722 | #endif | 727 | #endif |
723 | 728 | ||
@@ -731,12 +736,12 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
731 | const struct GNUNET_DISK_FileHandle *pr; | 736 | const struct GNUNET_DISK_FileHandle *pr; |
732 | char c; | 737 | char c; |
733 | 738 | ||
734 | GNUNET_assert (active_task == NULL); | 739 | GNUNET_assert (NULL == active_task); |
735 | rs = GNUNET_NETWORK_fdset_create (); | 740 | rs = GNUNET_NETWORK_fdset_create (); |
736 | ws = GNUNET_NETWORK_fdset_create (); | 741 | ws = GNUNET_NETWORK_fdset_create (); |
737 | GNUNET_assert (shutdown_pipe_handle == NULL); | 742 | GNUNET_assert (NULL == shutdown_pipe_handle); |
738 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); | 743 | shutdown_pipe_handle = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); |
739 | GNUNET_assert (shutdown_pipe_handle != NULL); | 744 | GNUNET_assert (NULL != shutdown_pipe_handle); |
740 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, | 745 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, |
741 | GNUNET_DISK_PIPE_END_READ); | 746 | GNUNET_DISK_PIPE_END_READ); |
742 | GNUNET_assert (pr != NULL); | 747 | GNUNET_assert (pr != NULL); |
@@ -793,15 +798,19 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
793 | (void) close (1); | 798 | (void) close (1); |
794 | (void) dup2 (2, 1); | 799 | (void) dup2 (2, 1); |
795 | if (0 != system (lsof)) | 800 | if (0 != system (lsof)) |
796 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system"); | 801 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
802 | "system"); | ||
797 | #endif | 803 | #endif |
798 | #endif | 804 | #endif |
799 | GNUNET_abort (); | 805 | GNUNET_abort (); |
800 | break; | 806 | break; |
801 | } | 807 | } |
802 | if ((0 == ret) && (0 == timeout.rel_value_us) && (busy_wait_warning > 16)) | 808 | if ( (0 == ret) && |
809 | (0 == timeout.rel_value_us) && | ||
810 | (busy_wait_warning > 16) ) | ||
803 | { | 811 | { |
804 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n")); | 812 | LOG (GNUNET_ERROR_TYPE_WARNING, |
813 | _("Looks like we're busy waiting...\n")); | ||
805 | short_wait (100); /* mitigate */ | 814 | short_wait (100); /* mitigate */ |
806 | } | 815 | } |
807 | check_ready (rs, ws); | 816 | check_ready (rs, ws); |
@@ -844,7 +853,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
844 | /** | 853 | /** |
845 | * Obtain the reason code for why the current task was | 854 | * Obtain the reason code for why the current task was |
846 | * started. Will return the same value as | 855 | * started. Will return the same value as |
847 | * the GNUNET_SCHEDULER_TaskContext's reason field. | 856 | * the `struct GNUNET_SCHEDULER_TaskContext`'s reason field. |
848 | * | 857 | * |
849 | * @return reason(s) why the current task is run | 858 | * @return reason(s) why the current task is run |
850 | */ | 859 | */ |
@@ -878,7 +887,7 @@ GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p) | |||
878 | p = current_priority; | 887 | p = current_priority; |
879 | ret = 0; | 888 | ret = 0; |
880 | pos = ready[check_priority (p)]; | 889 | pos = ready[check_priority (p)]; |
881 | while (pos != NULL) | 890 | while (NULL != pos) |
882 | { | 891 | { |
883 | pos = pos->next; | 892 | pos = pos->next; |
884 | ret++; | 893 | ret++; |
@@ -903,18 +912,18 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
903 | int to; | 912 | int to; |
904 | void *ret; | 913 | void *ret; |
905 | 914 | ||
906 | GNUNET_assert (active_task != NULL); | 915 | GNUNET_assert (NULL != active_task); |
907 | to = 0; | 916 | to = 0; |
908 | prev = NULL; | 917 | prev = NULL; |
909 | t = pending; | 918 | t = pending; |
910 | while (t != NULL) | 919 | while (NULL != t) |
911 | { | 920 | { |
912 | if (t->id == task) | 921 | if (t->id == task) |
913 | break; | 922 | break; |
914 | prev = t; | 923 | prev = t; |
915 | t = t->next; | 924 | t = t->next; |
916 | } | 925 | } |
917 | if (t == NULL) | 926 | if (NULL == t) |
918 | { | 927 | { |
919 | prev = NULL; | 928 | prev = NULL; |
920 | to = 1; | 929 | to = 1; |
@@ -930,18 +939,19 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
930 | pending_timeout_last = NULL; | 939 | pending_timeout_last = NULL; |
931 | } | 940 | } |
932 | p = 0; | 941 | p = 0; |
933 | while (t == NULL) | 942 | while (NULL == t) |
934 | { | 943 | { |
935 | p++; | 944 | p++; |
936 | if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) | 945 | if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) |
937 | { | 946 | { |
938 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Attempt to cancel dead task %llu!\n"), | 947 | LOG (GNUNET_ERROR_TYPE_ERROR, |
948 | _("Attempt to cancel dead task %llu!\n"), | ||
939 | (unsigned long long) task); | 949 | (unsigned long long) task); |
940 | GNUNET_assert (0); | 950 | GNUNET_assert (0); |
941 | } | 951 | } |
942 | prev = NULL; | 952 | prev = NULL; |
943 | t = ready[p]; | 953 | t = ready[p]; |
944 | while (t != NULL) | 954 | while (NULL != t) |
945 | { | 955 | { |
946 | if (t->id == task) | 956 | if (t->id == task) |
947 | { | 957 | { |
@@ -952,11 +962,11 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
952 | t = t->next; | 962 | t = t->next; |
953 | } | 963 | } |
954 | } | 964 | } |
955 | if (prev == NULL) | 965 | if (NULL == prev) |
956 | { | 966 | { |
957 | if (p == 0) | 967 | if (0 == p) |
958 | { | 968 | { |
959 | if (to == 0) | 969 | if (0 == to) |
960 | { | 970 | { |
961 | pending = t->next; | 971 | pending = t->next; |
962 | } | 972 | } |
@@ -975,7 +985,9 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
975 | prev->next = t->next; | 985 | prev->next = t->next; |
976 | } | 986 | } |
977 | ret = t->callback_cls; | 987 | ret = t->callback_cls; |
978 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling task: %llu / %p\n", task, | 988 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
989 | "Canceling task: %llu / %p\n", | ||
990 | task, | ||
979 | t->callback_cls); | 991 | t->callback_cls); |
980 | destroy_task (t); | 992 | destroy_task (t); |
981 | return ret; | 993 | return ret; |
@@ -988,7 +1000,7 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task) | |||
988 | * and the reason code can be specified. | 1000 | * and the reason code can be specified. |
989 | * | 1001 | * |
990 | * @param task main function of the task | 1002 | * @param task main function of the task |
991 | * @param task_cls closure for 'main' | 1003 | * @param task_cls closure for @a task |
992 | * @param reason reason for task invocation | 1004 | * @param reason reason for task invocation |
993 | * @param priority priority to use for the task | 1005 | * @param priority priority to use for the task |
994 | */ | 1006 | */ |
@@ -1004,9 +1016,9 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi | |||
1004 | #endif | 1016 | #endif |
1005 | 1017 | ||
1006 | GNUNET_assert (NULL != task); | 1018 | GNUNET_assert (NULL != task); |
1007 | GNUNET_assert ((active_task != NULL) || | 1019 | GNUNET_assert ((NULL != active_task) || |
1008 | (reason == GNUNET_SCHEDULER_REASON_STARTUP)); | 1020 | (GNUNET_SCHEDULER_REASON_STARTUP == reason)); |
1009 | t = GNUNET_malloc (sizeof (struct Task)); | 1021 | t = GNUNET_new (struct Task); |
1010 | #if EXECINFO | 1022 | #if EXECINFO |
1011 | t->num_backtrace_strings = backtrace (backtrace_array, 50); | 1023 | t->num_backtrace_strings = backtrace (backtrace_array, 50); |
1012 | t->backtrace_strings = | 1024 | t->backtrace_strings = |
@@ -1023,7 +1035,9 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi | |||
1023 | t->reason = reason; | 1035 | t->reason = reason; |
1024 | t->priority = priority; | 1036 | t->priority = priority; |
1025 | t->lifeness = current_lifeness; | 1037 | t->lifeness = current_lifeness; |
1026 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id, | 1038 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1039 | "Adding continuation task: %llu / %p\n", | ||
1040 | t->id, | ||
1027 | t->callback_cls); | 1041 | t->callback_cls); |
1028 | queue_ready_task (t); | 1042 | queue_ready_task (t); |
1029 | } | 1043 | } |
@@ -1035,7 +1049,7 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi | |||
1035 | * and the reason code can be specified. | 1049 | * and the reason code can be specified. |
1036 | * | 1050 | * |
1037 | * @param task main function of the task | 1051 | * @param task main function of the task |
1038 | * @param task_cls closure for 'main' | 1052 | * @param task_cls closure for @a task |
1039 | * @param reason reason for task invocation | 1053 | * @param reason reason for task invocation |
1040 | */ | 1054 | */ |
1041 | void | 1055 | void |
@@ -1052,10 +1066,10 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, | |||
1052 | * Schedule a new task to be run with a specified priority. | 1066 | * Schedule a new task to be run with a specified priority. |
1053 | * | 1067 | * |
1054 | * @param prio how important is the new task? | 1068 | * @param prio how important is the new task? |
1055 | * @param task main function of the task | 1069 | * @param task main function of the @a task |
1056 | * @param task_cls closure of task | 1070 | * @param task_cls closure of task |
1057 | * @return unique task identifier for the job | 1071 | * @return unique task identifier for the job |
1058 | * only valid until "task" is started! | 1072 | * only valid until @a task is started! |
1059 | */ | 1073 | */ |
1060 | GNUNET_SCHEDULER_TaskIdentifier | 1074 | GNUNET_SCHEDULER_TaskIdentifier |
1061 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | 1075 | GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, |
@@ -1073,12 +1087,12 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, | |||
1073 | * will be scheduled for execution once the delay has expired. | 1087 | * will be scheduled for execution once the delay has expired. |
1074 | * | 1088 | * |
1075 | * @param delay when should this operation time out? Use | 1089 | * @param delay when should this operation time out? Use |
1076 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | 1090 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" |
1077 | * @param priority priority to use for the task | 1091 | * @param priority priority to use for the task |
1078 | * @param task main function of the task | 1092 | * @param task main function of the task |
1079 | * @param task_cls closure of task | 1093 | * @param task_cls closure of @a task |
1080 | * @return unique task identifier for the job | 1094 | * @return unique task identifier for the job |
1081 | * only valid until "task" is started! | 1095 | * only valid until @a task is started! |
1082 | */ | 1096 | */ |
1083 | GNUNET_SCHEDULER_TaskIdentifier | 1097 | GNUNET_SCHEDULER_TaskIdentifier |
1084 | GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, | 1098 | GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, |
@@ -1093,9 +1107,9 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, | |||
1093 | void *backtrace_array[MAX_TRACE_DEPTH]; | 1107 | void *backtrace_array[MAX_TRACE_DEPTH]; |
1094 | #endif | 1108 | #endif |
1095 | 1109 | ||
1096 | GNUNET_assert (active_task != NULL); | 1110 | GNUNET_assert (NULL != active_task); |
1097 | GNUNET_assert (NULL != task); | 1111 | GNUNET_assert (NULL != task); |
1098 | t = GNUNET_malloc (sizeof (struct Task)); | 1112 | t = GNUNET_new (struct Task); |
1099 | t->callback = task; | 1113 | t->callback = task; |
1100 | t->callback_cls = task_cls; | 1114 | t->callback_cls = task_cls; |
1101 | #if EXECINFO | 1115 | #if EXECINFO |
@@ -1204,14 +1218,14 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
1204 | * (transitive) ignore-shutdown flag either explicitly set or | 1218 | * (transitive) ignore-shutdown flag either explicitly set or |
1205 | * explicitly enabled. This task (and all tasks created from it, | 1219 | * explicitly enabled. This task (and all tasks created from it, |
1206 | * other than by another call to this function) will either count or | 1220 | * other than by another call to this function) will either count or |
1207 | * not count for the 'lifeness' of the process. This API is only | 1221 | * not count for the "lifeness" of the process. This API is only |
1208 | * useful in a few special cases. | 1222 | * useful in a few special cases. |
1209 | * | 1223 | * |
1210 | * @param lifeness GNUNET_YES if the task counts for lifeness, GNUNET_NO if not. | 1224 | * @param lifeness #GNUNET_YES if the task counts for lifeness, #GNUNET_NO if not. |
1211 | * @param task main function of the task | 1225 | * @param task main function of the task |
1212 | * @param task_cls closure of task | 1226 | * @param task_cls closure of @a task |
1213 | * @return unique task identifier for the job | 1227 | * @return unique task identifier for the job |
1214 | * only valid until "task" is started! | 1228 | * only valid until @a task is started! |
1215 | */ | 1229 | */ |
1216 | GNUNET_SCHEDULER_TaskIdentifier | 1230 | GNUNET_SCHEDULER_TaskIdentifier |
1217 | GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | 1231 | GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, |
@@ -1247,13 +1261,13 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, | |||
1247 | * || shutdown-active ) | 1261 | * || shutdown-active ) |
1248 | * </code> | 1262 | * </code> |
1249 | * | 1263 | * |
1250 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", | 1264 | * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever", |
1251 | * which means that the task will only be run after we receive SIGTERM | 1265 | * which means that the task will only be run after we receive SIGTERM |
1252 | * @param priority priority to use | 1266 | * @param priority priority to use |
1253 | * @param rfd file descriptor we want to read (can be -1) | 1267 | * @param rfd file descriptor we want to read (can be -1) |
1254 | * @param wfd file descriptors we want to write (can be -1) | 1268 | * @param wfd file descriptors we want to write (can be -1) |
1255 | * @param task main function of the task | 1269 | * @param task main function of the task |
1256 | * @param task_cls closure of task | 1270 | * @param task_cls closure of @a task |
1257 | * @return unique task identifier for the job | 1271 | * @return unique task identifier for the job |
1258 | * only valid until "task" is started! | 1272 | * only valid until "task" is started! |
1259 | */ | 1273 | */ |
@@ -1270,9 +1284,9 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1270 | void *backtrace_array[MAX_TRACE_DEPTH]; | 1284 | void *backtrace_array[MAX_TRACE_DEPTH]; |
1271 | #endif | 1285 | #endif |
1272 | 1286 | ||
1273 | GNUNET_assert (active_task != NULL); | 1287 | GNUNET_assert (NULL != active_task); |
1274 | GNUNET_assert (NULL != task); | 1288 | GNUNET_assert (NULL != task); |
1275 | t = GNUNET_malloc (sizeof (struct Task)); | 1289 | t = GNUNET_new (struct Task); |
1276 | t->callback = task; | 1290 | t->callback = task; |
1277 | t->callback_cls = task_cls; | 1291 | t->callback_cls = task_cls; |
1278 | #if EXECINFO | 1292 | #if EXECINFO |
@@ -1287,12 +1301,16 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1287 | 1301 | ||
1288 | if ((flags == -1) && (errno == EBADF)) | 1302 | if ((flags == -1) && (errno == EBADF)) |
1289 | { | 1303 | { |
1290 | LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", rfd); | 1304 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1305 | "Got invalid file descriptor %d!\n", | ||
1306 | rfd); | ||
1291 | #if EXECINFO | 1307 | #if EXECINFO |
1292 | int i; | 1308 | int i; |
1293 | 1309 | ||
1294 | for (i = 0; i < t->num_backtrace_strings; i++) | 1310 | for (i = 0; i < t->num_backtrace_strings; i++) |
1295 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]); | 1311 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1312 | "Trace: %s\n", | ||
1313 | t->backtrace_strings[i]); | ||
1296 | #endif | 1314 | #endif |
1297 | GNUNET_assert (0); | 1315 | GNUNET_assert (0); |
1298 | } | 1316 | } |
@@ -1303,12 +1321,16 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1303 | 1321 | ||
1304 | if (flags == -1 && errno == EBADF) | 1322 | if (flags == -1 && errno == EBADF) |
1305 | { | 1323 | { |
1306 | LOG (GNUNET_ERROR_TYPE_ERROR, "Got invalid file descriptor %d!\n", wfd); | 1324 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1325 | "Got invalid file descriptor %d!\n", | ||
1326 | wfd); | ||
1307 | #if EXECINFO | 1327 | #if EXECINFO |
1308 | int i; | 1328 | int i; |
1309 | 1329 | ||
1310 | for (i = 0; i < t->num_backtrace_strings; i++) | 1330 | for (i = 0; i < t->num_backtrace_strings; i++) |
1311 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Trace: %s\n", t->backtrace_strings[i]); | 1331 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1332 | "Trace: %s\n", | ||
1333 | t->backtrace_strings[i]); | ||
1312 | #endif | 1334 | #endif |
1313 | GNUNET_assert (0); | 1335 | GNUNET_assert (0); |
1314 | } | 1336 | } |
@@ -1327,13 +1349,18 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1327 | t->next = pending; | 1349 | t->next = pending; |
1328 | pending = t; | 1350 | pending = t; |
1329 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); | 1351 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); |
1330 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, | 1352 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1353 | "Adding task: %llu / %p\n", | ||
1354 | t->id, | ||
1331 | t->callback_cls); | 1355 | t->callback_cls); |
1332 | #if EXECINFO | 1356 | #if EXECINFO |
1333 | int i; | 1357 | int i; |
1334 | 1358 | ||
1335 | for (i = 0; i < t->num_backtrace_strings; i++) | 1359 | for (i = 0; i < t->num_backtrace_strings; i++) |
1336 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, | 1360 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1361 | "Task %llu trace %d: %s\n", | ||
1362 | t->id, | ||
1363 | i, | ||
1337 | t->backtrace_strings[i]); | 1364 | t->backtrace_strings[i]); |
1338 | #endif | 1365 | #endif |
1339 | return t->id; | 1366 | return t->id; |
@@ -1350,12 +1377,12 @@ add_without_sets (struct GNUNET_TIME_Relative delay, | |||
1350 | * socket operation is ready. It will be run with the DEFAULT priority. | 1377 | * socket operation is ready. It will be run with the DEFAULT priority. |
1351 | * | 1378 | * |
1352 | * @param delay when should this operation time out? Use | 1379 | * @param delay when should this operation time out? Use |
1353 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | 1380 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" |
1354 | * @param rfd read file-descriptor | 1381 | * @param rfd read file-descriptor |
1355 | * @param task main function of the task | 1382 | * @param task main function of the task |
1356 | * @param task_cls closure of task | 1383 | * @param task_cls closure of @a task |
1357 | * @return unique task identifier for the job | 1384 | * @return unique task identifier for the job |
1358 | * only valid until "task" is started! | 1385 | * only valid until @a task is started! |
1359 | */ | 1386 | */ |
1360 | GNUNET_SCHEDULER_TaskIdentifier | 1387 | GNUNET_SCHEDULER_TaskIdentifier |
1361 | GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | 1388 | GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, |
@@ -1377,13 +1404,13 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, | |||
1377 | * will be run with the DEFAULT priority. | 1404 | * will be run with the DEFAULT priority. |
1378 | * | 1405 | * |
1379 | * @param delay when should this operation time out? Use | 1406 | * @param delay when should this operation time out? Use |
1380 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | 1407 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" |
1381 | * @param priority priority to use for the task | 1408 | * @param priority priority to use for the task |
1382 | * @param rfd read file-descriptor | 1409 | * @param rfd read file-descriptor |
1383 | * @param task main function of the task | 1410 | * @param task main function of the task |
1384 | * @param task_cls closure of task | 1411 | * @param task_cls closure of @a task |
1385 | * @return unique task identifier for the job | 1412 | * @return unique task identifier for the job |
1386 | * only valid until "task" is started! | 1413 | * only valid until @a task is started! |
1387 | */ | 1414 | */ |
1388 | GNUNET_SCHEDULER_TaskIdentifier | 1415 | GNUNET_SCHEDULER_TaskIdentifier |
1389 | GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, | 1416 | GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, |
@@ -1395,7 +1422,7 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, | |||
1395 | struct GNUNET_NETWORK_FDSet *rs; | 1422 | struct GNUNET_NETWORK_FDSet *rs; |
1396 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1423 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1397 | 1424 | ||
1398 | GNUNET_assert (rfd != NULL); | 1425 | GNUNET_assert (NULL != rfd); |
1399 | rs = GNUNET_NETWORK_fdset_create (); | 1426 | rs = GNUNET_NETWORK_fdset_create (); |
1400 | GNUNET_NETWORK_fdset_set (rs, rfd); | 1427 | GNUNET_NETWORK_fdset_set (rs, rfd); |
1401 | ret = | 1428 | ret = |
@@ -1413,7 +1440,6 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, | |||
1413 | } | 1440 | } |
1414 | 1441 | ||
1415 | 1442 | ||
1416 | |||
1417 | /** | 1443 | /** |
1418 | * Schedule a new task to be run with a specified delay or when the | 1444 | * Schedule a new task to be run with a specified delay or when the |
1419 | * specified file descriptor is ready for writing. The delay can be | 1445 | * specified file descriptor is ready for writing. The delay can be |
@@ -1423,12 +1449,12 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, | |||
1423 | * the calling task. | 1449 | * the calling task. |
1424 | * | 1450 | * |
1425 | * @param delay when should this operation time out? Use | 1451 | * @param delay when should this operation time out? Use |
1426 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | 1452 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" |
1427 | * @param wfd write file-descriptor | 1453 | * @param wfd write file-descriptor |
1428 | * @param task main function of the task | 1454 | * @param task main function of the task |
1429 | * @param task_cls closure of task | 1455 | * @param task_cls closure of @a task |
1430 | * @return unique task identifier for the job | 1456 | * @return unique task identifier for the job |
1431 | * only valid until "task" is started! | 1457 | * only valid until @a task is started! |
1432 | */ | 1458 | */ |
1433 | GNUNET_SCHEDULER_TaskIdentifier | 1459 | GNUNET_SCHEDULER_TaskIdentifier |
1434 | GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | 1460 | GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, |
@@ -1439,7 +1465,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1439 | struct GNUNET_NETWORK_FDSet *ws; | 1465 | struct GNUNET_NETWORK_FDSet *ws; |
1440 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1466 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1441 | 1467 | ||
1442 | GNUNET_assert (wfd != NULL); | 1468 | GNUNET_assert (NULL != wfd); |
1443 | ws = GNUNET_NETWORK_fdset_create (); | 1469 | ws = GNUNET_NETWORK_fdset_create (); |
1444 | GNUNET_NETWORK_fdset_set (ws, wfd); | 1470 | GNUNET_NETWORK_fdset_set (ws, wfd); |
1445 | ret = | 1471 | ret = |
@@ -1466,12 +1492,12 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, | |||
1466 | * socket operation is ready. It will be run with the DEFAULT priority. | 1492 | * socket operation is ready. It will be run with the DEFAULT priority. |
1467 | * | 1493 | * |
1468 | * @param delay when should this operation time out? Use | 1494 | * @param delay when should this operation time out? Use |
1469 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | 1495 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" |
1470 | * @param rfd read file-descriptor | 1496 | * @param rfd read file-descriptor |
1471 | * @param task main function of the task | 1497 | * @param task main function of the task |
1472 | * @param task_cls closure of task | 1498 | * @param task_cls closure of @a task |
1473 | * @return unique task identifier for the job | 1499 | * @return unique task identifier for the job |
1474 | * only valid until "task" is started! | 1500 | * only valid until @a task is started! |
1475 | */ | 1501 | */ |
1476 | GNUNET_SCHEDULER_TaskIdentifier | 1502 | GNUNET_SCHEDULER_TaskIdentifier |
1477 | GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | 1503 | GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, |
@@ -1482,7 +1508,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1482 | struct GNUNET_NETWORK_FDSet *rs; | 1508 | struct GNUNET_NETWORK_FDSet *rs; |
1483 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1509 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1484 | 1510 | ||
1485 | GNUNET_assert (rfd != NULL); | 1511 | GNUNET_assert (NULL != rfd); |
1486 | rs = GNUNET_NETWORK_fdset_create (); | 1512 | rs = GNUNET_NETWORK_fdset_create (); |
1487 | GNUNET_NETWORK_fdset_handle_set (rs, rfd); | 1513 | GNUNET_NETWORK_fdset_handle_set (rs, rfd); |
1488 | ret = | 1514 | ret = |
@@ -1511,12 +1537,12 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, | |||
1511 | * socket operation is ready. It will be run with the DEFAULT priority. | 1537 | * socket operation is ready. It will be run with the DEFAULT priority. |
1512 | * | 1538 | * |
1513 | * @param delay when should this operation time out? Use | 1539 | * @param delay when should this operation time out? Use |
1514 | * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" | 1540 | * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" |
1515 | * @param wfd write file-descriptor | 1541 | * @param wfd write file-descriptor |
1516 | * @param task main function of the task | 1542 | * @param task main function of the task |
1517 | * @param task_cls closure of task | 1543 | * @param task_cls closure of @a task |
1518 | * @return unique task identifier for the job | 1544 | * @return unique task identifier for the job |
1519 | * only valid until "task" is started! | 1545 | * only valid until @a task is started! |
1520 | */ | 1546 | */ |
1521 | GNUNET_SCHEDULER_TaskIdentifier | 1547 | GNUNET_SCHEDULER_TaskIdentifier |
1522 | GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | 1548 | GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, |
@@ -1527,7 +1553,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1527 | struct GNUNET_NETWORK_FDSet *ws; | 1553 | struct GNUNET_NETWORK_FDSet *ws; |
1528 | GNUNET_SCHEDULER_TaskIdentifier ret; | 1554 | GNUNET_SCHEDULER_TaskIdentifier ret; |
1529 | 1555 | ||
1530 | GNUNET_assert (wfd != NULL); | 1556 | GNUNET_assert (NULL != wfd); |
1531 | ws = GNUNET_NETWORK_fdset_create (); | 1557 | ws = GNUNET_NETWORK_fdset_create (); |
1532 | GNUNET_NETWORK_fdset_handle_set (ws, wfd); | 1558 | GNUNET_NETWORK_fdset_handle_set (ws, wfd); |
1533 | ret = | 1559 | ret = |
@@ -1549,7 +1575,6 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1549 | } | 1575 | } |
1550 | 1576 | ||
1551 | 1577 | ||
1552 | |||
1553 | /** | 1578 | /** |
1554 | * Schedule a new task to be run with a specified delay or when any of | 1579 | * Schedule a new task to be run with a specified delay or when any of |
1555 | * the specified file descriptor sets is ready. The delay can be used | 1580 | * the specified file descriptor sets is ready. The delay can be used |
@@ -1568,14 +1593,14 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, | |||
1568 | * </code> | 1593 | * </code> |
1569 | * | 1594 | * |
1570 | * @param prio how important is this task? | 1595 | * @param prio how important is this task? |
1571 | * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", | 1596 | * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever", |
1572 | * which means that the task will only be run after we receive SIGTERM | 1597 | * which means that the task will only be run after we receive SIGTERM |
1573 | * @param rs set of file descriptors we want to read (can be NULL) | 1598 | * @param rs set of file descriptors we want to read (can be NULL) |
1574 | * @param ws set of file descriptors we want to write (can be NULL) | 1599 | * @param ws set of file descriptors we want to write (can be NULL) |
1575 | * @param task main function of the task | 1600 | * @param task main function of the task |
1576 | * @param task_cls closure of task | 1601 | * @param task_cls closure of @a task |
1577 | * @return unique task identifier for the job | 1602 | * @return unique task identifier for the job |
1578 | * only valid until "task" is started! | 1603 | * only valid until @a task is started! |
1579 | */ | 1604 | */ |
1580 | GNUNET_SCHEDULER_TaskIdentifier | 1605 | GNUNET_SCHEDULER_TaskIdentifier |
1581 | GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | 1606 | GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, |
@@ -1592,7 +1617,7 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1592 | 1617 | ||
1593 | GNUNET_assert (NULL != active_task); | 1618 | GNUNET_assert (NULL != active_task); |
1594 | GNUNET_assert (NULL != task); | 1619 | GNUNET_assert (NULL != task); |
1595 | t = GNUNET_malloc (sizeof (struct Task)); | 1620 | t = GNUNET_new (struct Task); |
1596 | t->callback = task; | 1621 | t->callback = task; |
1597 | t->callback_cls = task_cls; | 1622 | t->callback_cls = task_cls; |
1598 | #if EXECINFO | 1623 | #if EXECINFO |
@@ -1625,13 +1650,17 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1625 | t->next = pending; | 1650 | t->next = pending; |
1626 | pending = t; | 1651 | pending = t; |
1627 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); | 1652 | max_priority_added = GNUNET_MAX (max_priority_added, t->priority); |
1628 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding task: %llu / %p\n", t->id, | 1653 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1654 | "Adding task: %llu / %p\n", | ||
1655 | t->id, | ||
1629 | t->callback_cls); | 1656 | t->callback_cls); |
1630 | #if EXECINFO | 1657 | #if EXECINFO |
1631 | int i; | 1658 | int i; |
1632 | 1659 | ||
1633 | for (i = 0; i < t->num_backtrace_strings; i++) | 1660 | for (i = 0; i < t->num_backtrace_strings; i++) |
1634 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Task %llu trace %d: %s\n", t->id, i, | 1661 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1662 | "Task %llu trace %d: %s\n", | ||
1663 | t->id, i, | ||
1635 | t->backtrace_strings[i]); | 1664 | t->backtrace_strings[i]); |
1636 | #endif | 1665 | #endif |
1637 | return t->id; | 1666 | return t->id; |