aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2017-09-04 15:05:26 +0200
committerlurchi <lurchi@strangeplace.net>2017-09-04 15:05:26 +0200
commit490c41e78c79a18ab683f83299b041564cb4a69b (patch)
tree62023b844146738bdb4bc9eea7b0b88a3c890c58 /src
parent0cdad12df4123d4b30603d552f1e3c1effab5015 (diff)
downloadgnunet-490c41e78c79a18ab683f83299b041564cb4a69b.tar.gz
gnunet-490c41e78c79a18ab683f83299b041564cb4a69b.zip
Fix select loop running conditions
The select loop has to keep running as long as the driver has tasks available (indicating that there are file descriptors left to wait for) or the timeout is not FOREVER (indicating that the scheduler has tasks with timeout left).
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_scheduler_lib.h12
-rw-r--r--src/util/scheduler.c6
2 files changed, 13 insertions, 5 deletions
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index b6f127f0c..aded41de8 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -242,15 +242,16 @@ struct GNUNET_SCHEDULER_Handle;
242 * there are tasks left to run just to give other tasks a chance as 242 * there are tasks left to run just to give other tasks a chance as
243 * well. If we return #GNUNET_YES, the driver should call this 243 * well. If we return #GNUNET_YES, the driver should call this
244 * function again as soon as possible, while if we return #GNUNET_NO 244 * function again as soon as possible, while if we return #GNUNET_NO
245 * it must block until the operating system has more work as the 245 * it must block until either the operating system has more work (the
246 * scheduler has no more work to do right now. 246 * scheduler has no more work to do right now) or the timeout set by
247 * the scheduler (using the set_wakeup callback) is reached.
247 * 248 *
248 * @param sh scheduler handle that was given to the `loop` 249 * @param sh scheduler handle that was given to the `loop`
249 * @return #GNUNET_OK if there are more tasks that are ready, 250 * @return #GNUNET_OK if there are more tasks that are ready,
250 * and thus we would like to run more (yield to avoid 251 * and thus we would like to run more (yield to avoid
251 * blocking other activities for too long) 252 * blocking other activities for too long)
252 * #GNUNET_NO if we are done running tasks (yield to block) 253 * #GNUNET_NO if we are done running tasks (yield to block)
253 * #GNUNET_SYSERR on error 254 * #GNUNET_SYSERR on error, e.g. no tasks were ready
254 */ 255 */
255int 256int
256GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh); 257GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh);
@@ -313,7 +314,10 @@ struct GNUNET_SCHEDULER_Driver
313 /** 314 /**
314 * Event loop's "main" function, to be called from 315 * Event loop's "main" function, to be called from
315 * #GNUNET_SCHEDULER_run_with_driver() to actually 316 * #GNUNET_SCHEDULER_run_with_driver() to actually
316 * launch the loop. 317 * launch the loop. The loop should run as long as
318 * tasks (added by the add callback) are available
319 * OR the wakeup time (added by the set_wakeup
320 * callback) is not FOREVER.
317 * 321 *
318 * @param cls closure 322 * @param cls closure
319 * @param sh scheduler handle to pass to 323 * @param sh scheduler handle to pass to
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 72f2b7230..4b963209d 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -2209,7 +2209,8 @@ select_loop (void *cls,
2209 rs = GNUNET_NETWORK_fdset_create (); 2209 rs = GNUNET_NETWORK_fdset_create ();
2210 ws = GNUNET_NETWORK_fdset_create (); 2210 ws = GNUNET_NETWORK_fdset_create ();
2211 tasks_ready = GNUNET_NO; 2211 tasks_ready = GNUNET_NO;
2212 while (NULL != context->scheduled_head || GNUNET_YES == tasks_ready) 2212 while (NULL != context->scheduled_head ||
2213 GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != context->timeout.rel_value_us)
2213 { 2214 {
2214 LOG (GNUNET_ERROR_TYPE_DEBUG, 2215 LOG (GNUNET_ERROR_TYPE_DEBUG,
2215 "select timeout = %s\n", 2216 "select timeout = %s\n",
@@ -2300,6 +2301,9 @@ select_loop (void *cls,
2300 } 2301 }
2301 tasks_ready = GNUNET_SCHEDULER_run_from_driver (sh); 2302 tasks_ready = GNUNET_SCHEDULER_run_from_driver (sh);
2302 GNUNET_assert (GNUNET_SYSERR != tasks_ready); 2303 GNUNET_assert (GNUNET_SYSERR != tasks_ready);
2304 LOG (GNUNET_ERROR_TYPE_WARNING,
2305 "select timeout = %s\n",
2306 GNUNET_STRINGS_relative_time_to_string (context->timeout, GNUNET_NO));
2303 } 2307 }
2304 return GNUNET_OK; 2308 return GNUNET_OK;
2305} 2309}