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.h121
1 files changed, 68 insertions, 53 deletions
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index ec605a3fd..4ee21e193 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -40,14 +40,7 @@ extern "C"
40/** 40/**
41 * Opaque reference to a task. 41 * Opaque reference to a task.
42 */ 42 */
43typedef unsigned long long GNUNET_SCHEDULER_TaskIdentifier; 43struct GNUNET_SCHEDULER_Task;
44
45
46/**
47 * Constant used to indicate that the scheduled
48 * task has no others as prerequisites.
49 */
50#define GNUNET_SCHEDULER_NO_TASK ((GNUNET_SCHEDULER_TaskIdentifier) 0)
51 44
52/** 45/**
53 * Reasons why the schedule may have triggered 46 * Reasons why the schedule may have triggered
@@ -56,36 +49,41 @@ typedef unsigned long long GNUNET_SCHEDULER_TaskIdentifier;
56enum GNUNET_SCHEDULER_Reason 49enum GNUNET_SCHEDULER_Reason
57{ 50{
58 /** 51 /**
52 * This task is not ready.
53 */
54 GNUNET_SCHEDULER_REASON_NONE = 0,
55
56 /**
59 * This is the very first task run during startup. 57 * This is the very first task run during startup.
60 */ 58 */
61 GNUNET_SCHEDULER_REASON_STARTUP = 0, 59 GNUNET_SCHEDULER_REASON_STARTUP = 1,
62 60
63 /** 61 /**
64 * We are shutting down and are running all shutdown-related tasks 62 * We are shutting down and are running all shutdown-related tasks
65 * (regardless of timeout, etc.). 63 * (regardless of timeout, etc.).
66 */ 64 */
67 GNUNET_SCHEDULER_REASON_SHUTDOWN = 1, 65 GNUNET_SCHEDULER_REASON_SHUTDOWN = 2,
68 66
69 /** 67 /**
70 * The specified timeout has expired. 68 * The specified timeout has expired.
71 * (also set if the delay given was 0). 69 * (also set if the delay given was 0).
72 */ 70 */
73 GNUNET_SCHEDULER_REASON_TIMEOUT = 2, 71 GNUNET_SCHEDULER_REASON_TIMEOUT = 4,
74 72
75 /** 73 /**
76 * The reading socket is ready. 74 * The reading socket is ready.
77 */ 75 */
78 GNUNET_SCHEDULER_REASON_READ_READY = 4, 76 GNUNET_SCHEDULER_REASON_READ_READY = 8,
79 77
80 /** 78 /**
81 * The writing socket is ready. 79 * The writing socket is ready.
82 */ 80 */
83 GNUNET_SCHEDULER_REASON_WRITE_READY = 8, 81 GNUNET_SCHEDULER_REASON_WRITE_READY = 16,
84 82
85 /** 83 /**
86 * The prerequisite task is done. 84 * The prerequisite task is done.
87 */ 85 */
88 GNUNET_SCHEDULER_REASON_PREREQ_DONE = 16 86 GNUNET_SCHEDULER_REASON_PREREQ_DONE = 32
89}; 87};
90 88
91 89
@@ -193,9 +191,9 @@ struct GNUNET_SCHEDULER_TaskContext
193 * @param cls closure 191 * @param cls closure
194 * @param tc context information (why was this task triggered now) 192 * @param tc context information (why was this task triggered now)
195 */ 193 */
196typedef void (*GNUNET_SCHEDULER_Task) (void *cls, 194typedef void
197 const struct GNUNET_SCHEDULER_TaskContext 195(*GNUNET_SCHEDULER_TaskCallback) (void *cls,
198 * tc); 196 const struct GNUNET_SCHEDULER_TaskContext *tc);
199 197
200 198
201/** 199/**
@@ -209,11 +207,12 @@ typedef void (*GNUNET_SCHEDULER_Task) (void *cls,
209 * @param timeout relative value when to return 207 * @param timeout relative value when to return
210 * @return number of selected sockets, #GNUNET_SYSERR on error 208 * @return number of selected sockets, #GNUNET_SYSERR on error
211 */ 209 */
212typedef int (*GNUNET_SCHEDULER_select) (void *cls, 210typedef int
213 struct GNUNET_NETWORK_FDSet *rfds, 211(*GNUNET_SCHEDULER_select) (void *cls,
214 struct GNUNET_NETWORK_FDSet *wfds, 212 struct GNUNET_NETWORK_FDSet *rfds,
215 struct GNUNET_NETWORK_FDSet *efds, 213 struct GNUNET_NETWORK_FDSet *wfds,
216 struct GNUNET_TIME_Relative timeout); 214 struct GNUNET_NETWORK_FDSet *efds,
215 struct GNUNET_TIME_Relative timeout);
217 216
218 217
219/** 218/**
@@ -231,7 +230,8 @@ typedef int (*GNUNET_SCHEDULER_select) (void *cls,
231 * @param task_cls closure of task 230 * @param task_cls closure of task
232 */ 231 */
233void 232void
234GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls); 233GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
234 void *task_cls);
235 235
236 236
237/** 237/**
@@ -279,7 +279,7 @@ GNUNET_SCHEDULER_get_reason (void);
279 * @return the closure of the callback of the cancelled task 279 * @return the closure of the callback of the cancelled task
280 */ 280 */
281void * 281void *
282GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task); 282GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task);
283 283
284 284
285/** 285/**
@@ -292,7 +292,8 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task);
292 * @param reason reason for task invocation 292 * @param reason reason for task invocation
293 */ 293 */
294void 294void
295GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, 295GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_TaskCallback task,
296 void *task_cls,
296 enum GNUNET_SCHEDULER_Reason reason); 297 enum GNUNET_SCHEDULER_Reason reason);
297 298
298 299
@@ -307,7 +308,8 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
307 * @param priority priority to use for the task 308 * @param priority priority to use for the task
308 */ 309 */
309void 310void
310GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, void *task_cls, 311GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_TaskCallback task,
312 void *task_cls,
311 enum GNUNET_SCHEDULER_Reason reason, 313 enum GNUNET_SCHEDULER_Reason reason,
312 enum GNUNET_SCHEDULER_Priority priority); 314 enum GNUNET_SCHEDULER_Priority priority);
313 315
@@ -321,9 +323,10 @@ GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, voi
321 * @return unique task identifier for the job 323 * @return unique task identifier for the job
322 * only valid until @a task is started! 324 * only valid until @a task is started!
323 */ 325 */
324GNUNET_SCHEDULER_TaskIdentifier 326struct GNUNET_SCHEDULER_Task *
325GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, 327GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
326 GNUNET_SCHEDULER_Task task, void *task_cls); 328 GNUNET_SCHEDULER_TaskCallback task,
329 void *task_cls);
327 330
328 331
329/** 332/**
@@ -341,8 +344,9 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
341 * @return unique task identifier for the job 344 * @return unique task identifier for the job
342 * only valid until @a task is started! 345 * only valid until @a task is started!
343 */ 346 */
344GNUNET_SCHEDULER_TaskIdentifier 347struct GNUNET_SCHEDULER_Task *
345GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls); 348GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
349 void *task_cls);
346 350
347 351
348/** 352/**
@@ -359,9 +363,9 @@ GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls);
359 * @return unique task identifier for the job 363 * @return unique task identifier for the job
360 * only valid until @a task is started! 364 * only valid until @a task is started!
361 */ 365 */
362GNUNET_SCHEDULER_TaskIdentifier 366struct GNUNET_SCHEDULER_Task *
363GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, 367GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
364 GNUNET_SCHEDULER_Task task, 368 GNUNET_SCHEDULER_TaskCallback task,
365 void *task_cls); 369 void *task_cls);
366 370
367 371
@@ -377,9 +381,10 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
377 * @return unique task identifier for the job 381 * @return unique task identifier for the job
378 * only valid until @a task is started! 382 * only valid until @a task is started!
379 */ 383 */
380GNUNET_SCHEDULER_TaskIdentifier 384struct GNUNET_SCHEDULER_Task *
381GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, 385GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
382 GNUNET_SCHEDULER_Task task, void *task_cls); 386 GNUNET_SCHEDULER_TaskCallback task,
387 void *task_cls);
383 388
384 389
385/** 390/**
@@ -394,10 +399,11 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
394 * @return unique task identifier for the job 399 * @return unique task identifier for the job
395 * only valid until @a task is started! 400 * only valid until @a task is started!
396 */ 401 */
397GNUNET_SCHEDULER_TaskIdentifier 402struct GNUNET_SCHEDULER_Task *
398GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, 403GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
399 enum GNUNET_SCHEDULER_Priority priority, 404 enum GNUNET_SCHEDULER_Priority priority,
400 GNUNET_SCHEDULER_Task task, void *task_cls); 405 GNUNET_SCHEDULER_TaskCallback task,
406 void *task_cls);
401 407
402 408
403/** 409/**
@@ -415,10 +421,11 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
415 * @return unique task identifier for the job 421 * @return unique task identifier for the job
416 * only valid until @a task is started! 422 * only valid until @a task is started!
417 */ 423 */
418GNUNET_SCHEDULER_TaskIdentifier 424struct GNUNET_SCHEDULER_Task *
419GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, 425GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
420 struct GNUNET_NETWORK_Handle *rfd, 426 struct GNUNET_NETWORK_Handle *rfd,
421 GNUNET_SCHEDULER_Task task, void *task_cls); 427 GNUNET_SCHEDULER_TaskCallback task,
428 void *task_cls);
422 429
423 430
424/** 431/**
@@ -438,11 +445,12 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
438 * @return unique task identifier for the job 445 * @return unique task identifier for the job
439 * only valid until @a task is started! 446 * only valid until @a task is started!
440 */ 447 */
441GNUNET_SCHEDULER_TaskIdentifier 448struct GNUNET_SCHEDULER_Task *
442GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay, 449GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
443 enum GNUNET_SCHEDULER_Priority priority, 450 enum GNUNET_SCHEDULER_Priority priority,
444 struct GNUNET_NETWORK_Handle *rfd, 451 struct GNUNET_NETWORK_Handle *rfd,
445 GNUNET_SCHEDULER_Task task, void *task_cls); 452 GNUNET_SCHEDULER_TaskCallback task,
453 void *task_cls);
446 454
447 455
448/** 456/**
@@ -460,10 +468,11 @@ GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
460 * @return unique task identifier for the job 468 * @return unique task identifier for the job
461 * only valid until @a task is started! 469 * only valid until @a task is started!
462 */ 470 */
463GNUNET_SCHEDULER_TaskIdentifier 471struct GNUNET_SCHEDULER_Task *
464GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, 472GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
465 struct GNUNET_NETWORK_Handle *wfd, 473 struct GNUNET_NETWORK_Handle *wfd,
466 GNUNET_SCHEDULER_Task task, void *task_cls); 474 GNUNET_SCHEDULER_TaskCallback task,
475 void *task_cls);
467 476
468 477
469/** 478/**
@@ -484,12 +493,14 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
484 * @return unique task identifier for the job 493 * @return unique task identifier for the job
485 * only valid until "task" is started! 494 * only valid until "task" is started!
486 */ 495 */
487GNUNET_SCHEDULER_TaskIdentifier 496struct GNUNET_SCHEDULER_Task *
488GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay, 497GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
489 enum GNUNET_SCHEDULER_Priority priority, 498 enum GNUNET_SCHEDULER_Priority priority,
490 struct GNUNET_NETWORK_Handle *fd, 499 struct GNUNET_NETWORK_Handle *fd,
491 int on_read, int on_write, 500 int on_read,
492 GNUNET_SCHEDULER_Task task, void *task_cls); 501 int on_write,
502 GNUNET_SCHEDULER_TaskCallback task,
503 void *task_cls);
493 504
494/** 505/**
495 * Schedule a new task to be run with a specified delay or when the 506 * Schedule a new task to be run with a specified delay or when the
@@ -506,10 +517,11 @@ GNUNET_SCHEDULER_add_net_with_priority (struct GNUNET_TIME_Relative delay,
506 * @return unique task identifier for the job 517 * @return unique task identifier for the job
507 * only valid until "task" is started! 518 * only valid until "task" is started!
508 */ 519 */
509GNUNET_SCHEDULER_TaskIdentifier 520struct GNUNET_SCHEDULER_Task *
510GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, 521GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
511 const struct GNUNET_DISK_FileHandle *rfd, 522 const struct GNUNET_DISK_FileHandle *rfd,
512 GNUNET_SCHEDULER_Task task, void *task_cls); 523 GNUNET_SCHEDULER_TaskCallback task,
524 void *task_cls);
513 525
514 526
515/** 527/**
@@ -527,10 +539,11 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
527 * @return unique task identifier for the job 539 * @return unique task identifier for the job
528 * only valid until @a task is started! 540 * only valid until @a task is started!
529 */ 541 */
530GNUNET_SCHEDULER_TaskIdentifier 542struct GNUNET_SCHEDULER_Task *
531GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, 543GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
532 const struct GNUNET_DISK_FileHandle *wfd, 544 const struct GNUNET_DISK_FileHandle *wfd,
533 GNUNET_SCHEDULER_Task task, void *task_cls); 545 GNUNET_SCHEDULER_TaskCallback task,
546 void *task_cls);
534 547
535 548
536/** 549/**
@@ -551,12 +564,13 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
551 * @return unique task identifier for the job 564 * @return unique task identifier for the job
552 * only valid until @a task is started! 565 * only valid until @a task is started!
553 */ 566 */
554GNUNET_SCHEDULER_TaskIdentifier 567struct GNUNET_SCHEDULER_Task *
555GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay, 568GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
556 enum GNUNET_SCHEDULER_Priority priority, 569 enum GNUNET_SCHEDULER_Priority priority,
557 const struct GNUNET_DISK_FileHandle *fd, 570 const struct GNUNET_DISK_FileHandle *fd,
558 int on_read, int on_write, 571 int on_read, int on_write,
559 GNUNET_SCHEDULER_Task task, void *task_cls); 572 GNUNET_SCHEDULER_TaskCallback task,
573 void *task_cls);
560 574
561 575
562/** 576/**
@@ -586,12 +600,13 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
586 * @return unique task identifier for the job 600 * @return unique task identifier for the job
587 * only valid until "task" is started! 601 * only valid until "task" is started!
588 */ 602 */
589GNUNET_SCHEDULER_TaskIdentifier 603struct GNUNET_SCHEDULER_Task *
590GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, 604GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
591 struct GNUNET_TIME_Relative delay, 605 struct GNUNET_TIME_Relative delay,
592 const struct GNUNET_NETWORK_FDSet *rs, 606 const struct GNUNET_NETWORK_FDSet *rs,
593 const struct GNUNET_NETWORK_FDSet *ws, 607 const struct GNUNET_NETWORK_FDSet *ws,
594 GNUNET_SCHEDULER_Task task, void *task_cls); 608 GNUNET_SCHEDULER_TaskCallback task,
609 void *task_cls);
595 610
596/** 611/**
597 * Sets the select function to use in the scheduler (scheduler_select). 612 * Sets the select function to use in the scheduler (scheduler_select).