aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_scheduler_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_scheduler_lib.h')
-rw-r--r--src/include/gnunet_scheduler_lib.h229
1 files changed, 102 insertions, 127 deletions
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index 621e57fcf..760a674d5 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -197,21 +197,30 @@ typedef void (*GNUNET_SCHEDULER_Task) (void *cls,
197 197
198 198
199/** 199/**
200 * Initialize and run scheduler. This function will return when 200 * Initialize and run scheduler. This function will return when all
201 * either a shutdown was initiated (via signal) and all tasks marked 201 * tasks have completed. On systems with signals, receiving a SIGTERM
202 * to "run_on_shutdown" have been completed or when all tasks in 202 * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown"
203 * general have been completed. 203 * to be run after the active task is complete. As a result, SIGTERM
204 * causes all active tasks to be scheduled with reason
205 * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added
206 * afterwards will execute normally!). Note that any particular
207 * signal will only shut down one scheduler; applications should
208 * always only create a single scheduler.
204 * 209 *
205 * @param task task to run immediately 210 * @param task task to run first (and immediately)
206 * @param cls closure of task 211 * @param task_cls closure of task
207 */ 212 */
208void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls); 213void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls);
209 214
210 215
211/** 216/**
212 * Request the shutdown of a scheduler. This function can be used to 217 * Request the shutdown of a scheduler. Marks all currently
213 * stop a scheduler, for example from within the signal 218 * pending tasks as ready because of shutdown. This will
214 * handler for signals causing shutdowns. 219 * cause all tasks to run (as soon as possible, respecting
220 * priorities and prerequisite tasks). Note that tasks
221 * scheduled AFTER this call may still be delayed arbitrarily.
222 *
223 * @param sched the scheduler
215 */ 224 */
216void GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched); 225void GNUNET_SCHEDULER_shutdown (struct GNUNET_SCHEDULER_Handle *sched);
217 226
@@ -256,68 +265,70 @@ void *GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched,
256 */ 265 */
257void 266void
258GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched, 267GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched,
259 int run_on_shutdown,
260 GNUNET_SCHEDULER_Task main, 268 GNUNET_SCHEDULER_Task main,
261 void *cls, 269 void *cls,
262 enum GNUNET_SCHEDULER_Reason reason); 270 enum GNUNET_SCHEDULER_Reason reason);
263 271
264 272
265/** 273/**
266 * Schedule a new task to be run after the specified 274 * Schedule a new task to be run after the specified prerequisite task
267 * prerequisite task has completed. 275 * has completed. It will be run with the priority of the calling
276 * task.
268 * 277 *
269 * @param sched scheduler to use 278 * @param sched scheduler to use
270 * @param run_on_shutdown run on shutdown?
271 * @param prio how important is this task?
272 * @param prerequisite_task run this task after the task with the given 279 * @param prerequisite_task run this task after the task with the given
273 * task identifier completes (and any of our other 280 * task identifier completes (and any of our other
274 * conditions, such as delay, read or write-readyness 281 * conditions, such as delay, read or write-readyness
275 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency 282 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
276 * on completion of other tasks. 283 * on completion of other tasks (this will cause the task to run as
277 * @param main main function of the task 284 * soon as possible).
278 * @param cls closure of task 285 * @param task main function of the task
286 * @param task_cls closure of task
279 * @return unique task identifier for the job 287 * @return unique task identifier for the job
280 * only valid until "main" is started! 288 * only valid until "task" is started!
281 */ 289 */
282GNUNET_SCHEDULER_TaskIdentifier 290GNUNET_SCHEDULER_TaskIdentifier
283GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched, 291GNUNET_SCHEDULER_add_after (struct GNUNET_SCHEDULER_Handle *sched,
284 int run_on_shutdown,
285 enum GNUNET_SCHEDULER_Priority prio,
286 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 292 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
287 GNUNET_SCHEDULER_Task main, void *cls); 293 GNUNET_SCHEDULER_Task task,
294 void *task_cls);
295
296
297/**
298 * Schedule a new task to be run with a specified priority.
299 *
300 * @param sched scheduler to use
301 * @param prio how important is the new task?
302 * @param task main function of the task
303 * @param task_cls closure of task
304 * @return unique task identifier for the job
305 * only valid until "task" is started!
306 */
307GNUNET_SCHEDULER_TaskIdentifier
308GNUNET_SCHEDULER_add_with_priority (struct GNUNET_SCHEDULER_Handle *sched,
309 enum GNUNET_SCHEDULER_Priority prio,
310 GNUNET_SCHEDULER_Task task,
311 void *task_cls);
288 312
289 313
290/** 314/**
291 * Schedule a new task to be run with a specified delay. The task 315 * Schedule a new task to be run with a specified delay. The task
292 * will be scheduled for execution once the delay has expired and the 316 * will be scheduled for execution once the delay has expired. It
293 * prerequisite task has completed. 317 * will be run with the priority of the calling task.
294 * 318 *
295 * @param sched scheduler to use 319 * @param sched scheduler to use
296 * @param run_on_shutdown run on shutdown? You can use this 320 * @param delay when should this operation time out? Use
297 * argument to run a function only during shutdown 321 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
298 * by setting delay to -1. Set this 322 * @param task main function of the task
299 * argument to GNUNET_NO to skip this task if 323 * @param task_cls closure of task
300 * the user requested process termination.
301 * @param prio how important is this task?
302 * @param prerequisite_task run this task after the task with the given
303 * task identifier completes (and any of our other
304 * conditions, such as delay, read or write-readyness
305 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
306 * on completion of other tasks.
307 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
308 * @param main main function of the task
309 * @param cls closure of task
310 * @return unique task identifier for the job 324 * @return unique task identifier for the job
311 * only valid until "main" is started! 325 * only valid until "task" is started!
312 */ 326 */
313GNUNET_SCHEDULER_TaskIdentifier 327GNUNET_SCHEDULER_TaskIdentifier
314GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched, 328GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched,
315 int run_on_shutdown,
316 enum GNUNET_SCHEDULER_Priority prio,
317 GNUNET_SCHEDULER_TaskIdentifier
318 prerequisite_task,
319 struct GNUNET_TIME_Relative delay, 329 struct GNUNET_TIME_Relative delay,
320 GNUNET_SCHEDULER_Task main, void *cls); 330 GNUNET_SCHEDULER_Task task,
331 void *task_cls);
321 332
322 333
323/** 334/**
@@ -325,32 +336,24 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched,
325 * specified file descriptor is ready for reading. The delay can be 336 * specified file descriptor is ready for reading. The delay can be
326 * used as a timeout on the socket being ready. The task will be 337 * used as a timeout on the socket being ready. The task will be
327 * scheduled for execution once either the delay has expired or the 338 * scheduled for execution once either the delay has expired or the
328 * socket operation is ready. 339 * socket operation is ready. It will be run with the priority of
340 * the calling task.
329 * 341 *
330 * @param sched scheduler to use 342 * @param sched scheduler to use
331 * @param run_on_shutdown run on shutdown? Set this 343 * @param delay when should this operation time out? Use
332 * argument to GNUNET_NO to skip this task if 344 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
333 * the user requested process termination.
334 * @param prio how important is this task?
335 * @param prerequisite_task run this task after the task with the given
336 * task identifier completes (and any of our other
337 * conditions, such as delay, read or write-readyness
338 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
339 * on completion of other tasks.
340 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
341 * @param rfd read file-descriptor 345 * @param rfd read file-descriptor
342 * @param main main function of the task 346 * @param task main function of the task
343 * @param cls closure of task 347 * @param task_cls closure of task
344 * @return unique task identifier for the job 348 * @return unique task identifier for the job
345 * only valid until "main" is started! 349 * only valid until "task" is started!
346 */ 350 */
347GNUNET_SCHEDULER_TaskIdentifier 351GNUNET_SCHEDULER_TaskIdentifier
348GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched, 352GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched,
349 int run_on_shutdown, 353 struct GNUNET_TIME_Relative delay,
350 enum GNUNET_SCHEDULER_Priority prio, 354 struct GNUNET_NETWORK_Handle *rfd,
351 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 355 GNUNET_SCHEDULER_Task task,
352 struct GNUNET_TIME_Relative delay, 356 void *task_cls);
353 struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_Task main, void *cls);
354 357
355 358
356/** 359/**
@@ -358,32 +361,24 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched,
358 * specified file descriptor is ready for writing. The delay can be 361 * specified file descriptor is ready for writing. The delay can be
359 * used as a timeout on the socket being ready. The task will be 362 * used as a timeout on the socket being ready. The task will be
360 * scheduled for execution once either the delay has expired or the 363 * scheduled for execution once either the delay has expired or the
361 * socket operation is ready. 364 * socket operation is ready. It will be run with the priority of
365 * the calling task.
362 * 366 *
363 * @param sched scheduler to use 367 * @param sched scheduler to use
364 * @param run_on_shutdown run on shutdown? Set this 368 * @param delay when should this operation time out? Use
365 * argument to GNUNET_NO to skip this task if 369 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
366 * the user requested process termination.
367 * @param prio how important is this task?
368 * @param prerequisite_task run this task after the task with the given
369 * task identifier completes (and any of our other
370 * conditions, such as delay, read or write-readyness
371 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
372 * on completion of other tasks.
373 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
374 * @param wfd write file-descriptor 370 * @param wfd write file-descriptor
375 * @param main main function of the task 371 * @param task main function of the task
376 * @param cls closure of task 372 * @param task_cls closure of task
377 * @return unique task identifier for the job 373 * @return unique task identifier for the job
378 * only valid until "main" is started! 374 * only valid until "task" is started!
379 */ 375 */
380GNUNET_SCHEDULER_TaskIdentifier 376GNUNET_SCHEDULER_TaskIdentifier
381GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched, 377GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched,
382 int run_on_shutdown, 378 struct GNUNET_TIME_Relative delay,
383 enum GNUNET_SCHEDULER_Priority prio, 379 struct GNUNET_NETWORK_Handle *wfd,
384 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 380 GNUNET_SCHEDULER_Task task,
385 struct GNUNET_TIME_Relative delay, 381 void *task_cls);
386 struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_Task main, void *cls);
387 382
388 383
389/** 384/**
@@ -391,33 +386,24 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched,
391 * specified file descriptor is ready for reading. The delay can be 386 * specified file descriptor is ready for reading. The delay can be
392 * used as a timeout on the socket being ready. The task will be 387 * used as a timeout on the socket being ready. The task will be
393 * scheduled for execution once either the delay has expired or the 388 * scheduled for execution once either the delay has expired or the
394 * socket operation is ready. 389 * socket operation is ready. It will be run with the priority of
390 * the calling task.
395 * 391 *
396 * @param sched scheduler to use 392 * @param sched scheduler to use
397 * @param run_on_shutdown run on shutdown? Set this 393 * @param delay when should this operation time out? Use
398 * argument to GNUNET_NO to skip this task if 394 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
399 * the user requested process termination.
400 * @param prio how important is this task?
401 * @param prerequisite_task run this task after the task with the given
402 * task identifier completes (and any of our other
403 * conditions, such as delay, read or write-readyness
404 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
405 * on completion of other tasks.
406 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
407 * @param rfd read file-descriptor 395 * @param rfd read file-descriptor
408 * @param main main function of the task 396 * @param task main function of the task
409 * @param cls closure of task 397 * @param task_cls closure of task
410 * @return unique task identifier for the job 398 * @return unique task identifier for the job
411 * only valid until "main" is started! 399 * only valid until "task" is started!
412 */ 400 */
413GNUNET_SCHEDULER_TaskIdentifier 401GNUNET_SCHEDULER_TaskIdentifier
414GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched, 402GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched,
415 int run_on_shutdown,
416 enum GNUNET_SCHEDULER_Priority prio,
417 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
418 struct GNUNET_TIME_Relative delay, 403 struct GNUNET_TIME_Relative delay,
419 const struct GNUNET_DISK_FileHandle *rfd, 404 const struct GNUNET_DISK_FileHandle *rfd,
420 GNUNET_SCHEDULER_Task main, void *cls); 405 GNUNET_SCHEDULER_Task task,
406 void *task_cls);
421 407
422 408
423/** 409/**
@@ -425,33 +411,24 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched,
425 * specified file descriptor is ready for writing. The delay can be 411 * specified file descriptor is ready for writing. The delay can be
426 * used as a timeout on the socket being ready. The task will be 412 * used as a timeout on the socket being ready. The task will be
427 * scheduled for execution once either the delay has expired or the 413 * scheduled for execution once either the delay has expired or the
428 * socket operation is ready. 414 * socket operation is ready. It will be run with the priority of
415 * the calling task.
429 * 416 *
430 * @param sched scheduler to use 417 * @param sched scheduler to use
431 * @param run_on_shutdown run on shutdown? Set this 418 * @param delay when should this operation time out? Use
432 * argument to GNUNET_NO to skip this task if 419 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
433 * the user requested process termination.
434 * @param prio how important is this task?
435 * @param prerequisite_task run this task after the task with the given
436 * task identifier completes (and any of our other
437 * conditions, such as delay, read or write-readyness
438 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
439 * on completion of other tasks.
440 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
441 * @param wfd write file-descriptor 420 * @param wfd write file-descriptor
442 * @param main main function of the task 421 * @param task main function of the task
443 * @param cls closure of task 422 * @param task_cls closure of task
444 * @return unique task identifier for the job 423 * @return unique task identifier for the job
445 * only valid until "main" is started! 424 * only valid until "task" is started!
446 */ 425 */
447GNUNET_SCHEDULER_TaskIdentifier 426GNUNET_SCHEDULER_TaskIdentifier
448GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched, 427GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched,
449 int run_on_shutdown,
450 enum GNUNET_SCHEDULER_Priority prio,
451 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
452 struct GNUNET_TIME_Relative delay, 428 struct GNUNET_TIME_Relative delay,
453 const struct GNUNET_DISK_FileHandle *wfd, 429 const struct GNUNET_DISK_FileHandle *wfd,
454 GNUNET_SCHEDULER_Task main, void *cls); 430 GNUNET_SCHEDULER_Task task,
431 void *task_cls);
455 432
456 433
457/** 434/**
@@ -472,33 +449,31 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched,
472 * </code> 449 * </code>
473 * 450 *
474 * @param sched scheduler to use 451 * @param sched scheduler to use
475 * @param run_on_shutdown run on shutdown? Set this
476 * argument to GNUNET_NO to skip this task if
477 * the user requested process termination.
478 * @param prio how important is this task? 452 * @param prio how important is this task?
479 * @param prerequisite_task run this task after the task with the given 453 * @param prerequisite_task run this task after the task with the given
480 * task identifier completes (and any of our other 454 * task identifier completes (and any of our other
481 * conditions, such as delay, read or write-readyness 455 * conditions, such as delay, read or write-readyness
482 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency 456 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
483 * on completion of other tasks. 457 * on completion of other tasks.
484 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever" 458 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever",
459 * which means that the task will only be run after we receive SIGTERM
485 * @param rs set of file descriptors we want to read (can be NULL) 460 * @param rs set of file descriptors we want to read (can be NULL)
486 * @param ws set of file descriptors we want to write (can be NULL) 461 * @param ws set of file descriptors we want to write (can be NULL)
487 * @param main main function of the task 462 * @param task main function of the task
488 * @param cls closure of task 463 * @param task_cls closure of task
489 * @return unique task identifier for the job 464 * @return unique task identifier for the job
490 * only valid until "main" is started! 465 * only valid until "task" is started!
491 */ 466 */
492GNUNET_SCHEDULER_TaskIdentifier 467GNUNET_SCHEDULER_TaskIdentifier
493GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched, 468GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched,
494 int run_on_shutdown,
495 enum GNUNET_SCHEDULER_Priority prio, 469 enum GNUNET_SCHEDULER_Priority prio,
496 GNUNET_SCHEDULER_TaskIdentifier 470 GNUNET_SCHEDULER_TaskIdentifier
497 prerequisite_task, 471 prerequisite_task,
498 struct GNUNET_TIME_Relative delay, 472 struct GNUNET_TIME_Relative delay,
499 const struct GNUNET_NETWORK_FDSet * rs, 473 const struct GNUNET_NETWORK_FDSet * rs,
500 const struct GNUNET_NETWORK_FDSet * ws, 474 const struct GNUNET_NETWORK_FDSet * ws,
501 GNUNET_SCHEDULER_Task main, void *cls); 475 GNUNET_SCHEDULER_Task task,
476 void *task_cls);
502 477
503#if 0 /* keep Emacsens' auto-indent happy */ 478#if 0 /* keep Emacsens' auto-indent happy */
504{ 479{