diff options
-rw-r--r-- | src/util/scheduler.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 7ef55cd86..b7c24e2ad 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -239,7 +239,7 @@ static int current_lifeness; | |||
239 | 239 | ||
240 | /** | 240 | /** |
241 | * Function to use as a select() in the scheduler. | 241 | * Function to use as a select() in the scheduler. |
242 | * If NULL, we use GNUNET_NETWORK_socket_select (). | 242 | * If NULL, we use GNUNET_NETWORK_socket_select(). |
243 | */ | 243 | */ |
244 | static GNUNET_SCHEDULER_select scheduler_select; | 244 | static GNUNET_SCHEDULER_select scheduler_select; |
245 | 245 | ||
@@ -252,7 +252,7 @@ static void *scheduler_select_cls; | |||
252 | * Sets the select function to use in the scheduler (scheduler_select). | 252 | * Sets the select function to use in the scheduler (scheduler_select). |
253 | * | 253 | * |
254 | * @param new_select new select function to use | 254 | * @param new_select new select function to use |
255 | * @param new_select_cls closure for 'new_select' | 255 | * @param new_select_cls closure for @a new_select |
256 | * @return previously used select function, NULL for default | 256 | * @return previously used select function, NULL for default |
257 | */ | 257 | */ |
258 | void | 258 | void |
@@ -363,7 +363,7 @@ set_overlaps (const struct GNUNET_NETWORK_FDSet *ready, | |||
363 | * @param now the current time | 363 | * @param now the current time |
364 | * @param rs set of FDs ready for reading | 364 | * @param rs set of FDs ready for reading |
365 | * @param ws set of FDs ready for writing | 365 | * @param ws set of FDs ready for writing |
366 | * @return GNUNET_YES if we can run it, GNUNET_NO if not. | 366 | * @return #GNUNET_YES if we can run it, #GNUNET_NO if not. |
367 | */ | 367 | */ |
368 | static int | 368 | static int |
369 | is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, | 369 | is_ready (struct Task *task, struct GNUNET_TIME_Absolute now, |
@@ -630,6 +630,26 @@ sighandler_pipe () | |||
630 | return; | 630 | return; |
631 | } | 631 | } |
632 | #endif | 632 | #endif |
633 | |||
634 | |||
635 | /** | ||
636 | * Wait for a short time. | ||
637 | * Sleeps for @a ms ms (as that should be long enough for virtually all | ||
638 | * modern systems to context switch and allow another process to do | ||
639 | * some 'real' work). | ||
640 | * | ||
641 | * @param ms how many ms to wait | ||
642 | */ | ||
643 | static void | ||
644 | short_wait (unsigned int ms) | ||
645 | { | ||
646 | struct GNUNET_TIME_Relative timeout; | ||
647 | |||
648 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, ms); | ||
649 | (void) GNUNET_NETWORK_socket_select (NULL, NULL, NULL, timeout); | ||
650 | } | ||
651 | |||
652 | |||
633 | /** | 653 | /** |
634 | * Signal handler called for signals that should cause us to shutdown. | 654 | * Signal handler called for signals that should cause us to shutdown. |
635 | */ | 655 | */ |
@@ -653,8 +673,8 @@ sighandler_shutdown () | |||
653 | * Check if the system is still life. Trigger shutdown if we | 673 | * Check if the system is still life. Trigger shutdown if we |
654 | * have tasks, but none of them give us lifeness. | 674 | * have tasks, but none of them give us lifeness. |
655 | * | 675 | * |
656 | * @return GNUNET_OK to continue the main loop, | 676 | * @return #GNUNET_OK to continue the main loop, |
657 | * GNUNET_NO to exit | 677 | * #GNUNET_NO to exit |
658 | */ | 678 | */ |
659 | static int | 679 | static int |
660 | check_lifeness () | 680 | check_lifeness () |
@@ -780,7 +800,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
780 | if ((0 == ret) && (0 == timeout.rel_value_us) && (busy_wait_warning > 16)) | 800 | if ((0 == ret) && (0 == timeout.rel_value_us) && (busy_wait_warning > 16)) |
781 | { | 801 | { |
782 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n")); | 802 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n")); |
783 | sleep (1); /* mitigate */ | 803 | short_wait (100); /* mitigate */ |
784 | } | 804 | } |
785 | check_ready (rs, ws); | 805 | check_ready (rs, ws); |
786 | run_ready (rs, ws); | 806 | run_ready (rs, ws); |
@@ -793,6 +813,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
793 | } | 813 | } |
794 | if (last_tr == tasks_run) | 814 | if (last_tr == tasks_run) |
795 | { | 815 | { |
816 | short_wait (1); | ||
796 | busy_wait_warning++; | 817 | busy_wait_warning++; |
797 | } | 818 | } |
798 | else | 819 | else |