GNUnet  0.10.x
Data Structures | Typedefs | Enumerations | Functions
Scheduler library

Event loop (scheduler) More...

Data Structures

struct  GNUNET_SCHEDULER_FdInfo
 Information about an event relating to a file descriptor/socket. More...
 
struct  GNUNET_SCHEDULER_TaskContext
 Context information passed to each scheduler task. More...
 
struct  GNUNET_SCHEDULER_Driver
 API an external event loop has to implement for GNUNET_SCHEDULER_driver_init. More...
 

Typedefs

typedef void(* GNUNET_SCHEDULER_TaskCallback) (void *cls)
 Signature of the main function of a task. More...
 
typedef 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. More...
 

Enumerations

enum  GNUNET_SCHEDULER_Reason {
  GNUNET_SCHEDULER_REASON_NONE = 0, GNUNET_SCHEDULER_REASON_STARTUP = 1, GNUNET_SCHEDULER_REASON_SHUTDOWN = 2, GNUNET_SCHEDULER_REASON_TIMEOUT = 4,
  GNUNET_SCHEDULER_REASON_READ_READY = 8, GNUNET_SCHEDULER_REASON_WRITE_READY = 16, GNUNET_SCHEDULER_REASON_PREREQ_DONE = 32
}
 Reasons why the schedule may have triggered the task now. More...
 
enum  GNUNET_SCHEDULER_EventType {
  GNUNET_SCHEDULER_ET_NONE = 0, GNUNET_SCHEDULER_ET_IN = 1, GNUNET_SCHEDULER_ET_OUT = 2, GNUNET_SCHEDULER_ET_HUP = 4,
  GNUNET_SCHEDULER_ET_ERR = 8, GNUNET_SCHEDULER_ET_PRI = 16, GNUNET_SCHEDULER_ET_NVAL = 32
}
 Possible events on FDs, used as a bitmask. More...
 

Functions

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 due to an event specified in the et field of fdi. More...
 
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 that are ready. More...
 
struct GNUNET_SCHEDULER_HandleGNUNET_SCHEDULER_driver_init (const struct GNUNET_SCHEDULER_Driver *driver)
 Function called by external event loop implementations to initialize the scheduler. More...
 
void GNUNET_SCHEDULER_driver_done (struct GNUNET_SCHEDULER_Handle *sh)
 Counter-part of GNUNET_SCHEDULER_driver_init. More...
 
struct GNUNET_SCHEDULER_DriverGNUNET_SCHEDULER_driver_select (void)
 Obtain the driver for using select() as the event loop. More...
 
void GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
 Initialize and run scheduler. More...
 
void GNUNET_SCHEDULER_run_with_optional_signals (int install_signals, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
 Initialize and run scheduler. More...
 
void GNUNET_SCHEDULER_shutdown (void)
 Request the shutdown of a scheduler. More...
 
unsigned int GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p)
 Get information about the current load of this scheduler. More...
 
const struct GNUNET_SCHEDULER_TaskContextGNUNET_SCHEDULER_get_task_context (void)
 Obtain the reasoning why the current task was started. More...
 
void * GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task)
 Cancel the task with the specified identifier. More...
 
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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
 Schedule a new task to be run as soon as possible. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 explicitly set or explicitly enabled. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 for reading. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 when the specified file descriptor is ready for reading. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 for writing. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 for reading. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 for writing. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_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 sets is ready. More...
 
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). More...
 
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 the current task after calling this function. More...
 

Detailed Description

Event loop (scheduler)

Schedule computations using continuation passing style.

Typedef Documentation

◆ GNUNET_SCHEDULER_TaskCallback

typedef void(* GNUNET_SCHEDULER_TaskCallback) (void *cls)

Signature of the main function of a task.

Parameters
clsclosure

Definition at line 328 of file gnunet_scheduler_lib.h.

◆ GNUNET_SCHEDULER_select

typedef 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.

GNUNET_NETWORK_socket_select matches it.

Parameters
clsclosure
rfdsset of sockets to be checked for readability
wfdsset of sockets to be checked for writability
efdsset of sockets to be checked for exceptions
timeoutrelative value when to return
Returns
number of selected sockets, GNUNET_SYSERR on error

Definition at line 405 of file gnunet_scheduler_lib.h.

Enumeration Type Documentation

◆ GNUNET_SCHEDULER_Reason

Reasons why the schedule may have triggered the task now.

Enumerator
GNUNET_SCHEDULER_REASON_NONE 

This task is not ready.

GNUNET_SCHEDULER_REASON_STARTUP 

This is the very first task run during startup.

GNUNET_SCHEDULER_REASON_SHUTDOWN 

We are shutting down and are running all shutdown-related tasks.

GNUNET_SCHEDULER_REASON_TIMEOUT 

The specified timeout has expired.

(also set if the delay given was 0).

GNUNET_SCHEDULER_REASON_READ_READY 

The reading socket is ready.

GNUNET_SCHEDULER_REASON_WRITE_READY 

The writing socket is ready.

GNUNET_SCHEDULER_REASON_PREREQ_DONE 

The prerequisite task is done.

Definition at line 55 of file gnunet_scheduler_lib.h.

56 {
61 
66 
71 
77 
82 
87 
92 };
The reading socket is ready.
The prerequisite task is done.
We are shutting down and are running all shutdown-related tasks.
The writing socket is ready.
The specified timeout has expired.
This task is not ready.
This is the very first task run during startup.

◆ GNUNET_SCHEDULER_EventType

Possible events on FDs, used as a bitmask.

Modelled after GPollFD.

Enumerator
GNUNET_SCHEDULER_ET_NONE 

No event (useful for timeout).

GNUNET_SCHEDULER_ET_IN 

Data available for reading.

GNUNET_SCHEDULER_ET_OUT 

Buffer available for writing.

GNUNET_SCHEDULER_ET_HUP 
GNUNET_SCHEDULER_ET_ERR 
GNUNET_SCHEDULER_ET_PRI 
GNUNET_SCHEDULER_ET_NVAL 

Definition at line 103 of file gnunet_scheduler_lib.h.

Function Documentation

◆ GNUNET_SCHEDULER_task_ready()

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 due to an event specified in the et field of fdi.

This function will then queue the task to notify the application that the task is ready (with the respective priority).

Parameters
taskthe task that is ready
fdiinformation about the related FD

Definition at line 1947 of file scheduler.c.

References GNUNET_SCHEDULER_FdInfo::et, GNUNET_CONTAINER_DLL_remove, GNUNET_NO, GNUNET_SCHEDULER_ET_IN, GNUNET_SCHEDULER_ET_OUT, GNUNET_SCHEDULER_REASON_PREREQ_DONE, GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_SCHEDULER_REASON_WRITE_READY, GNUNET_SCHEDULER_Task::in_ready_list, queue_ready_task(), and GNUNET_SCHEDULER_Task::reason.

Referenced by select_loop().

1949 {
1950  enum GNUNET_SCHEDULER_Reason reason;
1951 
1952  reason = task->reason;
1953  if ( (0 == (reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
1954  (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et)) )
1956  if ( (0 == (reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
1957  (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et)) )
1960  task->reason = reason;
1961  if (GNUNET_NO == task->in_ready_list)
1962  {
1964  pending_tail,
1965  task);
1966  queue_ready_task (task);
1967  }
1968 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
The reading socket is ready.
The prerequisite task is done.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_SCHEDULER_Task * pending_head
Head of list of tasks waiting for an event.
Definition: scheduler.c:317
GNUNET_SCHEDULER_Reason
Reasons why the schedule may have triggered the task now.
static struct GNUNET_SCHEDULER_Task * pending_tail
Tail of list of tasks waiting for an event.
Definition: scheduler.c:322
Buffer available for writing.
enum GNUNET_SCHEDULER_Reason reason
Why is the task ready? Set after task is added to ready queue.
Definition: scheduler.c:198
The writing socket is ready.
Data available for reading.
static void queue_ready_task(struct GNUNET_SCHEDULER_Task *task)
Put a task that is ready for execution into the ready queue.
Definition: scheduler.c:505
enum GNUNET_SCHEDULER_EventType et
Type of the event that was generated related to sock.
int in_ready_list
Is this task in the ready list?
Definition: scheduler.c:229
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_do_work()

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 that are ready.

Must be called only after GNUNET_SCHEDULER_driver_init has been called and before GNUNET_SCHEDULER_driver_done is called. This function may return even though there are tasks left to run just to give other tasks a chance as well. If we return GNUNET_YES, the event loop implementation should call this function again as soon as possible, while if we return GNUNET_NO it must block until either the operating system has more work (the scheduler has no more work to do right now) or the timeout set by the scheduler (using the set_wakeup callback) is reached.

Parameters
shscheduler handle that was returned by GNUNET_SCHEDULER_driver_init
Returns
GNUNET_YES if there are more tasks that are ready, and thus we would like to run more (yield to avoid blocking other activities for too long) GNUNET_NO if we are done running tasks (yield to block)

The event loop called this function before the current timeout was reached (and no FD tasks are ready). This is acceptable if

  • the system time was changed while the driver was waiting for the timeout
  • an external event loop called GNUnet API functions outside of the callbacks called in GNUNET_SCHEDULER_do_work and thus wasn't notified about the new timeout

It might also mean we are busy-waiting because of a programming error in the external event loop.

the current timeout was reached but no ready tasks were found, internal scheduler error!

Definition at line 1992 of file scheduler.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_SCHEDULER_Task::callback, GNUNET_SCHEDULER_Task::callback_cls, GNUNET_SCHEDULER_Driver::cls, current_lifeness, current_priority, GNUNET_SCHEDULER_Driver::del, DELAY_THRESHOLD, destroy_task(), dump_backtrace(), GNUNET_SCHEDULER_FdInfo::et, GNUNET_SCHEDULER_Task::fds, GNUNET_SCHEDULER_TaskContext::fds, GNUNET_SCHEDULER_Task::fds_len, GNUNET_SCHEDULER_TaskContext::fds_len, get_timeout(), GNUNET_assert, GNUNET_async_scope_enter(), GNUNET_async_scope_get(), GNUNET_async_scope_restore(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_NETWORK_fdset_set_native(), GNUNET_NETWORK_fdset_zero(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_ET_IN, GNUNET_SCHEDULER_ET_OUT, GNUNET_SCHEDULER_PRIORITY_COUNT, GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_REASON_TIMEOUT, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, GNUNET_AsyncScopeSave::have_scope, GNUNET_SCHEDULER_Task::lifeness, LOG, max_priority_added, GNUNET_SCHEDULER_Task::next, p, pending_head, pending_timeout_head, GNUNET_SCHEDULER_Task::priority, queue_ready_task(), GNUNET_SCHEDULER_TaskContext::read_ready, ready_count, GNUNET_SCHEDULER_TaskContext::reason, GNUNET_SCHEDULER_Task::reason, GNUNET_TIME_Relative::rel_value_us, GNUNET_SCHEDULER_Handle::rs, GNUNET_SCHEDULER_Task::scope, GNUNET_AsyncScopeSave::scope_id, GNUNET_SCHEDULER_Driver::set_wakeup, shutdown_if_no_lifeness(), GNUNET_SCHEDULER_FdInfo::sock, tc, GNUNET_SCHEDULER_Task::timeout, GNUNET_SCHEDULER_TaskContext::write_ready, and GNUNET_SCHEDULER_Handle::ws.

Referenced by select_loop().

1993 {
1995  struct GNUNET_SCHEDULER_Task *pos;
1996  struct GNUNET_TIME_Absolute now;
1997 
1998  /* check for tasks that reached the timeout! */
1999  now = GNUNET_TIME_absolute_get ();
2000  pos = pending_timeout_head;
2001  while (NULL != pos)
2002  {
2003  struct GNUNET_SCHEDULER_Task *next = pos->next;
2004  if (now.abs_value_us >= pos->timeout.abs_value_us)
2006  if (0 == pos->reason)
2007  break;
2010  pos);
2011  if (pending_timeout_last == pos)
2012  pending_timeout_last = NULL;
2013  queue_ready_task (pos);
2014  pos = next;
2015  }
2016  pos = pending_head;
2017  while (NULL != pos)
2018  {
2019  struct GNUNET_SCHEDULER_Task *next = pos->next;
2020  if (now.abs_value_us >= pos->timeout.abs_value_us)
2021  {
2024  pending_tail,
2025  pos);
2026  queue_ready_task (pos);
2027  }
2028  pos = next;
2029  }
2030 
2031  if (0 == ready_count)
2032  {
2034 
2035  if (timeout.abs_value_us > now.abs_value_us)
2036  {
2051  "GNUNET_SCHEDULER_do_work did not find any ready "
2052  "tasks and timeout has not been reached yet.\n");
2053  }
2054  else
2055  {
2060  GNUNET_assert (0);
2061  }
2062  }
2063  else
2064  {
2065  /* find out which task priority level we are going to
2066  process this time */
2069  /* yes, p>0 is correct, 0 is "KEEP" which should
2070  * always be an empty queue (see assertion)! */
2071  for (p = GNUNET_SCHEDULER_PRIORITY_COUNT - 1; p > 0; p--)
2072  {
2073  pos = ready_head[p];
2074  if (NULL != pos)
2075  break;
2076  }
2077  GNUNET_assert (NULL != pos); /* ready_count wrong? */
2078 
2079  /* process all tasks at this priority level, then yield */
2080  while (NULL != (pos = ready_head[p]))
2081  {
2083  ready_tail[p],
2084  pos);
2085  ready_count--;
2086  current_priority = pos->priority;
2087  current_lifeness = pos->lifeness;
2088  active_task = pos;
2089 #if PROFILE_DELAYS
2090  if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us >
2091  DELAY_THRESHOLD.rel_value_us)
2092  {
2094  "Task %p took %s to be scheduled\n",
2095  pos,
2097  GNUNET_YES));
2098  }
2099 #endif
2100  tc.reason = pos->reason;
2103  // FIXME: do we have to remove FdInfos from fds if they are not ready?
2104  tc.fds_len = pos->fds_len;
2105  tc.fds = pos->fds;
2106  for (unsigned int i = 0; i != pos->fds_len; ++i)
2107  {
2108  struct GNUNET_SCHEDULER_FdInfo *fdi = &pos->fds[i];
2109  if (0 != (GNUNET_SCHEDULER_ET_IN & fdi->et))
2110  {
2112  fdi->sock);
2113  }
2114  if (0 != (GNUNET_SCHEDULER_ET_OUT & fdi->et))
2115  {
2117  fdi->sock);
2118  }
2119  }
2120  tc.read_ready = sh->rs;
2121  tc.write_ready = sh->ws;
2123  "Running task %p\n",
2124  pos);
2125  GNUNET_assert (NULL != pos->callback);
2126  {
2127  struct GNUNET_AsyncScopeSave old_scope;
2128  if (pos->scope.have_scope)
2129  GNUNET_async_scope_enter (&pos->scope.scope_id, &old_scope);
2130  else
2131  GNUNET_async_scope_get (&old_scope);
2132  pos->callback (pos->callback_cls);
2133  GNUNET_async_scope_restore (&old_scope);
2134  }
2135  if (NULL != pos->fds)
2136  {
2137  int del_result = scheduler_driver->del (scheduler_driver->cls, pos);
2138  if (GNUNET_OK != del_result)
2139  {
2141  "driver could not delete task %p\n", pos);
2142  GNUNET_assert (0);
2143  }
2144  }
2145  active_task = NULL;
2146  dump_backtrace (pos);
2147  destroy_task (pos);
2148  }
2149  }
2151  if (0 == ready_count)
2152  {
2154  get_timeout ());
2155  return GNUNET_NO;
2156  }
2159  return GNUNET_YES;
2160 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static unsigned int ready_count
Number of tasks on the ready list.
Definition: scheduler.c:389
Information about an event relating to a file descriptor/socket.
struct GNUNET_NETWORK_FDSet * rs
Passed here to avoid constantly allocating/deallocating this element, but generally we want to get ri...
Definition: scheduler.c:86
uint64_t rel_value_us
The actual value.
GNUNET_SCHEDULER_TaskCallback callback
Function to run when ready.
Definition: scheduler.c:149
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
Definition: network.c:1325
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
Run with the same priority as the current job.
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 ...
static struct GNUNET_SCHEDULER_Task * pending_timeout_tail
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:350
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_TIME_Absolute get_timeout()
chooses the nearest timeout from all pending tasks, to be used to tell the driver the next wakeup tim...
Definition: scheduler.c:463
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 ...
static struct GNUNET_SCHEDULER_Task * pending_head
Head of list of tasks waiting for an event.
Definition: scheduler.c:317
GNUNET_SCHEDULER_Priority
Valid task priorities.
static struct GNUNET_SCHEDULER_Task * active_task
ID of the task that is running right now.
Definition: scheduler.c:361
uint64_t abs_value_us
The actual value.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
static struct GNUNET_SCHEDULER_Task * pending_timeout_last
Last inserted task waiting ONLY for a timeout event.
Definition: scheduler.c:356
const struct GNUNET_SCHEDULER_FdInfo * fds
Array of length fds_len with information about ready FDs.
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
unsigned int fds_len
Length of the following array.
static struct GNUNET_SCHEDULER_Task * pending_tail
Tail of list of tasks waiting for an event.
Definition: scheduler.c:322
static struct GNUNET_SCHEDULER_Task * ready_tail[GNUNET_SCHEDULER_PRIORITY_COUNT]
Tail of list of tasks ready to run right now, grouped by importance.
Definition: scheduler.c:371
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
int sock
Underlying OS handle the event was about.
static int current_lifeness
Value of the 'lifeness' flag for the current task.
Definition: scheduler.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
static struct GNUNET_SCHEDULER_Task * pending_timeout_head
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:341
static struct GNUNET_SCHEDULER_Task * ready_head[GNUNET_SCHEDULER_PRIORITY_COUNT]
Head of list of tasks ready to run right now, grouped by importance.
Definition: scheduler.c:366
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
Buffer available for writing.
struct GNUNET_SCHEDULER_FdInfo * fds
Information about which FDs are ready for this task (and why).
Definition: scheduler.c:159
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void * callback_cls
Closure for the callback.
Definition: scheduler.c:154
enum GNUNET_SCHEDULER_Reason reason
Why is the task ready? Set after task is added to ready queue.
Definition: scheduler.c:198
Data available for reading.
static void queue_ready_task(struct GNUNET_SCHEDULER_Task *task)
Put a task that is ready for execution into the ready queue.
Definition: scheduler.c:505
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
#define LOG(kind,...)
Definition: scheduler.c:31
Saved async scope identifier or root scope.
#define DELAY_THRESHOLD
Task that were in the queue for longer than this are reported if PROFILE_DELAYS is active...
Definition: scheduler.c:71
The specified timeout has expired.
void GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread's async scope.
void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds)
Reset FD set (clears all file descriptors).
Definition: network.c:1146
static void destroy_task(struct GNUNET_SCHEDULER_Task *t)
Destroy a task (release associated resources)
Definition: scheduler.c:578
static enum GNUNET_SCHEDULER_Priority current_priority
Priority of the task running right now.
Definition: scheduler.c:395
void(* set_wakeup)(void *cls, struct GNUNET_TIME_Absolute dt)
Set time at which we definitively want to get a wakeup call.
enum GNUNET_SCHEDULER_EventType et
Type of the event that was generated related to sock.
unsigned int fds_len
Size of the fds array.
Definition: scheduler.c:171
struct GNUNET_AsyncScopeId scope_id
Saved scope.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Definition: scheduler.c:139
static enum GNUNET_SCHEDULER_Priority max_priority_added
Priority of the highest task added in the current select iteration.
Definition: scheduler.c:401
void * cls
Closure to pass to the functions in this struct.
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_TIME_Absolute timeout
Absolute timeout value for the task, or GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout".
Definition: scheduler.c:184
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void dump_backtrace(struct GNUNET_SCHEDULER_Task *t)
Output stack trace of task t.
Definition: scheduler.c:557
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
struct GNUNET_AsyncScopeSave scope
Asynchronous scope of the task that scheduled this scope,.
Definition: scheduler.c:247
Number of priorities (must be the last priority).
struct GNUNET_NETWORK_FDSet * ws
Passed here to avoid constantly allocating/deallocating this element, but generally we want to get ri...
Definition: scheduler.c:93
int(* del)(void *cls, struct GNUNET_SCHEDULER_Task *task)
Delete a task from the set of tasks to be run.
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
static void shutdown_if_no_lifeness()
Definition: scheduler.c:676
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_driver_init()

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.

An external implementation has to provide driver which contains callbacks for the scheduler (see definition of struct GNUNET_SCHEDULER_Driver). The callbacks are used to instruct the external implementation to watch for events. If it detects any of those events it is expected to call GNUNET_SCHEDULER_do_work to let the scheduler handle it. If an event is related to a specific task (e.g. the scheduler gave instructions to watch a file descriptor), the external implementation is expected to mark that task ready before by calling GNUNET_SCHEDULER_task_ready.

This function has to be called before any tasks are scheduled and before GNUNET_SCHEDULER_do_work is called for the first time. It allocates resources that have to be freed again by calling GNUNET_SCHEDULER_driver_done.

This function installs the same signal handlers as GNUNET_SCHEDULER_run. This means SIGTERM (and other similar signals) will induce a call to GNUNET_SCHEDULER_shutdown during the next call to GNUNET_SCHEDULER_do_work. As a result, SIGTERM causes all active tasks to be scheduled with reason GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added afterwards will execute normally!). Note that any particular signal will only shut down one scheduler; applications should always only create a single scheduler.

Parameters
driverto use for the event loop
Returns
handle to be passed to GNUNET_SCHEDULER_do_work and GNUNET_SCHEDULER_driver_done

Definition at line 2195 of file scheduler.c.

References GNUNET_SCHEDULER_Driver::cls, current_lifeness, current_priority, get_timeout(), GNUNET_assert, GNUNET_DISK_pipe(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_handle_set(), GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SIGNAL_handler_install(), GNUNET_TERM_SIG, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, install_parent_control_handler(), LOG, my_pid, GNUNET_SCHEDULER_Handle::rs, GNUNET_SCHEDULER_Driver::set_wakeup, sh, GNUNET_SCHEDULER_Handle::shc_hup, GNUNET_SCHEDULER_Handle::shc_int, GNUNET_SCHEDULER_Handle::shc_pipe, GNUNET_SCHEDULER_Handle::shc_quit, GNUNET_SCHEDULER_Handle::shc_term, shutdown_pipe_cb(), sighandler_pipe(), sighandler_shutdown(), and GNUNET_SCHEDULER_Handle::ws.

Referenced by GNUNET_SCHEDULER_run().

2196 {
2197  struct GNUNET_SCHEDULER_Handle *sh;
2198  const struct GNUNET_DISK_FileHandle *pr;
2199 
2200  /* scheduler must not be running */
2201  GNUNET_assert (NULL == scheduler_driver);
2203  /* general set-up */
2204  sh = GNUNET_new (struct GNUNET_SCHEDULER_Handle);
2206  GNUNET_NO,
2207  GNUNET_NO,
2208  GNUNET_NO);
2212  my_pid = getpid ();
2213  scheduler_driver = driver;
2214 
2215  /* install signal handlers */
2217  "Registering signal handlers\n");
2218  sh->shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
2220  sh->shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
2222 #if (SIGTERM != GNUNET_TERM_SIG)
2225 #endif
2226 #ifndef MINGW
2227  sh->shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
2228  &sighandler_pipe);
2229  sh->shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
2231  sh->shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
2233 #endif
2234 
2235  /* Setup initial tasks */
2240  NULL);
2243  pr,
2245  NULL);
2248  get_timeout ());
2249  /* begin main event loop */
2253  return sh;
2254 }
struct GNUNET_NETWORK_FDSet * rs
Passed here to avoid constantly allocating/deallocating this element, but generally we want to get ri...
Definition: scheduler.c:86
static void install_parent_control_handler(void *cls)
Definition: scheduler.c:921
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void sighandler_shutdown()
Wait for a short time.
Definition: scheduler.c:660
struct GNUNET_SIGNAL_Context * shc_term
context of the SIGTERM handler
Definition: scheduler.c:103
static pid_t my_pid
Process ID of this process at the time we installed the various signal handlers.
Definition: scheduler.c:624
static struct GNUNET_DISK_PipeHandle * shutdown_pipe_handle
Pipe used to communicate shutdown via signal.
Definition: scheduler.c:618
#define GNUNET_NO
Definition: gnunet_common.h:81
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:1643
struct GNUNET_TIME_Absolute get_timeout()
chooses the nearest timeout from all pending tasks, to be used to tell the driver the next wakeup tim...
Definition: scheduler.c:463
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * install_parent_control_task
Task for installing parent control handlers (it might happen that the scheduler is shutdown before th...
Definition: scheduler.c:378
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:2641
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
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:1273
static struct SolverHandle * sh
static int current_lifeness
Value of the 'lifeness' flag for the current task.
Definition: scheduler.c:406
struct GNUNET_SIGNAL_Context * shc_int
context of the SIGINT handler
Definition: scheduler.c:98
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
The reading-end of a pipe.
static struct GNUNET_SCHEDULER_Task * shutdown_pipe_task
Task for reading from a pipe that signal handlers will use to initiate shutdown.
Definition: scheduler.c:384
struct GNUNET_SIGNAL_Context * shc_hup
context of the SIGHUP handler
Definition: scheduler.c:121
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:2289
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition: signal.c:59
#define LOG(kind,...)
Definition: scheduler.c:31
static enum GNUNET_SCHEDULER_Priority current_priority
Priority of the task running right now.
Definition: scheduler.c:395
void(* set_wakeup)(void *cls, struct GNUNET_TIME_Absolute dt)
Set time at which we definitively want to get a wakeup call.
void GNUNET_NETWORK_fdset_handle_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h)
Add a file handle to the fd set.
Definition: network.c:1359
struct GNUNET_SIGNAL_Context * shc_pipe
context of hte SIGPIPE handler
Definition: scheduler.c:126
static void sighandler_pipe()
Signal handler called for SIGPIPE.
Definition: scheduler.c:631
static void shutdown_pipe_cb(void *cls)
Definition: scheduler.c:930
void * cls
Closure to pass to the functions in this struct.
#define GNUNET_YES
Definition: gnunet_common.h:80
Run with the default priority (normal P2P operations).
struct GNUNET_NETWORK_FDSet * ws
Passed here to avoid constantly allocating/deallocating this element, but generally we want to get ri...
Definition: scheduler.c:93
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
struct GNUNET_SIGNAL_Context * shc_quit
context of the SIGQUIT handler
Definition: scheduler.c:116
Handle used to access files (and pipes).
Argument to be passed from the driver to GNUNET_SCHEDULER_do_work().
Definition: scheduler.c:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_driver_done()

void GNUNET_SCHEDULER_driver_done ( struct GNUNET_SCHEDULER_Handle sh)

Counter-part of GNUNET_SCHEDULER_driver_init.

Has to be called by external event loop implementations after the scheduler has shut down. This is the case if both of the following conditions are met:

  • all tasks the scheduler has added through the driver's add callback have been removed again through the driver's del callback
  • the timeout the scheduler has set through the driver's add_wakeup callback is FOREVER
Parameters
shthe handle returned by GNUNET_SCHEDULER_driver_init

Definition at line 2272 of file scheduler.c.

References GNUNET_assert, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_PRIORITY_COUNT, GNUNET_SIGNAL_handler_uninstall(), GNUNET_SCHEDULER_Handle::rs, GNUNET_SCHEDULER_Handle::shc_hup, GNUNET_SCHEDULER_Handle::shc_int, GNUNET_SCHEDULER_Handle::shc_pipe, GNUNET_SCHEDULER_Handle::shc_quit, GNUNET_SCHEDULER_Handle::shc_term, and GNUNET_SCHEDULER_Handle::ws.

Referenced by GNUNET_SCHEDULER_run().

2273 {
2274  GNUNET_assert (NULL == pending_head);
2276  GNUNET_assert (NULL == shutdown_head);
2277  for (int i = 0; i != GNUNET_SCHEDULER_PRIORITY_COUNT; ++i)
2278  {
2279  GNUNET_assert (NULL == ready_head[i]);
2280  }
2283 
2284  /* uninstall signal handlers */
2287 #if (SIGTERM != GNUNET_TERM_SIG)
2288  GNUNET_SIGNAL_handler_uninstall (sh->shc_gterm);
2289 #endif
2290 #ifndef MINGW
2294 #endif
2296  shutdown_pipe_handle = NULL;
2297  scheduler_driver = NULL;
2298  GNUNET_free (sh);
2299 }
struct GNUNET_NETWORK_FDSet * rs
Passed here to avoid constantly allocating/deallocating this element, but generally we want to get ri...
Definition: scheduler.c:86
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SIGNAL_Context * shc_term
context of the SIGTERM handler
Definition: scheduler.c:103
static struct GNUNET_DISK_PipeHandle * shutdown_pipe_handle
Pipe used to communicate shutdown via signal.
Definition: scheduler.c:618
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal hander.
Definition: signal.c:99
static struct GNUNET_SCHEDULER_Task * pending_head
Head of list of tasks waiting for an event.
Definition: scheduler.c:317
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
static struct GNUNET_SCHEDULER_Task * pending_timeout_head
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:341
static struct GNUNET_SCHEDULER_Task * ready_head[GNUNET_SCHEDULER_PRIORITY_COUNT]
Head of list of tasks ready to run right now, grouped by importance.
Definition: scheduler.c:366
struct GNUNET_SIGNAL_Context * shc_int
context of the SIGINT handler
Definition: scheduler.c:98
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
struct GNUNET_SIGNAL_Context * shc_hup
context of the SIGHUP handler
Definition: scheduler.c:121
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
struct GNUNET_SIGNAL_Context * shc_pipe
context of hte SIGPIPE handler
Definition: scheduler.c:126
Number of priorities (must be the last priority).
static struct GNUNET_SCHEDULER_Task * shutdown_head
Head of list of tasks waiting for shutdown.
Definition: scheduler.c:327
struct GNUNET_NETWORK_FDSet * ws
Passed here to avoid constantly allocating/deallocating this element, but generally we want to get ri...
Definition: scheduler.c:93
struct GNUNET_SIGNAL_Context * shc_quit
context of the SIGQUIT handler
Definition: scheduler.c:116
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_driver_select()

struct GNUNET_SCHEDULER_Driver* GNUNET_SCHEDULER_driver_select ( void  )

Obtain the driver for using select() as the event loop.

Returns
NULL on error

Definition at line 2520 of file scheduler.c.

References GNUNET_SCHEDULER_Driver::add, GNUNET_SCHEDULER_Driver::del, GNUNET_new, select_add(), select_del(), select_set_wakeup(), and GNUNET_SCHEDULER_Driver::set_wakeup.

Referenced by GNUNET_SCHEDULER_run().

2521 {
2522  struct GNUNET_SCHEDULER_Driver *select_driver;
2523  select_driver = GNUNET_new (struct GNUNET_SCHEDULER_Driver);
2524 
2525  select_driver->add = &select_add;
2526  select_driver->del = &select_del;
2527  select_driver->set_wakeup = &select_set_wakeup;
2528 
2529  return select_driver;
2530 }
API an external event loop has to implement for GNUNET_SCHEDULER_driver_init.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int select_del(void *cls, struct GNUNET_SCHEDULER_Task *task)
Definition: scheduler.c:2474
static void select_set_wakeup(void *cls, struct GNUNET_TIME_Absolute dt)
Definition: scheduler.c:2504
static int select_add(void *cls, struct GNUNET_SCHEDULER_Task *task, struct GNUNET_SCHEDULER_FdInfo *fdi)
Definition: scheduler.c:2444
void(* set_wakeup)(void *cls, struct GNUNET_TIME_Absolute dt)
Set time at which we definitively want to get a wakeup call.
int(* add)(void *cls, struct GNUNET_SCHEDULER_Task *task, struct GNUNET_SCHEDULER_FdInfo *fdi)
Add a task to be run if the conditions specified in the et field of the given fdi are satisfied...
int(* del)(void *cls, struct GNUNET_SCHEDULER_Task *task)
Delete a task from the set of tasks to be run.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_run()

void GNUNET_SCHEDULER_run ( GNUNET_SCHEDULER_TaskCallback  task,
void *  task_cls 
)

Initialize and run scheduler.

This function will return when all tasks have completed. On systems with signals, receiving a SIGTERM (and other similar signals) will cause GNUNET_SCHEDULER_shutdown to be run after the active task is complete. As a result, SIGTERM causes all shutdown tasks to be scheduled with reason GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added afterwards will execute normally!). Note that any particular signal will only shut down one scheduler; applications should always only create a single scheduler.

Parameters
tasktask to run first (and immediately)
task_clsclosure of task

This function will return when all tasks have completed. On systems with signals, receiving a SIGTERM (and other similar signals) will cause GNUNET_SCHEDULER_shutdown() to be run after the active task is complete. As a result, SIGTERM causes all active tasks to be scheduled with reason GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added afterwards will execute normally!). Note that any particular signal will only shut down one scheduler; applications should always only create a single scheduler.

Parameters
tasktask to run immediately
task_clsclosure of task

Definition at line 716 of file scheduler.c.

References GNUNET_SCHEDULER_Driver::cls, context, GNUNET_free, GNUNET_SCHEDULER_add_with_reason_and_priority(), GNUNET_SCHEDULER_driver_done(), GNUNET_SCHEDULER_driver_init(), GNUNET_SCHEDULER_driver_select(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SCHEDULER_REASON_STARTUP, GNUNET_TIME_absolute_get(), DriverContext::scheduled_head, select_loop(), and sh.

Referenced by GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), GNUNET_TESTING_service_run(), LEGACY_SERVICE_run(), and main().

718 {
719  struct GNUNET_SCHEDULER_Handle *sh;
720  struct GNUNET_SCHEDULER_Driver *driver;
721  struct DriverContext context = {.scheduled_head = NULL,
722  .scheduled_tail = NULL,
723  .timeout = GNUNET_TIME_absolute_get ()};
724 
725  driver = GNUNET_SCHEDULER_driver_select ();
726  driver->cls = &context;
727  sh = GNUNET_SCHEDULER_driver_init (driver);
729  task_cls,
732  select_loop (sh,
733  &context);
735  GNUNET_free (driver);
736 }
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:2195
API an external event loop has to implement for GNUNET_SCHEDULER_driver_init.
static pa_context * context
Pulseaudio context.
struct GNUNET_SCHEDULER_Driver * GNUNET_SCHEDULER_driver_select()
Obtain the driver for using select() as the event loop.
Definition: scheduler.c:2520
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:1059
Driver context used by GNUNET_SCHEDULER_run.
Definition: scheduler.c:283
static struct SolverHandle * sh
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static int select_loop(struct GNUNET_SCHEDULER_Handle *sh, struct DriverContext *context)
Definition: scheduler.c:2303
This is the very first task run during startup.
void * cls
Closure to pass to the functions in this struct.
void GNUNET_SCHEDULER_driver_done(struct GNUNET_SCHEDULER_Handle *sh)
Counter-part of GNUNET_SCHEDULER_driver_init.
Definition: scheduler.c:2272
Run with the default priority (normal P2P operations).
Argument to be passed from the driver to GNUNET_SCHEDULER_do_work().
Definition: scheduler.c:79
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_run_with_optional_signals()

void GNUNET_SCHEDULER_run_with_optional_signals ( int  install_signals,
GNUNET_SCHEDULER_TaskCallback  task,
void *  task_cls 
)

Initialize and run scheduler.

This function will return when all tasks have completed. When @ install_signals is GNUNET_YES, then this function behaves in the same was as GNUNET_SCHEDULER_run does. If @ install_signals is GNUNET_NO then no signal handlers are installed.

Parameters
install_signalswhether to install signals (GNUNET_YES/NO)
tasktask to run first (and immediately)
task_clsclosure of task

◆ GNUNET_SCHEDULER_shutdown()

void GNUNET_SCHEDULER_shutdown ( void  )

Request the shutdown of a scheduler.

Marks all tasks awaiting shutdown as ready. Note that tasks scheduled with GNUNET_SCHEDULER_add_shutdown() AFTER this call will be delayed until the next shutdown signal.

Definition at line 524 of file scheduler.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_REASON_SHUTDOWN, LOG, queue_ready_task(), and GNUNET_SCHEDULER_Task::reason.

Referenced by action_loop(), addr_info_cb(), allocation_cb(), ats_connect_completion_cb(), bandwidth_stats_cont(), cadet_connect_cb(), calculate_pow(), channel_ended(), check_all_done(), child_death_task(), churn_cb(), cleanup(), client_disconnect_cb(), comm_connect_completion_cb(), conn_status(), connect_check_run(), connect_completion_callback(), controller_event_cb(), controller_status_cb(), core_init(), decrypt_cb(), default_ego_cb(), dht_connect_cb(), dht_connected(), directory_scan_cb(), directory_trim_complete(), disconnect_cadet_peers(), do_abort(), do_connect_peers(), do_directory_scan(), do_get(), do_quit(), do_send(), do_shutdown(), do_timeout(), ego_callback(), event_cb(), experiment_done_cb(), find_proof(), GCD_init(), get_cb(), get_ego(), GNUNET_ATS_TEST_shutdown_topology(), GNUNET_CADET_TEST_cleanup(), GNUNET_DHT_TEST_cleanup(), handle_block(), handle_collect_result(), handle_data(), handle_revocation_union_request(), handle_stop(), handle_verify_result(), hello_callback(), host_habitable_cb(), host_registration_completion(), identity_cb(), identity_continuation(), identity_master_cb(), init_callback(), iteration_done(), list_callback(), logger_run(), main_init(), manage_service_cb(), monitor_cb(), mq_error_handler(), next_round(), operation_timeout(), path_callback(), peer_create_cb(), peer_init_handler(), peers_callback(), post_test_op(), post_test_shutdown_ready_cb(), print_finish(), print_query_result(), print_revocation_result(), process_lookup_result(), process_peer_string(), process_queue(), progress_cb(), put_cb(), read_stdio(), read_task(), reannounce_regex(), replace_cont(), reply_handle(), requester_callback(), responder_callback(), rps_connect_complete_cb(), run(), run_with_zone_pkey(), secret_ready_cb(), service_connect_comp(), session_disconnect_adapter(), set_result_cb(), show_peer(), shutdown_if_no_lifeness(), shutdown_pipe_cb(), shutdown_task(), slave_status_cb(), start_callback(), start_dump(), start_insert(), state_machine(), statistics_done(), statistics_done_cb(), stats_cb(), stdin_cb(), stop_callback(), stun_read_task(), switch_to_speaker(), term_callback(), test_finished(), test_master(), test_run(), testing_main(), timeout_task(), timeout_task_cb(), tokenizer_cb(), trigger_shutdown(), tunnels_callback(), uri_ksk_continuation(), uri_sks_continuation(), view_update_handle(), and zone_iteration_error().

525 {
526  struct GNUNET_SCHEDULER_Task *pos;
527 
529  "GNUNET_SCHEDULER_shutdown\n");
530  if (NULL != install_parent_control_task)
531  {
534  }
535  if (NULL != shutdown_pipe_task)
536  {
538  shutdown_pipe_task = NULL;
539  }
540  while (NULL != (pos = shutdown_head))
541  {
544  pos);
546  queue_ready_task (pos);
547  }
548 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_SCHEDULER_Task * shutdown_tail
Tail of list of tasks waiting for shutdown.
Definition: scheduler.c:332
static struct GNUNET_SCHEDULER_Task * install_parent_control_task
Task for installing parent control handlers (it might happen that the scheduler is shutdown before th...
Definition: scheduler.c:378
We are shutting down and are running all shutdown-related tasks.
static struct GNUNET_SCHEDULER_Task * shutdown_pipe_task
Task for reading from a pipe that signal handlers will use to initiate shutdown.
Definition: scheduler.c:384
enum GNUNET_SCHEDULER_Reason reason
Why is the task ready? Set after task is added to ready queue.
Definition: scheduler.c:198
static void queue_ready_task(struct GNUNET_SCHEDULER_Task *task)
Put a task that is ready for execution into the ready queue.
Definition: scheduler.c:505
#define LOG(kind,...)
Definition: scheduler.c:31
Entry in list of pending tasks.
Definition: scheduler.c:134
static struct GNUNET_SCHEDULER_Task * shutdown_head
Head of list of tasks waiting for shutdown.
Definition: scheduler.c:327
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:

◆ GNUNET_SCHEDULER_get_load()

unsigned int GNUNET_SCHEDULER_get_load ( enum GNUNET_SCHEDULER_Priority  p)

Get information about the current load of this scheduler.

Use this function to determine if an elective task should be added or simply dropped (if the decision should be made based on the number of tasks ready to run).

Parameters
ppriority-level to query, use KEEP to query the level of the current task, use COUNT to get the sum over all priority levels
Returns
number of tasks pending right now

Use this function to determine if an elective task should be added or simply dropped (if the decision should be made based on the number of tasks ready to run).

Parameters
ppriority level to look at
Returns
number of tasks pending right now

Definition at line 763 of file scheduler.c.

References check_priority(), current_priority, GNUNET_assert, GNUNET_SCHEDULER_PRIORITY_COUNT, GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_SCHEDULER_Task::next, ready_count, and ret.

764 {
765  struct GNUNET_SCHEDULER_Task *pos;
766  unsigned int ret;
767 
768  GNUNET_assert (NULL != active_task);
770  return ready_count;
773  ret = 0;
774  for (pos = ready_head[check_priority (p)]; NULL != pos; pos = pos->next)
775  ret++;
776  return ret;
777 }
static unsigned int ready_count
Number of tasks on the ready list.
Definition: scheduler.c:389
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Run with the same priority as the current job.
static struct GNUNET_SCHEDULER_Task * active_task
ID of the task that is running right now.
Definition: scheduler.c:361
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct GNUNET_SCHEDULER_Task * ready_head[GNUNET_SCHEDULER_PRIORITY_COUNT]
Head of list of tasks ready to run right now, grouped by importance.
Definition: scheduler.c:366
static enum GNUNET_SCHEDULER_Priority current_priority
Priority of the task running right now.
Definition: scheduler.c:395
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Definition: scheduler.c:139
static enum GNUNET_SCHEDULER_Priority check_priority(enum GNUNET_SCHEDULER_Priority p)
Check that the given priority is legal (and return it).
Definition: scheduler.c:448
Entry in list of pending tasks.
Definition: scheduler.c:134
Number of priorities (must be the last priority).
Here is the call graph for this function:

◆ GNUNET_SCHEDULER_get_task_context()

const struct GNUNET_SCHEDULER_TaskContext* GNUNET_SCHEDULER_get_task_context ( void  )

Obtain the reasoning why the current task was started.

Returns
task context with information why the current task is run

Obtain the reasoning why the current task was started.

Returns
current tasks' scheduler context

Definition at line 746 of file scheduler.c.

References GNUNET_assert, and tc.

Referenced by child_death_task(), cmd_read(), connect_probe_continuation(), do_read(), do_s5r_read(), do_udp_read(), maint_child_death(), process_listen_socket(), read_dns4(), read_dns6(), read_response(), receive_ready(), tcp_send(), transmit_ready(), udp_plugin_select_v4(), udp_plugin_select_v6(), unix_plugin_select_read(), and unix_plugin_select_write().

747 {
748  GNUNET_assert (NULL != active_task);
749  return &tc;
750 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
static struct GNUNET_SCHEDULER_Task * active_task
ID of the task that is running right now.
Definition: scheduler.c:361
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_cancel()

void* GNUNET_SCHEDULER_cancel ( struct GNUNET_SCHEDULER_Task task)

Cancel the task with the specified identifier.

The task must not yet have run. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
taskid of the task to cancel
Returns
original closure of the task

Definition at line 965 of file scheduler.c.

References GNUNET_SCHEDULER_Task::callback_cls, check_priority(), GNUNET_SCHEDULER_Driver::cls, GNUNET_SCHEDULER_Driver::del, destroy_task(), GNUNET_SCHEDULER_Task::fds, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_YES, GNUNET_SCHEDULER_Task::in_ready_list, LOG, GNUNET_SCHEDULER_Task::on_shutdown, p, GNUNET_SCHEDULER_Task::priority, ready_count, and ret.

Referenced by abort_all_requests(), abort_test(), adjust_running_peers(), announce_next_regex(), ats_perf_cb(), bi_destroy(), cadet_mq_cancel_impl(), calculate_pow_shutdown(), call_continuation(), call_master(), cancel_aps(), cancel_interrupt_task(), cancel_pending_req(), channel_destroy(), check_autoconfig_finished(), check_completed(), check_disconnect(), child_death_task(), clean_request(), cleaning_task(), cleanup(), cleanup_cth(), cleanup_handle(), cleanup_ncc(), cleanup_occ(), cleanup_rocc(), cleanup_rs(), cleanup_s5r(), cleanup_task(), cleanup_validation_entry(), client_connect(), client_delete_session(), client_disconnect_cb(), client_receive(), client_schedule(), client_wake_up(), connect_fail_continuation(), connect_probe_continuation(), connect_success_continuation(), connection_client_cancel_impl(), connection_client_destroy_impl(), connection_ready_cb(), consider_peer_activate(), consider_peer_destroy(), consider_sending_fc(), continuation_print(), continue_store_activity(), cummulative_ack(), curl_download_prepare(), curl_task_download(), data_sent_cb(), default_reply_handle(), destroy_ai(), destroy_channel(), destroy_iterator_cb(), destroy_peer(), destroy_pooled_connection(), destroy_sub(), destroy_tunnel(), discard_oldest_mc(), disconnect_cb(), disconnect_neighbour(), disconnect_notify(), dns_result_parser(), dns_result_processor(), do_abort(), do_cleanup(), do_error(), do_s5r_read(), do_shutdown(), do_stop_task(), do_suspend(), download_progress_cb(), expire_task_cancel(), free_active_lookup(), free_address_list_entry(), free_backtalker(), free_dv_route(), free_fragment_message(), free_macendpoint(), free_neighbour(), free_peer(), free_pending_request(), free_qe(), free_queue(), free_queue_entry(), free_tmps(), free_virtual_link(), GAS_preference_done(), GCC_destroy(), GCC_handle_connection_create_ack(), GCC_handle_duplicate_create(), GCC_transmit(), GCCH_bind(), GCCH_channel_local_destroy(), GCCH_handle_channel_open_ack(), GCCH_handle_channel_plaintext_data_ack(), GCCH_handle_local_data(), GCD_hello_update(), GCD_shutdown(), GCO_shutdown(), GCP_add_connection(), GCT_add_channel(), GCT_change_estate(), GCT_destroy_tunnel_now(), GCT_handle_encrypted(), GCT_handle_kx(), GCT_send(), GDS_CLIENTS_stop(), get_cadet(), get_iter(), get_request_socket(), GN_nat_status_changed(), GN_stop_gnunet_nat_server_(), GNS_resolver_lookup_cancel(), GNUNET_ARM_disconnect(), GNUNET_ARM_monitor_stop(), GNUNET_ATS_application_done(), GNUNET_ATS_connectivity_done(), GNUNET_ATS_performance_done(), GNUNET_ATS_scheduling_done(), GNUNET_ATS_solver_generate_preferences_stop(), GNUNET_ATS_solver_generate_property_stop(), GNUNET_ATS_solver_logging_free(), GNUNET_ATS_solver_logging_stop(), GNUNET_ATS_solvers_experimentation_stop(), GNUNET_ATS_TEST_experimentation_stop(), GNUNET_ATS_TEST_generate_preferences_stop(), GNUNET_ATS_TEST_generate_traffic_stop(), GNUNET_ATS_TEST_logging_stop(), GNUNET_ATS_transport_done(), GNUNET_BANDWIDTH_tracker_notification_stop(), GNUNET_CADET_disconnect(), GNUNET_CADET_get_channel_cancel(), GNUNET_CADET_get_path_cancel(), GNUNET_CADET_list_peers_cancel(), GNUNET_CADET_list_tunnels_cancel(), GNUNET_CONNECTION_destroy(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_CONNECTION_notify_transmit_ready_cancel(), GNUNET_CONNECTION_receive_cancel(), GNUNET_CORE_disconnect(), GNUNET_CREDENTIAL_disconnect(), GNUNET_CRYPTO_hash_file_cancel(), GNUNET_CURL_gnunet_rc_destroy(), GNUNET_CURL_gnunet_scheduler_reschedule(), GNUNET_DATASTORE_disconnect(), GNUNET_DEFRAGMENT_context_destroy(), GNUNET_DEFRAGMENT_process_fragment(), GNUNET_DHT_disconnect(), GNUNET_DNS_disconnect(), GNUNET_DNSSTUB_resolve_cancel(), GNUNET_FRAGMENT_context_destroy(), GNUNET_FRAGMENT_process_ack(), GNUNET_FS_dequeue_(), GNUNET_FS_directory_scan_abort(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), GNUNET_FS_publish_ksk_cancel(), GNUNET_FS_publish_signal_suspend_(), GNUNET_FS_publish_stop(), GNUNET_FS_publish_ublock_cancel_(), GNUNET_FS_queue_(), GNUNET_FS_search_pause(), GNUNET_FS_search_probe_progress_(), GNUNET_FS_search_signal_suspend_(), GNUNET_FS_search_start_searching_(), GNUNET_FS_search_stop(), GNUNET_FS_search_stop_probe_(), GNUNET_FS_stop(), GNUNET_FS_stop_probe_ping_task_(), GNUNET_GNS_disconnect(), GNUNET_HELPER_destroy(), GNUNET_HELPER_kill(), GNUNET_HELPER_send_cancel(), GNUNET_HELPER_wait(), GNUNET_HOSTLIST_client_stop(), GNUNET_HOSTLIST_server_stop(), GNUNET_IDENTITY_disconnect(), GNUNET_MQ_destroy(), GNUNET_NAMECACHE_disconnect(), GNUNET_NAMESTORE_disconnect(), GNUNET_NAT_AUTO_test_start(), GNUNET_NAT_AUTO_test_stop(), GNUNET_NAT_autoconfig_cancel(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_NAT_mini_map_stop(), GNUNET_NAT_test_start(), GNUNET_NAT_test_stop(), GNUNET_NAT_unregister(), GNUNET_NSE_disconnect(), GNUNET_NT_scanner_done(), GNUNET_OS_command_stop(), GNUNET_PEERINFO_disconnect(), GNUNET_PEERINFO_notify_cancel(), GNUNET_RECLAIM_disconnect(), GNUNET_RESOLVER_disconnect(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_destroy(), GNUNET_SERVER_disable_receive_done_warning(), GNUNET_SERVER_receive_done(), GNUNET_SERVER_stop_listening(), GNUNET_SERVER_suspend(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_disable_continue_warning(), GNUNET_SERVICE_client_drop(), GNUNET_SET_listen_cancel(), GNUNET_SPEEDUP_stop_(), GNUNET_STATISTICS_destroy(), GNUNET_TESTBED_is_host_habitable_cancel(), GNUNET_TESTBED_LOGGER_disconnect(), GNUNET_TESTBED_LOGGER_flush_cancel(), GNUNET_TRANSPORT_application_done(), GNUNET_TRANSPORT_core_disconnect(), GNUNET_TRANSPORT_core_get_mq(), GNUNET_TRANSPORT_hello_get_cancel(), GNUNET_TRANSPORT_manipulation_disconnect(), GNUNET_TRANSPORT_monitor_peers_cancel(), GNUNET_TRANSPORT_monitor_plugins_cancel(), GNUNET_TRANSPORT_TESTING_connect_peers_cancel(), gnunet_uri(), GNUNET_VPN_disconnect(), GSC_KX_done(), GSC_SESSIONS_confirm_typemap(), GSC_SESSIONS_end(), GSF_cadet_release_clients(), GSF_connected_peer_done_(), GSF_peer_disconnect_handler(), GSF_pending_request_cancel_(), GSF_plan_notify_peer_disconnect_(), GSF_push_done_(), GSF_put_done_(), GST_blacklist_test_cancel(), GST_clear_fopcq(), GST_connection_pool_get_handle_done(), GST_forwarded_operation_reply_relay(), GST_free_lcf(), GST_hello_stop(), GST_manipulation_peer_disconnect(), GST_manipulation_stop(), GST_neighbour_get_connection_cancel(), GST_neighbours_send(), GST_neighbours_session_terminated(), GST_neighbours_stop(), GST_notify_client_disconnect_oc(), GST_notify_client_disconnect_peers(), GST_stats_destroy(), GST_validation_set_address_use(), handle_announce(), handle_core_disconnect(), handle_dht_local_get(), handle_disconnect_confirm(), handle_dns_response(), handle_encrypted(), handle_external_ip(), handle_flow_control(), handle_incoming_msg(), handle_monitor_next(), handle_p2p_estimate(), handle_plaintext_channel_open(), handle_pong(), handle_stream_input(), handle_stun(), handle_tcp_nat_probe(), handle_transport_notify_disconnect(), http_client_plugin_send(), http_client_plugin_session_disconnect(), http_client_plugin_update_inbound_delay(), http_server_plugin_update_inbound_delay(), incoming_channel(), incoming_destroy(), insert_sorted(), kill_httpd(), LEGACY_SERVICE_stop(), libgnunet_plugin_ats_ril_done(), LIBGNUNET_PLUGIN_TRANSPORT_DONE(), libgnunet_plugin_transport_http_client_done(), libgnunet_plugin_transport_http_server_done(), libgnunet_plugin_transport_udp_done(), libgnunet_plugin_transport_unix_done(), maint_child_death(), manage_first_hop_mq(), mhd_log_callback(), monitor_unblock(), mq_cancel(), mq_error_handler(), neighbour_connect_cb(), neighbour_delete(), notify_connect(), numeric_reverse(), occ_cache_get_handle_ats_occ_cb(), occ_cache_get_handle_core_cb(), oprelease_get_stats(), outbound_bw_tracker_update(), overlay_connect_get_config(), overlay_connect_notify(), p1_transport_connect_cache_callback(), p2_transport_connect_cache_callback(), parent_control_handler(), peer_free(), plugin_env_session_end(), post_test_op(), primary_task(), process_job_queue(), process_local_reply(), process_peer_iteration_cb(), process_peer_monitoring_cb(), process_peer_string(), process_queue(), process_stat_done(), publish_progress_cb(), queue_destroy(), rc_cleanup_operations(), reconnect(), reconnect_later(), reconstruct_cont(), refresh_hello(), refresh_timeout_task(), regex_found_handler(), remove_channel_ctx(), remove_stream_request(), reschedule_hellos(), reset_cadet_async(), RPS_sampler_request_cancel(), RPS_sampler_request_single_info_cancel(), rq_remove(), run(), run_httpd_now(), run_mhd_now(), schedule_current_round(), schedule_httpd(), schedule_next_hello(), schedule_read(), schedule_select_v4(), schedule_select_v6(), schedule_transmit_on_queue(), search_result_freeze_probes(), select_read_cb(), send_disconnect_cont(), send_key(), send_push(), send_response(), server_delete_session(), server_reschedule(), server_schedule(), server_stop(), service_mq_cancel(), set_state_and_timeout(), shutdown_op(), shutdown_pch(), shutdown_task(), signal_transmit_error(), slave_event_cb(), start_process(), start_test(), start_typemap_task(), statistics_da(), stats_cont(), stop_broadcast(), stop_helper(), stop_stun(), switch_to_speaker(), tcp_plugin_disconnect_session(), tcp_plugin_update_inbound_delay(), teardown_service(), terminate_ac_activities(), terminate_task(), test_master(), test_nat_punched(), test_run(), timeout_episode(), timeout_experiment(), transmit_ready(), transmit_send_continuation(), transport_addr_to_str_cb(), trigger_flush_notification(), try_transmission(), udp_disconnect_session(), unix_plugin_session_disconnect(), update_backtalker_monotime(), update_excess(), update_flood_times(), update_next_challenge_time(), update_timeout(), wlan_plugin_disconnect_session(), and zone_iteration_error().

966 {
968  int is_fd_task;
969  void *ret;
970 
972  "canceling task %p\n",
973  task);
974 
975  /* scheduler must be running */
977  is_fd_task = (NULL != task->fds);
978  if (is_fd_task)
979  {
980  int del_result = scheduler_driver->del (scheduler_driver->cls, task);
981  if (GNUNET_OK != del_result)
982  {
984  "driver could not delete task\n");
985  GNUNET_assert (0);
986  }
987  }
988  if (! task->in_ready_list)
989  {
990  if (is_fd_task)
991  {
993  pending_tail,
994  task);
995  }
996  else if (GNUNET_YES == task->on_shutdown)
997  {
1000  task);
1001  }
1002  else
1003  {
1006  task);
1007  if (pending_timeout_last == task)
1008  pending_timeout_last = NULL;
1009  }
1010  }
1011  else
1012  {
1013  p = check_priority (task->priority);
1015  ready_tail[p],
1016  task);
1017  ready_count--;
1018  }
1019  ret = task->callback_cls;
1020  destroy_task (task);
1021  return ret;
1022 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static unsigned int ready_count
Number of tasks on the ready list.
Definition: scheduler.c:389
static struct GNUNET_SCHEDULER_Task * shutdown_tail
Tail of list of tasks waiting for shutdown.
Definition: scheduler.c:332
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int on_shutdown
Is this task run on shutdown?
Definition: scheduler.c:224
static struct GNUNET_SCHEDULER_Task * pending_timeout_tail
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:350
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_SCHEDULER_Task * pending_head
Head of list of tasks waiting for an event.
Definition: scheduler.c:317
GNUNET_SCHEDULER_Priority
Valid task priorities.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_SCHEDULER_Task * pending_timeout_last
Last inserted task waiting ONLY for a timeout event.
Definition: scheduler.c:356
static struct GNUNET_SCHEDULER_Task * pending_tail
Tail of list of tasks waiting for an event.
Definition: scheduler.c:322
static struct GNUNET_SCHEDULER_Task * ready_tail[GNUNET_SCHEDULER_PRIORITY_COUNT]
Tail of list of tasks ready to run right now, grouped by importance.
Definition: scheduler.c:371
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct GNUNET_SCHEDULER_Task * pending_timeout_head
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:341
static struct GNUNET_SCHEDULER_Task * ready_head[GNUNET_SCHEDULER_PRIORITY_COUNT]
Head of list of tasks ready to run right now, grouped by importance.
Definition: scheduler.c:366
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
struct GNUNET_SCHEDULER_FdInfo * fds
Information about which FDs are ready for this task (and why).
Definition: scheduler.c:159
void * callback_cls
Closure for the callback.
Definition: scheduler.c:154
#define LOG(kind,...)
Definition: scheduler.c:31
static void destroy_task(struct GNUNET_SCHEDULER_Task *t)
Destroy a task (release associated resources)
Definition: scheduler.c:578
static enum GNUNET_SCHEDULER_Priority check_priority(enum GNUNET_SCHEDULER_Priority p)
Check that the given priority is legal (and return it).
Definition: scheduler.c:448
void * cls
Closure to pass to the functions in this struct.
#define GNUNET_YES
Definition: gnunet_common.h:80
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
static struct GNUNET_SCHEDULER_Task * shutdown_head
Head of list of tasks waiting for shutdown.
Definition: scheduler.c:327
int in_ready_list
Is this task in the ready list?
Definition: scheduler.c:229
int(* del)(void *cls, struct GNUNET_SCHEDULER_Task *task)
Delete a task from the set of tasks to be run.
Here is the call graph for this function:

◆ GNUNET_SCHEDULER_add_with_reason_and_priority()

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.

This is similar to the other "add" functions except that there is no delay and the reason code can be specified.

Parameters
taskmain function of the task
task_clsclosure for task
reasonreason for task invocation
prioritypriority to use for the task

Definition at line 1059 of file scheduler.c.

References GNUNET_SCHEDULER_Task::callback, GNUNET_SCHEDULER_Task::callback_cls, check_priority(), current_lifeness, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_TIME_absolute_get(), init_backtrace(), GNUNET_SCHEDULER_Task::lifeness, LOG, GNUNET_SCHEDULER_Task::priority, queue_ready_task(), GNUNET_SCHEDULER_Task::read_fd, GNUNET_SCHEDULER_Task::reason, t, and GNUNET_SCHEDULER_Task::write_fd.

Referenced by GNUNET_SCHEDULER_run().

1063 {
1064  struct GNUNET_SCHEDULER_Task *t;
1065 
1066  /* scheduler must be running */
1067  GNUNET_assert (NULL != scheduler_driver);
1068  GNUNET_assert (NULL != task);
1069  t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1070  t->read_fd = -1;
1071  t->write_fd = -1;
1072  t->callback = task;
1073  t->callback_cls = task_cls;
1074 #if PROFILE_DELAYS
1075  t->start_time = GNUNET_TIME_absolute_get ();
1076 #endif
1077  t->reason = reason;
1081  "Adding continuation task %p\n",
1082  t);
1083  init_backtrace (t);
1084  queue_ready_task (t);
1085 }
int read_fd
Set if we only wait for reading from a single FD, otherwise -1.
Definition: scheduler.c:208
GNUNET_SCHEDULER_TaskCallback callback
Function to run when ready.
Definition: scheduler.c:149
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void init_backtrace(struct GNUNET_SCHEDULER_Task *t)
Initialize backtrace data for task t.
Definition: scheduler.c:1031
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * t
Main task.
int write_fd
Set if we only wait for writing to a single FD, otherwise -1.
Definition: scheduler.c:213
static int current_lifeness
Value of the 'lifeness' flag for the current task.
Definition: scheduler.c:406
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void * callback_cls
Closure for the callback.
Definition: scheduler.c:154
enum GNUNET_SCHEDULER_Reason reason
Why is the task ready? Set after task is added to ready queue.
Definition: scheduler.c:198
static void queue_ready_task(struct GNUNET_SCHEDULER_Task *task)
Put a task that is ready for execution into the ready queue.
Definition: scheduler.c:505
#define LOG(kind,...)
Definition: scheduler.c:31
static enum GNUNET_SCHEDULER_Priority check_priority(enum GNUNET_SCHEDULER_Priority p)
Check that the given priority is legal (and return it).
Definition: scheduler.c:448
Entry in list of pending tasks.
Definition: scheduler.c:134
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_with_priority()

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.

Parameters
priohow important is the new task?
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1200 of file scheduler.c.

References GNUNET_SCHEDULER_add_delayed_with_priority(), and GNUNET_TIME_UNIT_ZERO.

Referenced by begin_service(), block_proc(), deserialize_publish_file(), ds_put_cont(), encode_cont(), file_hash_task(), finish_reserve(), GNUNET_CRYPTO_hash_file(), GNUNET_FS_publish_start(), GSF_connected_peer_init_(), maint_child_death(), publish_kblocks_cont(), run(), and schedule_transmit_on_queue().

1203 {
1205  prio,
1206  task,
1207  task_cls);
1208 }
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:1178
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_now()

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.

Note that this does not guarantee that this will be the next task that is being run, as other tasks with higher priority (or that are already ready to run) might get to run first. Just as with delays, clients must not rely on any particular order of execution between tasks scheduled concurrently.

The task will be run with the DEFAULT priority.

Parameters
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1273 of file scheduler.c.

References GNUNET_SCHEDULER_add_delayed(), and GNUNET_TIME_UNIT_ZERO.

Referenced by abort_test(), add_attribute_cont(), add_continuation(), add_valid_address(), advertise_dns_exit(), announce_regex(), ats_connect_completion_cb(), ats_perf_cb(), attr_delete_cont(), attr_store_cont(), authorize_endpoint(), build_authz_response(), build_redirect(), cadet_mq_send_impl(), calculate_pow(), check_autoconfig_finished(), child_death_task(), cleanup_task(), client_connect(), client_disconnect_cb(), client_response_handler(), code_redirect(), collect_cred_cont(), collect_finished_cb(), comm_connect_completion_cb(), conclude_cb(), connect_cb(), connection_ready(), consume_cont(), consume_ticket(), consume_ticket_cont(), continuation_print(), continue_with_gns2dns(), controller_status_cb(), core_startup_cb(), create_download_context(), create_finished(), default_reply_handle(), del_attr_finished(), del_finished(), delete_attribute_cont(), delete_finished_cb(), deserialize_download(), disconnect_notify(), dns_result_parser(), do_abort(), do_announce(), do_error(), do_finished(), do_reconnect(), do_redirect_error(), do_userinfo_error(), download_progress_cb(), download_timeout(), dump_pc(), ego_callback(), ego_create(), ego_delete_name(), ego_delete_pubkey(), ego_edit(), ego_edit_name(), ego_edit_pubkey(), ego_edit_subsystem(), ego_get_all(), ego_get_for_subsystem(), ego_get_name(), ego_get_pubkey(), ego_get_response(), ego_get_subsystem(), experiment_done_cb(), fail_resolution(), find_timed_out(), finish_profiler(), finish_round(), finished_cont(), free_dv_route(), free_neighbour(), gather_dht_put_blocks(), GCCH_bind(), GCCH_channel_local_destroy(), GCCH_handle_duplicate_open(), GCCH_tunnel_up(), GCP_attach_path(), GCT_change_estate(), GCT_create_tunnel(), GCT_handle_encrypted(), GCT_handle_kx(), GCT_send(), get_cont(), get_cred_issuer_cb(), get_gns_cont(), GN_nat_status_changed(), GNS_resolver_lookup(), GNS_resolver_lookup_cancel(), GNUNET_ARM_request_service_start(), GNUNET_ATS_solver_generate_preferences_start(), GNUNET_ATS_solver_generate_property_start(), GNUNET_ATS_solver_logging_start(), GNUNET_ATS_TEST_generate_preferences_start(), GNUNET_ATS_TEST_generate_traffic_start(), GNUNET_ATS_TEST_logging_start(), GNUNET_ATS_TEST_traffic_handle_pong(), GNUNET_CLIENT_connect(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_CURL_gnunet_scheduler_reschedule(), GNUNET_DNS_connect(), GNUNET_DNSSTUB_resolve(), GNUNET_FRAGMENT_context_create(), GNUNET_FRAGMENT_process_ack(), GNUNET_FS_dequeue_(), GNUNET_FS_download_start_task_(), GNUNET_FS_publish_ksk(), GNUNET_FS_publish_ublock_(), GNUNET_FS_queue_(), GNUNET_FS_search_probe_progress_(), GNUNET_HOSTLIST_client_start(), GNUNET_MQ_impl_send_continue(), GNUNET_NAT_AUTO_test_start(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_test_start(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_SCHEDULER_add_now_with_lifeness(), GNUNET_SCHEDULER_driver_init(), GNUNET_SERVER_receive_done(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_TRANSPORT_TESTING_connect_peers(), GSF_plan_add_(), GSF_put_init_(), GST_blacklist_test_allowed(), GST_connection_pool_get_handle(), GST_neighbours_handle_disconnect_message(), GST_neighbours_send(), GST_neighbours_session_terminated(), GST_stats_init(), GST_validation_handle_address(), GST_validation_set_address_use(), handle_add_address(), handle_add_queue_message(), handle_attribute_store_message(), handle_client_blacklist_reply(), handle_collect_response(), handle_core_connect(), handle_cred_collection_cb(), handle_dht_local_get(), handle_disconnect_confirm(), handle_gns_cname_result(), handle_gns_resolution_result(), handle_gns_response(), handle_helper_message(), handle_link_controllers(), handle_local_ack(), handle_monitor_next(), handle_monitor_start(), handle_p2p_estimate(), handle_p2p_reply(), handle_stop(), handle_stream_input(), handle_verify_response(), handler_advertisement(), hello_callback(), host_registration_completion(), identity_cb(), iface_proc(), init_callback(), init_cont(), iter_error(), iter_finished(), iteration_completion_cb(), kb_put_cont(), kill_session(), lcf_forwarded_operation_timeout(), lcf_proc_cc(), lcf_proc_task(), libgnunet_plugin_transport_unix_init(), list_attribute_cont(), list_callback(), list_tickets_cont(), login_cont(), login_redirect(), lookup_hole_external(), lookup_redirect_uri_result(), main_task(), message_sent_cont(), monitor_iterate_cb(), mq_init(), namestore_add(), namestore_delete(), namestore_get(), namestore_iteration_error(), namestore_list_finished(), new_sub(), next_rnd(), notify_disconnect(), ns_lookup_cb(), ns_lookup_error_cb(), occ_cache_get_handle_ats_occ_cb(), occ_cache_get_handle_core_cb(), oidc_collect_finished_cb(), oidc_iteration_error(), oidc_ticket_issue_cb(), opstart_get_handle_transport(), options_cont(), overlay_connect_get_config(), overlay_connect_notify(), p1_transport_connect_cache_callback(), p2_transport_connect(), p2_transport_connect_cache_callback(), parse_hello_uri(), peer_create_cb(), peerinfo_list_finished(), peerinfo_list_iteration(), peerinformation_cb(), primary_task(), print_my_uri(), print_peer_info(), process_attrs(), process_delete(), process_dht_put_content(), process_helper_msgs(), process_result(), process_rq_task(), process_rvk(), process_stdin(), progress_cb(), publish_progress_cb(), put_cont(), queue_read_kx(), reconnect_later(), reconstruct_cb(), recursive_dns_resolution(), recursive_gns2dns_resolution(), recursive_pkey_resolution(), refresh_hello(), regex_found_handler(), regex_iterator(), report_success(), reschedule_hellos(), reset_cadet_async(), rest_config_process_request(), rest_copying_process_request(), rest_credential_process_request(), revoke_ticket_cont(), rocc_cache_get_handle_transport_cb(), RPS_sampler_get_n_rand_peers(), RPS_sampler_get_rand_peer_info(), rq_add(), run(), run_httpd_now(), run_mhd_now(), rvk_move_attr_cb(), rvk_ticket_update_finished(), schedule_channel_destruction(), schedule_next_hello(), schedule_next_task(), search_timed_out(), send_disconnect_cont(), send_push(), server_configure_plugin(), setup_neighbour(), setup_sender(), shutdown_task(), simple_session_del(), slave_event_cb(), start_callback(), start_probe_ping_task(), start_process(), start_resolver_lookup(), stat_timeout_task(), state_machine(), stats_cont(), stop_callback(), store_attr_cont(), store_completed_cb(), subject_ego_lookup(), task_check(), term_callback(), test_connection_ok(), test_icmp_server(), test_master(), test_monitor_clients(), ticket_issue_cb(), ticket_iter_err(), ticket_iter_fin(), ticket_processed(), ticket_updated(), timeout_task(), token_endpoint(), transmit_send_continuation(), transport_addr_to_str_cb(), trigger_flush_notification(), trigger_notifications(), userinfo_endpoint(), verify_cred_cont(), watch_cb(), zone_iteration_error(), and zone_iteration_finished().

1275 {
1277  task,
1278  task_cls);
1279 }
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:1246
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Here is the call graph for this function:

◆ GNUNET_SCHEDULER_add_shutdown()

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.

Parameters
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1293 of file scheduler.c.

References GNUNET_SCHEDULER_Task::callback, GNUNET_SCHEDULER_Task::callback_cls, GNUNET_assert, GNUNET_async_scope_get(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_PRIORITY_SHUTDOWN, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_YES, init_backtrace(), GNUNET_SCHEDULER_Task::lifeness, LOG, GNUNET_SCHEDULER_Task::on_shutdown, GNUNET_SCHEDULER_Task::priority, GNUNET_SCHEDULER_Task::read_fd, GNUNET_SCHEDULER_Task::scope, t, GNUNET_SCHEDULER_Task::timeout, and GNUNET_SCHEDULER_Task::write_fd.

Referenced by communicator_start(), connect_check_run(), ego_callback(), GNUNET_OS_install_parent_control_handler(), GNUNET_TESTBED_run(), init_cb(), interrupt(), logger_run(), main_init(), main_run(), main_task(), program_main(), run(), service_main(), service_task(), setup_ac(), shutdown_task(), terminate_task(), test_master(), test_run(), testbed_run(), testing_main(), tmain(), topology_setup_done(), and transport_communicator_start().

1295 {
1296  struct GNUNET_SCHEDULER_Task *t;
1297 
1298  /* scheduler must be running */
1299  GNUNET_assert (NULL != scheduler_driver);
1300  GNUNET_assert (NULL != task);
1301  t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1303  t->callback = task;
1304  t->callback_cls = task_cls;
1305  t->read_fd = -1;
1306  t->write_fd = -1;
1307 #if PROFILE_DELAYS
1308  t->start_time = GNUNET_TIME_absolute_get ();
1309 #endif
1312  t->on_shutdown = GNUNET_YES;
1313  t->lifeness = GNUNET_NO;
1315  shutdown_tail,
1316  t);
1318  "Adding shutdown task %p\n",
1319  t);
1320  init_backtrace (t);
1321  return t;
1322 }
int read_fd
Set if we only wait for reading from a single FD, otherwise -1.
Definition: scheduler.c:208
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
GNUNET_SCHEDULER_TaskCallback callback
Function to run when ready.
Definition: scheduler.c:149
static struct GNUNET_SCHEDULER_Task * shutdown_tail
Tail of list of tasks waiting for shutdown.
Definition: scheduler.c:332
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void init_backtrace(struct GNUNET_SCHEDULER_Task *t)
Initialize backtrace data for task t.
Definition: scheduler.c:1031
int on_shutdown
Is this task run on shutdown?
Definition: scheduler.c:224
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * t
Main task.
int write_fd
Set if we only wait for writing to a single FD, otherwise -1.
Definition: scheduler.c:213
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void * callback_cls
Closure for the callback.
Definition: scheduler.c:154
This is an internal priority level that is only used for tasks that are being triggered due to shutdo...
#define LOG(kind,...)
Definition: scheduler.c:31
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_TIME_Absolute timeout
Absolute timeout value for the task, or GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout".
Definition: scheduler.c:184
#define GNUNET_YES
Definition: gnunet_common.h:80
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
struct GNUNET_AsyncScopeSave scope
Asynchronous scope of the task that scheduled this scope,.
Definition: scheduler.c:247
static struct GNUNET_SCHEDULER_Task * shutdown_head
Head of list of tasks waiting for shutdown.
Definition: scheduler.c:327
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_now_with_lifeness()

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 explicitly set or explicitly enabled.

This task (and all tasks created from it, other than by another call to this function) will either count or not count for the 'lifeness' of the process. This API is only useful in a few special cases.

Parameters
lifenessGNUNET_YES if the task counts for lifeness, GNUNET_NO if not.
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

This task (and all tasks created from it, other than by another call to this function) will either count or not count for the "lifeness" of the process. This API is only useful in a few special cases.

Parameters
lifenessGNUNET_YES if the task counts for lifeness, GNUNET_NO if not.
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1340 of file scheduler.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_SCHEDULER_add_now(), init_backtrace(), GNUNET_SCHEDULER_Task::lifeness, LOG, ret, and t.

Referenced by GNUNET_SPEEDUP_start_().

1343 {
1344  struct GNUNET_SCHEDULER_Task *ret;
1345 
1346  ret = GNUNET_SCHEDULER_add_now (task, task_cls);
1347  ret->lifeness = lifeness;
1348  return ret;
1349 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:1273
Entry in list of pending tasks.
Definition: scheduler.c:134
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_delayed()

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.

The task will be scheduled for execution once the delay has expired. It will be run with the DEFAULT priority.

Parameters
delaywith which the operation should be run
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

The task will be scheduled for execution once the delay has expired. It will be run with the DEFAULT priority.

Parameters
delaywhen should this operation time out?
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1246 of file scheduler.c.

References GNUNET_SCHEDULER_add_delayed_with_priority(), and GNUNET_SCHEDULER_PRIORITY_DEFAULT.

Referenced by add_to_lru(), age_cover_counters(), announce_id(), announce_next_regex(), ats_reserve_callback(), attempt_connect_task(), channel_new_cb(), channel_open_sent_cb(), check_disconnect(), check_timeouts(), check_zone_namestore_next(), churn(), churn_test_cb(), cleanup_expired_records(), client_connect_cb(), client_receive(), client_send_cb(), client_session_timeout(), collect_cred_cont(), collect_log_task(), connect_check_run(), connect_fail_continuation(), connection_ready_cb(), consider_gathering(), consider_peer_destroy(), consider_sending_fc(), continue_store_activity(), create_macendpoint(), create_session(), cron_clean_data_hosts(), curl_download_prepare(), daemon_started(), delay_warning(), delayed_get(), dht_connected(), disconnect_and_schedule_reconnect(), disconnect_neighbour(), dns_pre_request_handler(), do_broadcast(), do_dht_put(), do_disconnect(), do_reconnect(), do_refresh(), do_rekey(), do_round(), do_speedup(), error_handler(), expire_records_continuation(), find_string(), find_validation_entry(), force_reconnect(), forward_overlay_connect(), GCC_handle_connection_create_ack(), GCCH_channel_incoming_new(), GCD_hello_update(), GCD_init(), GCT_remove_channel(), get_addresses(), get_cadet(), GNUNET_ATS_solver_generate_preferences_start(), GNUNET_ATS_solvers_experimentation_run(), GNUNET_ATS_TEST_experimentation_run(), GNUNET_ATS_TEST_traffic_handle_pong(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_DEFRAGMENT_process_fragment(), GNUNET_FS_search_probe_progress_(), GNUNET_FS_TEST_download(), GNUNET_FS_TEST_publish(), GNUNET_HOSTLIST_client_start(), GNUNET_NAMESTORE_records_store(), GNUNET_NAT_mini_map_start(), GNUNET_NAT_test_start(), GNUNET_NT_scanner_init(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_SCHEDULER_add_now(), GNUNET_SERVER_inject(), GNUNET_STATISTICS_destroy(), GNUNET_TESTBED_is_host_habitable(), GNUNET_TESTBED_run(), GSC_KX_init(), GSF_cadet_query_cancel(), GST_ats_block_address(), GST_manipulation_send(), GST_neighbours_start(), GST_process_next_focc(), habitability_check(), handle_announce(), handle_autoconfig_request(), handle_barrier_init(), handle_client_listener_error(), handle_connection_create(), handle_core_connect(), handle_data(), handle_external_ip(), handle_fragment_box(), handle_link_controllers(), handle_manage_peer_service(), handle_monitor_next(), handle_mq_error(), handle_overlay_connect(), handle_p2p_migration_stop(), handle_p2p_reply(), handle_peer_create(), handle_peer_destroy(), handle_peer_get_config(), handle_peer_reconfigure(), handle_peer_start(), handle_peer_stop(), handle_remote_overlay_connect(), handle_request(), handle_stun(), handle_tcp_data(), handle_transport_notify_connect(), handler_advertisement(), hello_offered(), helper_read(), helper_write(), http_client_plugin_get_session(), http_client_plugin_update_inbound_delay(), http_server_plugin_update_inbound_delay(), ifc_broadcast(), incoming_channel(), issue_cred_cont(), iter_finished(), keepalive_done(), lcf_proc_task(), learn_dv_path(), logging_task(), lookup_authz_cb(), macendpoint_timeout(), main_init(), maintain_connections_cb(), mal_cb(), manage_first_hop_mq(), master_task(), monitor_unblock(), mq_error_handler(), next_rnd(), notify_send_done(), odc_warn_delay_task(), outbound_bw_tracker_update(), peer_id_cb(), peerstore_store_own_cb(), preference_aging(), probe_ping_task_cb(), process_external_ip(), process_job_queue(), process_local_reply(), process_map_output(), process_peer_iteration_cb(), process_peer_monitoring_cb(), process_queue(), process_requests(), profiler_cb(), queue_timeout(), reannounce(), reannounce_regex(), reconnect(), reconnect_arm_later(), reconnect_arm_monitor_later(), reconnect_later(), reconnect_peer_ctx(), reconnect_plugin_ctx(), recursive_dns_resolution(), refresh_hello_task(), refresh_timeout_task(), reschedule_connect(), resolve_and_cache(), rest_identity_process_request(), rest_process_request(), revalidate_address(), revive_migration(), ril_step_schedule_next(), run(), run_external_ip(), run_round(), run_scan(), sample_load_task(), schedule_current_round(), schedule_httpd(), schedule_missing_requests(), schedule_next_hello(), schedule_next_put(), schedule_next_task(), schedule_reconnect(), send_create_ack(), send_find_peer_message(), send_hello(), send_hello_beacon(), send_keep_alive(), send_keepalive(), send_key(), send_push(), send_with_fragmentation(), server_access_cb(), server_lookup_connection(), server_session_timeout(), service_client_mst_cb(), session_timeout(), set_feedback_task(), set_pref_task(), set_prop_task(), setup_data_transfer(), setup_queue(), start_cb(), start_dv_learn(), start_helper(), start_local_query(), start_test(), start_typemap_task(), store_pi(), suggest_start_cb(), switch_to_speaker(), task_check(), task_download_dispatcher(), task_hostlist_saving(), tcp_plugin_get_session(), tcp_plugin_update_inbound_delay(), test_master(), test_run(), timeout_episode(), timeout_hello_validation(), tmain(), tmt_rdy_ping(), topology_setup_done(), transmit_cummulative_ack_cb(), transmit_next(), transmit_query(), transmit_task_cb(), transmit_typemap_task(), try_again(), try_reconnect(), udp_ipv4_broadcast_send(), udp_ipv6_broadcast_send(), udp_plugin_create_session(), unix_plugin_get_session(), update_excess(), update_flood_message(), update_flood_times(), update_preference(), update_timeout(), update_zoneinfo_page(), utilization_transmission(), verify_cred_cont(), warn_delay_task(), warn_monitor_slow(), warn_no_client_continue(), warn_no_receive_done(), work(), and zone_iteration_finished().

1249 {
1252  task,
1253  task_cls);
1254 }
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:1178
Run with the default priority (normal P2P operations).
Here is the call graph for this function:

◆ GNUNET_SCHEDULER_add_at()

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.

The task will be scheduled for execution once specified time has been reached. It will be run with the DEFAULT priority.

Parameters
attime at which this operation should run
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1223 of file scheduler.c.

References GNUNET_SCHEDULER_add_at_with_priority(), and GNUNET_SCHEDULER_PRIORITY_DEFAULT.

Referenced by activate_core_visible_dv_path(), backtalker_monotime_store_cb(), backtalker_timeout_cb(), check_link_down(), connection_ready_cb(), core_init(), cummulative_ack(), data_sent_cb(), GCC_handle_duplicate_create(), GCCH_handle_channel_plaintext_data_ack(), GCT_add_channel(), GCT_handle_kx_auth(), GNUNET_FRAGMENT_context_transmission_done(), GST_manipulation_peer_disconnect(), handle_dv_box(), handle_validation_response(), insert_sorted(), manage_first_hop_mq(), path_cleanup_cb(), process_queue(), reassembly_cleanup_task(), schedule_peer_transmission(), send_delayed(), set_state_and_timeout(), timeout_cb(), transmit_next_request_task(), try_transmission(), update_flood_message(), and update_next_challenge_time().

1226 {
1229  task,
1230  task_cls);
1231 }
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:1100
Run with the default priority (normal P2P operations).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_delayed_with_priority()

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.

The task will be scheduled for execution once the delay has expired.

Parameters
delaywhen should this operation time out?
prioritypriority to use for the task
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1178 of file scheduler.c.

References GNUNET_SCHEDULER_add_at_with_priority(), and GNUNET_TIME_relative_to_absolute().

Referenced by cron_flush_respect(), cron_scan_directory_data_hosts(), delayed_restart_task(), expired_processor(), find_proof(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_select(), and GNUNET_SCHEDULER_add_with_priority().

1182 {
1184  priority,
1185  task,
1186  task_cls);
1187 }
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:1100
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_at_with_priority()

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.

The task will be scheduled for execution at time at.

Parameters
attime when the operation should run
prioritypriority to use for the task
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1100 of file scheduler.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_SCHEDULER_Task::callback, GNUNET_SCHEDULER_Task::callback_cls, check_priority(), current_lifeness, GNUNET_assert, GNUNET_async_scope_get(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_after, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_TIME_absolute_get(), init_backtrace(), GNUNET_SCHEDULER_Task::lifeness, LOG, GNUNET_SCHEDULER_Task::next, pending_timeout_head, pending_timeout_last, GNUNET_SCHEDULER_Task::prev, GNUNET_SCHEDULER_Task::priority, GNUNET_SCHEDULER_Task::read_fd, GNUNET_SCHEDULER_Task::scope, t, GNUNET_SCHEDULER_Task::timeout, and GNUNET_SCHEDULER_Task::write_fd.

Referenced by GNUNET_SCHEDULER_add_at(), and GNUNET_SCHEDULER_add_delayed_with_priority().

1104 {
1105  struct GNUNET_SCHEDULER_Task *t;
1106  struct GNUNET_SCHEDULER_Task *pos;
1107  struct GNUNET_SCHEDULER_Task *prev;
1108 
1109  /* scheduler must be running */
1110  GNUNET_assert (NULL != scheduler_driver);
1111  GNUNET_assert (NULL != task);
1112  t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1114  t->callback = task;
1115  t->callback_cls = task_cls;
1116  t->read_fd = -1;
1117  t->write_fd = -1;
1118 #if PROFILE_DELAYS
1119  t->start_time = GNUNET_TIME_absolute_get ();
1120 #endif
1121  t->timeout = at;
1124  /* try tail first (optimization in case we are
1125  * appending to a long list of tasks with timeouts) */
1126  if ( (NULL == pending_timeout_head) ||
1128  {
1131  t);
1132  }
1133  else
1134  {
1135  /* first move from heuristic start backwards to before start time */
1136  prev = pending_timeout_last;
1137  while ( (NULL != prev) &&
1138  (prev->timeout.abs_value_us > t->timeout.abs_value_us) )
1139  prev = prev->prev;
1140  /* now, move from heuristic start (or head of list) forward to insertion point */
1141  if (NULL == prev)
1142  pos = pending_timeout_head;
1143  else
1144  pos = prev->next;
1145  while ((NULL != pos) && (pos->timeout.abs_value_us <= t->timeout.abs_value_us))
1146  {
1147  prev = pos;
1148  pos = pos->next;
1149  }
1152  prev,
1153  t);
1154  }
1155  /* finally, update heuristic insertion point to last insertion... */
1157 
1159  "Adding task %p\n",
1160  t);
1161  init_backtrace (t);
1162  return t;
1163 }
int read_fd
Set if we only wait for reading from a single FD, otherwise -1.
Definition: scheduler.c:208
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
GNUNET_SCHEDULER_TaskCallback callback
Function to run when ready.
Definition: scheduler.c:149
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void init_backtrace(struct GNUNET_SCHEDULER_Task *t)
Initialize backtrace data for task t.
Definition: scheduler.c:1031
struct GNUNET_SCHEDULER_Task * prev
This is a linked list.
Definition: scheduler.c:144
static struct GNUNET_SCHEDULER_Task * pending_timeout_tail
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:350
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * t
Main task.
uint64_t abs_value_us
The actual value.
static struct GNUNET_SCHEDULER_Task * pending_timeout_last
Last inserted task waiting ONLY for a timeout event.
Definition: scheduler.c:356
int write_fd
Set if we only wait for writing to a single FD, otherwise -1.
Definition: scheduler.c:213
static int current_lifeness
Value of the &#39;lifeness&#39; flag for the current task.
Definition: scheduler.c:406
static struct GNUNET_SCHEDULER_Task * pending_timeout_head
List of tasks waiting ONLY for a timeout event.
Definition: scheduler.c:341
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void * callback_cls
Closure for the callback.
Definition: scheduler.c:154
#define LOG(kind,...)
Definition: scheduler.c:31
struct GNUNET_SCHEDULER_Task * next
This is a linked list.
Definition: scheduler.c:139
static enum GNUNET_SCHEDULER_Priority check_priority(enum GNUNET_SCHEDULER_Priority p)
Check that the given priority is legal (and return it).
Definition: scheduler.c:448
Entry in list of pending tasks.
Definition: scheduler.c:134
struct GNUNET_TIME_Absolute timeout
Absolute timeout value for the task, or GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout".
Definition: scheduler.c:184
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
struct GNUNET_AsyncScopeSave scope
Asynchronous scope of the task that scheduled this scope,.
Definition: scheduler.c:247
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_read_net()

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 for reading.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. It will be run with the DEFAULT priority. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
rfdread file-descriptor
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1478 of file scheduler.c.

References GNUNET_SCHEDULER_add_read_net_with_priority(), and GNUNET_SCHEDULER_PRIORITY_DEFAULT.

Referenced by accept_client(), connect_success_continuation(), core_read_finished_cb(), create_listen_socket(), delayed_restart_task(), do_accept(), do_resume(), do_s5r_read(), do_udp_read(), GNUNET_CONNECTION_receive(), GNUNET_NAT_AUTO_test_start(), GNUNET_NAT_test_start(), listen_cb(), maint_child_death(), mq_init(), proto_read_kx(), queue_destroy(), queue_read(), queue_read_kx(), read_dns4(), read_dns6(), receive_complete_cb(), receive_ready(), resume_client_receive(), run(), schedule_select_v4(), schedule_select_v6(), select_read_cb(), service_client_recv(), sock_read(), start_client(), stun_read_task(), test_nat_punched(), test_stun(), unix_plugin_select_read(), and unix_transport_server_start().

1482 {
1485  rfd, task, task_cls);
1486 }
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:1512
Run with the default priority (normal P2P operations).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_read_net_with_priority()

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 when the specified file descriptor is ready for reading.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. It will be run with the DEFAULT priority. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
prioritypriority to use for the task
rfdread file-descriptor
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1512 of file scheduler.c.

References GNUNET_NO, GNUNET_SCHEDULER_add_net_with_priority(), and GNUNET_YES.

Referenced by GNUNET_SCHEDULER_add_read_net(), and GNUNET_SERVER_resume().

1517 {
1519  rfd,
1520  GNUNET_YES,
1521  GNUNET_NO,
1522  task, task_cls);
1523 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_YES
Definition: gnunet_common.h:80
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:1584
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_write_net()

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 for writing.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. It will be run with the priority of the calling task. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
wfdwrite file-descriptor
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1548 of file scheduler.c.

References GNUNET_NO, GNUNET_SCHEDULER_add_net_with_priority(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, and GNUNET_YES.

Referenced by connect_success_continuation(), connection_client_send_impl(), do_s5r_read(), do_send(), do_write(), GNUNET_CONNECTION_notify_transmit_ready(), mq_init(), mq_send(), proto_read_kx(), queue_write(), select_write_cb(), service_mq_send(), signal_socks_failure(), signal_socks_success(), transmit_ready(), try_connect_using_address(), try_send_tcp(), unix_plugin_select_write(), and unix_plugin_send().

1552 {
1555  wfd,
1557  task, task_cls);
1558 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_YES
Definition: gnunet_common.h:80
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:1584
Run with the default priority (normal P2P operations).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_net_with_priority()

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.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
prioritypriority of the task
fdfile-descriptor
on_readwhether to poll the file-descriptor for readability
on_writewhether to poll the file-descriptor for writability
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until "task" is started!

Definition at line 1584 of file scheduler.c.

References add_without_sets(), GNUNET_assert, GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_NETWORK_fdset_set(), GNUNET_NETWORK_get_fd(), GNUNET_SCHEDULER_add_select(), and ret.

Referenced by GNUNET_SCHEDULER_add_read_net_with_priority(), and GNUNET_SCHEDULER_add_write_net().

1591 {
1592  /* scheduler must be running */
1593  GNUNET_assert (NULL != scheduler_driver);
1594 
1595 #if MINGW
1596  struct GNUNET_NETWORK_FDSet *s;
1597  struct GNUNET_SCHEDULER_Task * ret;
1598 
1599  GNUNET_assert (NULL != fd);
1601  GNUNET_NETWORK_fdset_set (s, fd);
1603  priority, delay,
1604  on_read ? s : NULL,
1605  on_write ? s : NULL,
1606  task, task_cls);
1608  return ret;
1609 #else
1610  GNUNET_assert (on_read || on_write);
1612  return add_without_sets (delay, priority,
1613  on_read ? fd : NULL,
1614  on_write ? fd : NULL,
1615  NULL,
1616  NULL,
1617  task, task_cls);
1618 #endif
1619 }
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1268
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:89
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
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:1829
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
static struct GNUNET_SCHEDULER_Task * add_without_sets(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, const struct GNUNET_NETWORK_Handle *read_nh, const struct GNUNET_NETWORK_Handle *write_nh, const struct GNUNET_DISK_FileHandle *read_fh, const struct GNUNET_DISK_FileHandle *write_fh, 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:1406
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
Definition: network.c:1163
Entry in list of pending tasks.
Definition: scheduler.c:134
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_read_file()

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 for reading.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. It will be run with the DEFAULT priority. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
rfdread file-descriptor
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1643 of file scheduler.c.

References GNUNET_NO, GNUNET_SCHEDULER_add_file_with_priority(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, and GNUNET_YES.

Referenced by child_death_task(), cmd_read(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), GNUNET_OS_install_parent_control_handler(), GNUNET_SCHEDULER_driver_init(), gnunet_uri(), handle_command(), helper_read(), maint_child_death(), nat_server_read(), parent_control_handler(), read_external_ipv4(), read_task(), restart_nat_server(), run(), shutdown_pipe_cb(), start_helper(), stdin_cb(), testing_main(), tokenizer_cb(), and work().

1646 {
1649  rfd, GNUNET_YES, GNUNET_NO,
1650  task, task_cls);
1651 }
#define GNUNET_NO
Definition: gnunet_common.h:81
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:1710
#define GNUNET_YES
Definition: gnunet_common.h:80
Run with the default priority (normal P2P operations).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_write_file()

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 for writing.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. It will be run with the DEFAULT priority. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
wfdwrite file-descriptor
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1675 of file scheduler.c.

References GNUNET_NO, GNUNET_SCHEDULER_add_file_with_priority(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, and GNUNET_YES.

Referenced by GNUNET_HELPER_send(), helper_write(), tokenizer_cb(), udp_ipv4_broadcast_send(), udp_ipv6_broadcast_send(), and write_task().

1678 {
1681  wfd, GNUNET_NO, GNUNET_YES,
1682  task, task_cls);
1683 }
#define GNUNET_NO
Definition: gnunet_common.h:81
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:1710
#define GNUNET_YES
Definition: gnunet_common.h:80
Run with the default priority (normal P2P operations).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_file_with_priority()

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.

The delay can be used as a timeout on the socket being ready. The task will be scheduled for execution once either the delay has expired or the socket operation is ready. Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
delaywhen should this operation time out?
prioritypriority of the task
fdfile-descriptor
on_readwhether to poll the file-descriptor for readability
on_writewhether to poll the file-descriptor for writability
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

Definition at line 1710 of file scheduler.c.

References add_without_sets(), GNUNET_DISK_FileHandle::fd, GNUNET_assert, GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_NETWORK_fdset_handle_set(), GNUNET_SCHEDULER_add_select(), and ret.

Referenced by GNUNET_SCHEDULER_add_read_file(), and GNUNET_SCHEDULER_add_write_file().

1715 {
1716  /* scheduler must be running */
1717  GNUNET_assert (NULL != scheduler_driver);
1718 
1719 #if MINGW
1720  struct GNUNET_NETWORK_FDSet *s;
1721  struct GNUNET_SCHEDULER_Task * ret;
1722 
1723  GNUNET_assert (NULL != fd);
1727  priority, delay,
1728  on_read ? s : NULL,
1729  on_write ? s : NULL,
1730  task, task_cls);
1732  return ret;
1733 #else
1734  GNUNET_assert (on_read || on_write);
1735  GNUNET_assert (fd->fd >= 0);
1736  return add_without_sets (delay, priority,
1737  NULL,
1738  NULL,
1739  on_read ? fd : NULL,
1740  on_write ? fd : NULL,
1741  task, task_cls);
1742 #endif
1743 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Final status code.
Definition: gnunet-arm.c:89
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
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:1829
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
static struct GNUNET_SCHEDULER_Task * add_without_sets(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, const struct GNUNET_NETWORK_Handle *read_nh, const struct GNUNET_NETWORK_Handle *write_nh, const struct GNUNET_DISK_FileHandle *read_fh, const struct GNUNET_DISK_FileHandle *write_fh, 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:1406
void GNUNET_NETWORK_fdset_handle_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_DISK_FileHandle *h)
Add a file handle to the fd set.
Definition: network.c:1359
Entry in list of pending tasks.
Definition: scheduler.c:134
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
int fd
File handle on other OSes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_add_select()

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 sets is ready.

The delay can be used as a timeout on the socket(s) being ready. The task will be scheduled for execution once either the delay has expired or any of the socket operations is ready. This is the most general function of the "add" family. Note that the "prerequisite_task" must be satisfied in addition to any of the other conditions. In other words, the task will be started when (prerequisite-run) && (delay-ready || any-rs-ready || any-ws-ready) ) Only allowed to be called as long as the scheduler is running, that is one of the following conditions is met:

Parameters
priohow important is this task?
delayhow long should we wait?
rsset of file descriptors we want to read (can be NULL)
wsset of file descriptors we want to write (can be NULL)
taskmain function of the task
task_clsclosure of task
Returns
unique task identifier for the job only valid until task is started!

here we consider the case that a GNUNET_NETWORK_FDSet might be empty although its maximum FD number (nsds) is greater than 0. We handle this case gracefully because some libraries such as libmicrohttpd only provide a hint what the maximum FD number in an FD set might be and not the exact FD number (see e.g. gnunet-rest-service.c)

Definition at line 1829 of file scheduler.c.

References GNUNET_SCHEDULER_Task::callback, GNUNET_SCHEDULER_Task::callback_cls, check_priority(), current_lifeness, current_priority, driver_add_multiple(), extract_handles(), GNUNET_array_grow, GNUNET_assert, GNUNET_async_scope_get(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MAX, GNUNET_new, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_KEEP, GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, init_backtrace(), init_fd_info(), GNUNET_SCHEDULER_Task::lifeness, LOG, max_priority_added, GNUNET_NETWORK_FDSet::nsds, GNUNET_SCHEDULER_Task::own_handles, GNUNET_SCHEDULER_Task::priority, GNUNET_SCHEDULER_Handle::rs, GNUNET_SCHEDULER_Task::scope, t, GNUNET_SCHEDULER_Task::timeout, and GNUNET_SCHEDULER_Handle::ws.

Referenced by client_schedule(), context_task(), curl_download_prepare(), download_prepare(), GNUNET_SCHEDULER_add_file_with_priority(), GNUNET_SCHEDULER_add_net_with_priority(), GNUNET_SERVER_resume(), listen_stdio(), prepare_daemon(), run_httpd(), schedule_httpd(), schedule_read(), and server_schedule().

1835 {
1836  struct GNUNET_SCHEDULER_Task *t;
1837  const struct GNUNET_NETWORK_Handle **read_nhandles = NULL;
1838  const struct GNUNET_NETWORK_Handle **write_nhandles = NULL;
1839  const struct GNUNET_DISK_FileHandle **read_fhandles = NULL;
1840  const struct GNUNET_DISK_FileHandle **write_fhandles = NULL;
1841  unsigned int read_nhandles_len = 0;
1842  unsigned int write_nhandles_len = 0;
1843  unsigned int read_fhandles_len = 0;
1844  unsigned int write_fhandles_len = 0;
1845 
1846  /* scheduler must be running */
1847  GNUNET_assert (NULL != scheduler_driver);
1848  GNUNET_assert (NULL != task);
1849  int no_rs = (NULL == rs);
1850  int no_ws = (NULL == ws);
1851  int empty_rs = (NULL != rs) && (0 == rs->nsds);
1852  int empty_ws = (NULL != ws) && (0 == ws->nsds);
1853  int no_fds = (no_rs && no_ws) ||
1854  (empty_rs && empty_ws) ||
1855  (no_rs && empty_ws) ||
1856  (no_ws && empty_rs);
1857  if (! no_fds)
1858  {
1859  if (NULL != rs)
1860  {
1861  extract_handles (rs,
1862  &read_nhandles,
1863  &read_nhandles_len,
1864  &read_fhandles,
1865  &read_fhandles_len);
1866  }
1867  if (NULL != ws)
1868  {
1869  extract_handles (ws,
1870  &write_nhandles,
1871  &write_nhandles_len,
1872  &write_fhandles,
1873  &write_fhandles_len);
1874  }
1875  }
1883  int no_fds_extracted = (0 == read_nhandles_len) &&
1884  (0 == read_fhandles_len) &&
1885  (0 == write_nhandles_len) &&
1886  (0 == write_fhandles_len);
1887  if (no_fds || no_fds_extracted)
1889  prio,
1890  task,
1891  task_cls);
1892  t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
1894  init_fd_info (t,
1895  read_nhandles,
1896  read_nhandles_len,
1897  write_nhandles,
1898  write_nhandles_len,
1899  read_fhandles,
1900  read_fhandles_len,
1901  write_fhandles,
1902  write_fhandles_len);
1903  t->callback = task;
1904  t->callback_cls = task_cls;
1905  t->own_handles = GNUNET_YES;
1906  /* free the arrays of pointers to network / file handles, the actual
1907  * handles will be freed in destroy_task */
1908  GNUNET_array_grow (read_nhandles, read_nhandles_len, 0);
1909  GNUNET_array_grow (write_nhandles, write_nhandles_len, 0);
1910  GNUNET_array_grow (read_fhandles, read_fhandles_len, 0);
1911  GNUNET_array_grow (write_fhandles, write_fhandles_len, 0);
1912 #if PROFILE_DELAYS
1913  t->start_time = GNUNET_TIME_absolute_get ();
1914 #endif
1916  t->priority =
1917  check_priority ((prio ==
1919  prio);
1922  pending_tail,
1923  t);
1924  driver_add_multiple (t);
1926  t->priority);
1928  "Adding task %p\n",
1929  t);
1930  init_backtrace (t);
1931  return t;
1932 }
int nsds
Maximum number of any socket descriptor in the set (plus one)
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
GNUNET_SCHEDULER_TaskCallback callback
Function to run when ready.
Definition: scheduler.c:149
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:1178
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void init_backtrace(struct GNUNET_SCHEDULER_Task *t)
Initialize backtrace data for task t.
Definition: scheduler.c:1031
Run with the same priority as the current job.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_SCHEDULER_Task * pending_head
Head of list of tasks waiting for an event.
Definition: scheduler.c:317
static struct GNUNET_SCHEDULER_Task * t
Main task.
void extract_handles(const struct GNUNET_NETWORK_FDSet *fdset, const struct GNUNET_NETWORK_Handle ***ntarget, unsigned int *extracted_nhandles, const struct GNUNET_DISK_FileHandle ***ftarget, unsigned int *extracted_fhandles)
Definition: scheduler.c:1747
static struct GNUNET_SCHEDULER_Task * pending_tail
Tail of list of tasks waiting for an event.
Definition: scheduler.c:322
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:85
static int current_lifeness
Value of the &#39;lifeness&#39; flag for the current task.
Definition: scheduler.c:406
static void driver_add_multiple(struct GNUNET_SCHEDULER_Task *t)
calls the given function func on each FdInfo related to t.
Definition: scheduler.c:899
static const struct GNUNET_SCHEDULER_Driver * scheduler_driver
The driver used for the event loop.
Definition: scheduler.c:312
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
void * callback_cls
Closure for the callback.
Definition: scheduler.c:154
#define LOG(kind,...)
Definition: scheduler.c:31
static enum GNUNET_SCHEDULER_Priority current_priority
Priority of the task running right now.
Definition: scheduler.c:395
int own_handles
Do we own the network and file handles referenced by the FdInfo structs in the fds array...
Definition: scheduler.c:178
static enum GNUNET_SCHEDULER_Priority max_priority_added
Priority of the highest task added in the current select iteration.
Definition: scheduler.c:401
static enum GNUNET_SCHEDULER_Priority check_priority(enum GNUNET_SCHEDULER_Priority p)
Check that the given priority is legal (and return it).
Definition: scheduler.c:448
Entry in list of pending tasks.
Definition: scheduler.c:134
void init_fd_info(struct GNUNET_SCHEDULER_Task *t, const struct GNUNET_NETWORK_Handle *const *read_nh, unsigned int read_nh_len, const struct GNUNET_NETWORK_Handle *const *write_nh, unsigned int write_nh_len, const struct GNUNET_DISK_FileHandle *const *read_fh, unsigned int read_fh_len, const struct GNUNET_DISK_FileHandle *const *write_fh, unsigned int write_fh_len)
Definition: scheduler.c:781
handle to a socket
Definition: network.c:46
struct GNUNET_TIME_Absolute timeout
Absolute timeout value for the task, or GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout".
Definition: scheduler.c:184
#define GNUNET_YES
Definition: gnunet_common.h:80
enum GNUNET_SCHEDULER_Priority priority
Task priority.
Definition: scheduler.c:203
struct GNUNET_AsyncScopeSave scope
Asynchronous scope of the task that scheduled this scope,.
Definition: scheduler.c:247
Handle used to access files (and pipes).
int lifeness
Should the existence of this task in the queue be counted as reason to not shutdown the scheduler...
Definition: scheduler.c:219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCHEDULER_set_select()

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).

Parameters
new_selectnew select function to use (NULL to reset to default)
new_select_clsclosure for new_select
new_selectnew select function to use
new_select_clsclosure for new_select
Returns
previously used select function, NULL for default

Definition at line 433 of file scheduler.c.

References scheduler_select, and scheduler_select_cls.

435 {
436  scheduler_select = new_select;
437  scheduler_select_cls = new_select_cls;
438 }
static GNUNET_SCHEDULER_select scheduler_select
Function to use as a select() in the scheduler.
Definition: scheduler.c:412
static void * scheduler_select_cls
Closure for scheduler_select.
Definition: scheduler.c:422

◆ GNUNET_SCHEDULER_begin_async_scope()

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 the current task after calling this function.

Nested tasks can begin their own nested async scope.

Once the current task is finished, the async scope ID is reset to its previous value.

Must only be called from a running task.

Parameters
aidthe asynchronous scope id to enter

Definition at line 2546 of file scheduler.c.

References GNUNET_assert, and GNUNET_async_scope_enter().

2547 {
2548  struct GNUNET_AsyncScopeSave dummy_old_scope;
2549 
2550  GNUNET_assert (NULL != active_task);
2551  /* Since we're in a task, the context will be automatically
2552  restored by the scheduler. */
2553  GNUNET_async_scope_enter (aid, &dummy_old_scope);
2554 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * active_task
ID of the task that is running right now.
Definition: scheduler.c:361
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
Saved async scope identifier or root scope.
Here is the call graph for this function: