GNUnet  0.11.x
Typedefs | Functions
testing_messenger_barrier.h File Reference

Pseudo-barriers for simple event handling. More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for testing_messenger_barrier.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* GNUNET_BarrierStatusCallback) (void *cls, struct GNUNET_BarrierHandle *barrier, int status)
 Functions of this type are to be given as callback argument to GNUNET_init_barrier(). More...
 
typedef void(* GNUNET_BarrierWaitStatusCallback) (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status)
 Functions of this type are to be given as acallback argument to GNUNET_wait_barrier(). More...
 

Functions

struct GNUNET_BarrierHandleGNUNET_init_barrier (unsigned int requirement, GNUNET_BarrierStatusCallback cb, void *cb_cls)
 Initialise a pseudo-barrier and call the given callback when the required amount of peers (requirement) reach the pseudo-barrier OR upon error. More...
 
void GNUNET_cancel_barrier (struct GNUNET_BarrierHandle *barrier)
 Cancel a pseudo-barrier. More...
 
struct GNUNET_BarrierWaitHandleGNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, GNUNET_BarrierWaitStatusCallback cb, void *cb_cls)
 Wait for a pseudo-barrier to be crossed. More...
 
void GNUNET_cancel_wait_barrier (struct GNUNET_BarrierWaitHandle *waiting)
 Cancel a pseudo-barrier wait handle. More...
 

Detailed Description

Pseudo-barriers for simple event handling.

Author
Tobias Frisch

Definition in file testing_messenger_barrier.h.

Typedef Documentation

◆ GNUNET_BarrierStatusCallback

typedef void(* GNUNET_BarrierStatusCallback) (void *cls, struct GNUNET_BarrierHandle *barrier, int status)

Functions of this type are to be given as callback argument to GNUNET_init_barrier().

The callback will be called when status information is available for the pseudo-barrier.

Parameters
clsthe closure given to GNUNET_init_barrier()
barrierthe pseudo-barrier handle
statusstatus of the pseudo-barrier. The pseudo-barrier is removed once it has been crossed or an error occurs while processing it. Therefore it is invalid to call GNUNET_cancel_barrier() on a crossed or errored pseudo-barrier.

Definition at line 50 of file testing_messenger_barrier.h.

◆ GNUNET_BarrierWaitStatusCallback

typedef void(* GNUNET_BarrierWaitStatusCallback) (void *cls, struct GNUNET_BarrierWaitHandle *waiting, int status)

Functions of this type are to be given as acallback argument to GNUNET_wait_barrier().

The callback will be called when the pseudo-barrier corresponding given in GNUNET_wait_barrier() is crossed or cancelled.

Parameters
clsclosure pointer given to GNUNET_wait_barrier()
waitingthe pseudo-barrier wait handle
statusGNUNET_SYSERR in case of error while waiting for the pseudo-barrier; GNUNET_OK if the pseudo-barrier is crossed

Definition at line 99 of file testing_messenger_barrier.h.

Function Documentation

◆ GNUNET_init_barrier()

struct GNUNET_BarrierHandle* GNUNET_init_barrier ( unsigned int  requirement,
GNUNET_BarrierStatusCallback  cb,
void *  cb_cls 
)

Initialise a pseudo-barrier and call the given callback when the required amount of peers (requirement) reach the pseudo-barrier OR upon error.

Parameters
requirementthe amount of peers that is required to reach the pseudo-barrier. Peers signal reaching a pseudo-barrier by calling GNUNET_wait_barrier().
cbthe callback to call when the pseudo-barrier is reached or upon error. Can be NULL.
clsclosure for the above callback
Returns
pseudo-barrier handle; NULL upon error

Definition at line 41 of file testing_messenger_barrier.c.

44 {
45  if (0 == requirement)
46  return NULL;
47 
48  struct GNUNET_BarrierHandle *barrier = GNUNET_new(struct GNUNET_BarrierHandle);
49 
50  if (!barrier)
51  return NULL;
52 
53  barrier->requirement = requirement;
54  barrier->cb = cb;
55  barrier->cls = cb_cls;
56  barrier->head = NULL;
57  barrier->tail = NULL;
58  barrier->task = NULL;
59 
60  return barrier;
61 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_BarrierWaitHandle * head
struct GNUNET_BarrierWaitHandle * tail
GNUNET_BarrierStatusCallback cb
struct GNUNET_SCHEDULER_Task * task

References GNUNET_BarrierHandle::cb, GNUNET_BarrierHandle::cls, GNUNET_new, GNUNET_BarrierHandle::head, GNUNET_BarrierHandle::requirement, GNUNET_BarrierHandle::tail, and GNUNET_BarrierHandle::task.

Referenced by barrier_cb(), and GNUNET_run_messenger_setup().

Here is the caller graph for this function:

◆ GNUNET_cancel_barrier()

void GNUNET_cancel_barrier ( struct GNUNET_BarrierHandle barrier)

Cancel a pseudo-barrier.

Parameters
barrierthe pseudo-barrier handle

Definition at line 80 of file testing_messenger_barrier.c.

81 {
82  if ((!barrier) || (barrier->task))
83  return;
84 
85  barrier->task = GNUNET_SCHEDULER_add_now(cancel_barrier, barrier);
86 }
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:1296
static void cancel_barrier(void *cls)

References cancel_barrier(), GNUNET_SCHEDULER_add_now(), and GNUNET_BarrierHandle::task.

Referenced by shutdown_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_wait_barrier()

struct GNUNET_BarrierWaitHandle* GNUNET_wait_barrier ( struct GNUNET_BarrierHandle barrier,
GNUNET_BarrierWaitStatusCallback  cb,
void *  cb_cls 
)

Wait for a pseudo-barrier to be crossed.

This function should be called for the peers which have been started by the testbed.

Parameters
barrierthe pseudo-barrier handle
cbthe pseudo-barrier wait callback
clsthe closure for the above callback
Returns
pseudo-barrier wait handle which can be used to cancel the waiting at anytime before the callback is called. NULL upon error.

Definition at line 124 of file testing_messenger_barrier.c.

127 {
128  if ((!barrier) || (0 == barrier->requirement))
129  return NULL;
130 
132 
133  if (!waiting)
134  return NULL;
135 
136  waiting->cb = cb;
137  waiting->cls = cb_cls;
138  waiting->prev = NULL;
139  waiting->next = NULL;
140  waiting->barrier = barrier;
141 
143  barrier->requirement--;
144 
145  if ((barrier->requirement == 0) && (!barrier->task))
147 
148  return waiting;
149 }
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
GNUNET_BarrierWaitStatusCallback cb
struct GNUNET_BarrierHandle * barrier
struct GNUNET_BarrierWaitHandle * prev
struct GNUNET_BarrierWaitHandle * next
static void complete_barrier(void *cls)

References GNUNET_BarrierWaitHandle::barrier, GNUNET_BarrierWaitHandle::cb, GNUNET_BarrierWaitHandle::cls, complete_barrier(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_BarrierHandle::head, GNUNET_BarrierWaitHandle::next, GNUNET_BarrierWaitHandle::prev, GNUNET_BarrierHandle::requirement, GNUNET_BarrierHandle::tail, and GNUNET_BarrierHandle::task.

Referenced by on_message(), and on_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_cancel_wait_barrier()

void GNUNET_cancel_wait_barrier ( struct GNUNET_BarrierWaitHandle waiting)

Cancel a pseudo-barrier wait handle.

Should not be called in or after the callback given to GNUNET_wait_barrier() has been called.

Parameters
waitingthe pseudo-barrier wait handle

Definition at line 152 of file testing_messenger_barrier.c.

153 {
154  if (!waiting)
155  return;
156 
157  struct GNUNET_BarrierHandle *barrier = waiting->barrier;
158 
159  if (!barrier)
160  return;
161 
162  if ((barrier->requirement == 0) && (barrier->task))
163  {
164  GNUNET_SCHEDULER_cancel(barrier->task);
165  barrier->task = NULL;
166  }
167 
168  barrier->requirement++;
169  GNUNET_CONTAINER_DLL_remove(barrier->head, barrier->tail, waiting);
170 
171  GNUNET_free(waiting);
172 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972

References GNUNET_BarrierWaitHandle::barrier, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_BarrierHandle::head, GNUNET_BarrierHandle::requirement, GNUNET_BarrierHandle::tail, and GNUNET_BarrierHandle::task.

Referenced by on_message(), and shutdown_cb().

Here is the call graph for this function:
Here is the caller graph for this function: