GNUnet  0.11.x
gnunet_scheduler_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2009-2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
35 #ifndef GNUNET_SCHEDULER_LIB_H
36 #define GNUNET_SCHEDULER_LIB_H
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0 /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45 
50 
56 {
61 
66 
71 
77 
82 
87 
92 };
93 
94 
95 #include "gnunet_time_lib.h"
96 #include "gnunet_network_lib.h"
97 
98 
104 {
109 
114 
119 
124 
129 
134 
139 };
140 
141 
146 {
152  const struct GNUNET_NETWORK_Handle *fd;
153 
159  const struct GNUNET_DISK_FileHandle *fh;
160 
165 
169  int sock;
170 };
171 
172 
177 {
182 
186  unsigned int fds_len;
187 
195 
202 
209 };
210 
211 
223 void
225  struct GNUNET_SCHEDULER_FdInfo *fdi);
226 
227 
232 
233 
254 int
256 
257 
263 {
267  void *cls;
268 
282  int
283  (*add)(void *cls,
284  struct GNUNET_SCHEDULER_Task *task,
285  struct GNUNET_SCHEDULER_FdInfo *fdi);
286 
297  int
298  (*del)(void *cls,
299  struct GNUNET_SCHEDULER_Task *task);
300 
307  void
308  (*set_wakeup)(void *cls,
309  struct GNUNET_TIME_Absolute dt);
310 };
311 
312 
318 typedef void
320 
321 
355 
356 
371 void
373 
374 
382 
383 
395 typedef int
397  struct GNUNET_NETWORK_FDSet *rfds,
398  struct GNUNET_NETWORK_FDSet *wfds,
399  struct GNUNET_NETWORK_FDSet *efds,
401 
402 
417 void
419  void *task_cls);
420 
432 void
433 GNUNET_SCHEDULER_run_with_optional_signals (int install_signals,
435  void *task_cls);
436 
437 
444 void
446 
447 
459 unsigned int
461 
462 
469 const struct GNUNET_SCHEDULER_TaskContext *
471 
472 
485 void *
487 
488 
499 void
501  task,
502  void *task_cls,
504  reason,
506  priority);
507 
508 
518 struct GNUNET_SCHEDULER_Task *
521  void *task_cls);
522 
523 
539 struct GNUNET_SCHEDULER_Task *
541  void *task_cls);
542 
543 
554 struct GNUNET_SCHEDULER_Task *
556  void *task_cls);
557 
558 
573 struct GNUNET_SCHEDULER_Task *
576  void *task_cls);
577 
578 
590 struct GNUNET_SCHEDULER_Task *
593  void *task_cls);
594 
595 
607 struct GNUNET_SCHEDULER_Task *
610  void *task_cls);
611 
612 
624 struct GNUNET_SCHEDULER_Task *
627  priority,
629  void *task_cls);
630 
631 
643 struct GNUNET_SCHEDULER_Task *
647  void *task_cls);
648 
649 
670 struct GNUNET_SCHEDULER_Task *
672  struct GNUNET_NETWORK_Handle *rfd,
674  void *task_cls);
675 
676 
699 struct GNUNET_SCHEDULER_Task *
702  priority,
703  struct GNUNET_NETWORK_Handle *rfd,
705  void *task_cls);
706 
707 
729 struct GNUNET_SCHEDULER_Task *
731  struct GNUNET_NETWORK_Handle *wfd,
733  void *task_cls);
734 
735 
759 struct GNUNET_SCHEDULER_Task *
762  struct GNUNET_NETWORK_Handle *fd,
763  int on_read,
764  int on_write,
766  void *task_cls);
767 
768 
789 struct GNUNET_SCHEDULER_Task *
791  const struct GNUNET_DISK_FileHandle *rfd,
793  void *task_cls);
794 
795 
816 struct GNUNET_SCHEDULER_Task *
818  const struct GNUNET_DISK_FileHandle *wfd,
820  void *task_cls);
821 
822 
846 struct GNUNET_SCHEDULER_Task *
849  priority,
850  const struct
852  int on_read,
853  int on_write,
855  void *task_cls);
856 
857 
889 struct GNUNET_SCHEDULER_Task *
892  const struct GNUNET_NETWORK_FDSet *rs,
893  const struct GNUNET_NETWORK_FDSet *ws,
895  void *task_cls);
896 
903 void
905  void *new_select_cls);
906 
907 
920 void
922 
923 
924 #if 0 /* keep Emacsens' auto-indent happy */
925 {
926 #endif
927 #ifdef __cplusplus
928 }
929 #endif
930 
931 #endif
932  /* end of group scheduler */
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at_with_priority(struct GNUNET_TIME_Absolute at, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition: scheduler.c:1104
Information about an event relating to a file descriptor/socket.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1183
The reading socket is ready.
Context information passed to each scheduler task.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
The prerequisite task is done.
struct GNUNET_SCHEDULER_Handle * GNUNET_SCHEDULER_driver_init(const struct GNUNET_SCHEDULER_Driver *driver)
Function called by external event loop implementations to initialize the scheduler.
Definition: scheduler.c:2175
const struct GNUNET_NETWORK_FDSet * write_ready
Set of file descriptors ready for writing; note that additional bits may be set that were not in the ...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1557
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:717
API an external event loop has to implement for GNUNET_SCHEDULER_driver_init.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1669
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1636
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
Identifier for an asynchronous execution context.
GNUNET_SCHEDULER_Priority
Valid task priorities.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_file_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, const struct GNUNET_DISK_FileHandle *fd, int on_read, int on_write, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready...
Definition: scheduler.c:1705
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority and to be run after the specified delay or wh...
Definition: scheduler.c:1520
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_SCHEDULER_Driver * GNUNET_SCHEDULER_driver_select(void)
Obtain the driver for using select() as the event loop.
Definition: scheduler.c:2496
We are shutting down and are running all shutdown-related tasks.
void GNUNET_SCHEDULER_add_with_reason_and_priority(GNUNET_SCHEDULER_TaskCallback task, void *task_cls, enum GNUNET_SCHEDULER_Reason reason, enum GNUNET_SCHEDULER_Priority priority)
Continue the current execution with the given function.
Definition: scheduler.c:1060
const struct GNUNET_SCHEDULER_FdInfo * fds
Array of length fds_len with information about ready FDs.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now_with_lifeness(int lifeness, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible with the (transitive) ignore-shutdown flag either e...
Definition: scheduler.c:1347
GNUNET_SCHEDULER_Reason
Reasons why the schedule may have triggered the task now.
unsigned int fds_len
Length of the following array.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
void GNUNET_SCHEDULER_set_select(GNUNET_SCHEDULER_select new_select, void *new_select_cls)
Sets the select function to use in the scheduler (scheduler_select).
Definition: scheduler.c:434
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1207
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static int del
Desired action is to remove a record.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
int sock
Underlying OS handle the event was about.
static struct SolverHandle * sh
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1810
const struct GNUNET_DISK_FileHandle * fh
GNUnet file handle the event is about, matches sock, NULL if this is about a network socket or if no ...
const struct GNUNET_NETWORK_Handle * fd
GNUnet network socket the event is about, matches sock, NULL if this is about a file handle or if no ...
Buffer available for writing.
void GNUNET_SCHEDULER_run_with_optional_signals(int install_signals, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
The writing socket is ready.
Data available for reading.
The specified timeout has expired.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static int add
Desired action is to add a record.
int GNUNET_SCHEDULER_do_work(struct GNUNET_SCHEDULER_Handle *sh)
Function called by external event loop implementations to tell the scheduler to run some of the tasks...
Definition: scheduler.c:1972
enum GNUNET_SCHEDULER_EventType et
Type of the event that was generated related to sock.
No event (useful for timeout).
This task is not ready.
int(* GNUNET_SCHEDULER_select)(void *cls, struct GNUNET_NETWORK_FDSet *rfds, struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds, struct GNUNET_TIME_Relative timeout)
Signature of the select function used by the scheduler.
void GNUNET_SCHEDULER_begin_async_scope(struct GNUNET_AsyncScopeId *aid)
Change the async scope for the currently executing task and (transitively) for all tasks scheduled by...
Definition: scheduler.c:2523
This is the very first task run during startup.
void * cls
Closure to pass to the functions in this struct.
Entry in list of pending tasks.
Definition: scheduler.c:134
handle to a socket
Definition: network.c:52
void GNUNET_SCHEDULER_driver_done(struct GNUNET_SCHEDULER_Handle *sh)
Counter-part of GNUNET_SCHEDULER_driver_init.
Definition: scheduler.c:2250
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1486
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_net_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, struct GNUNET_NETWORK_Handle *fd, int on_read, int on_write, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready...
Definition: scheduler.c:1594
void GNUNET_SCHEDULER_task_ready(struct GNUNET_SCHEDULER_Task *task, struct GNUNET_SCHEDULER_FdInfo *fdi)
Function used by event-loop implementations to signal the scheduler that a particular task is ready d...
Definition: scheduler.c:1927
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition: scheduler.c:1230
Handle used to access files (and pipes).
Argument to be passed from the driver to GNUNET_SCHEDULER_do_work().
Definition: scheduler.c:81
unsigned int GNUNET_SCHEDULER_get_load(enum GNUNET_SCHEDULER_Priority p)
Get information about the current load of this scheduler.
Definition: scheduler.c:764
Time for relative time used by GNUnet, in microseconds.
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
GNUNET_SCHEDULER_EventType
Possible events on FDs, used as a bitmask.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966