gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29165 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r29165 - gnunet/src/util
Date: Tue, 10 Sep 2013 16:33:57 +0200

Author: grothoff
Date: 2013-09-10 16:33:57 +0200 (Tue, 10 Sep 2013)
New Revision: 29165

Modified:
   gnunet/src/util/scheduler.c
Log:
-perform tiny wait if we do get worken up to do no work

Modified: gnunet/src/util/scheduler.c
===================================================================
--- gnunet/src/util/scheduler.c 2013-09-10 13:04:46 UTC (rev 29164)
+++ gnunet/src/util/scheduler.c 2013-09-10 14:33:57 UTC (rev 29165)
@@ -239,7 +239,7 @@
 
 /**
  * Function to use as a select() in the scheduler.
- * If NULL, we use GNUNET_NETWORK_socket_select ().
+ * If NULL, we use GNUNET_NETWORK_socket_select().
  */
 static GNUNET_SCHEDULER_select scheduler_select;
 
@@ -252,7 +252,7 @@
  * Sets the select function to use in the scheduler (scheduler_select).
  *
  * @param new_select new select function to use
- * @param new_select_cls closure for 'new_select'
+ * @param new_select_cls closure for @a new_select
  * @return previously used select function, NULL for default
  */
 void
@@ -363,7 +363,7 @@
  * @param now the current time
  * @param rs set of FDs ready for reading
  * @param ws set of FDs ready for writing
- * @return GNUNET_YES if we can run it, GNUNET_NO if not.
+ * @return #GNUNET_YES if we can run it, #GNUNET_NO if not.
  */
 static int
 is_ready (struct Task *task, struct GNUNET_TIME_Absolute now,
@@ -630,7 +630,27 @@
   return;
 }
 #endif
+
+
 /**
+ * Wait for a short time.
+ * Sleeps for @a ms ms (as that should be long enough for virtually all
+ * modern systems to context switch and allow another process to do
+ * some 'real' work).
+ *
+ * @param ms how many ms to wait
+ */
+static void
+short_wait (unsigned int ms)
+{
+  struct GNUNET_TIME_Relative timeout;
+
+  timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, ms);
+  (void) GNUNET_NETWORK_socket_select (NULL, NULL, NULL, timeout);
+}
+
+
+/**
  * Signal handler called for signals that should cause us to shutdown.
  */
 static void
@@ -653,8 +673,8 @@
  * Check if the system is still life. Trigger shutdown if we
  * have tasks, but none of them give us lifeness.
  *
- * @return GNUNET_OK to continue the main loop,
- *         GNUNET_NO to exit
+ * @return #GNUNET_OK to continue the main loop,
+ *         #GNUNET_NO to exit
  */
 static int
 check_lifeness ()
@@ -780,7 +800,7 @@
     if ((0 == ret) && (0 == timeout.rel_value_us) && (busy_wait_warning > 16))
     {
       LOG (GNUNET_ERROR_TYPE_WARNING, _("Looks like we're busy waiting...\n"));
-      sleep (1);                /* mitigate */
+      short_wait (100);                /* mitigate */
     }
     check_ready (rs, ws);
     run_ready (rs, ws);
@@ -793,6 +813,7 @@
     }
     if (last_tr == tasks_run)
     {
+      short_wait (1);
       busy_wait_warning++;
     }
     else




reply via email to

[Prev in Thread] Current Thread [Next in Thread]