GNUnet 0.21.1
gnunet_testing_barrier.h File Reference

API to manage barriers. More...

Include dependency graph for gnunet_testing_barrier.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_TESTING_BarrierListEntry
 An entry for a barrier list FIXME: why is this in the public API!??! More...
 
struct  GNUNET_TESTING_BarrierList
 A list to hold barriers provided by plugins FIXME: why is this in the public API!??! More...
 

Macros

#define GNUNET_TESTING_BARRIER_MAX   32
 

Functions

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create (const char *label, double percentage_to_be_reached, unsigned int number_to_be_reached)
 Command to create a barrier. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached (const char *label, const char *barrier_label, unsigned int asynchronous_finish, unsigned int node_number, unsigned int running_on_master, GNUNET_TESTING_cmd_helper_write_cb write_message)
 If this command is executed the the process is signaling the master process that it reached a barrier. More...
 

Detailed Description

API to manage barriers.

Author
t3sserakt

Definition in file gnunet_testing_barrier.h.

Macro Definition Documentation

◆ GNUNET_TESTING_BARRIER_MAX

#define GNUNET_TESTING_BARRIER_MAX   32

Definition at line 36 of file gnunet_testing_barrier.h.

Function Documentation

◆ GNUNET_TESTING_cmd_barrier_create()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_create ( const char *  label,
double  percentage_to_be_reached,
unsigned int  number_to_be_reached 
)

Command to create a barrier.

FIXME: high-level it is baffling how we need both the GNUNET_TESTING_Barrier and the Command that creates barriers. Conceptually this seems to be very much separate. Can we move _Barrier completely into testing as private?

Parameters
labelThe label of this command.
percentage_to_be_reachedIf this percentage of processes reached this barrier, all processes waiting at this barrier can pass it. Must not be used together with number_to_be_reached.
number_to_be_reachedIf this number of processes reached this barrier, all processes waiting at this barrier can pass it. Must not be used together with percentage_to_be_reached.

Definition at line 183 of file testing_api_cmd_barrier.c.

186{
187 struct GNUNET_TESTING_Barrier *barrier;
188 struct BarrierState *bs;
189
190 bs = GNUNET_new (struct BarrierState);
191 bs->label = label;
193 barrier->name = label;
194 barrier->percentage_to_be_reached = percentage_to_be_reached;
195 barrier->number_to_be_reached = number_to_be_reached;
196 GNUNET_assert ((0 < percentage_to_be_reached &&
197 0 == number_to_be_reached) ||
198 (0 == percentage_to_be_reached &&
199 0 < number_to_be_reached));
200 bs->barrier = barrier;
205 NULL);
206}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * label
Our label.
struct GNUNET_TESTING_Barrier * barrier
Our barrier, set to NULL once the barrier is active.
const char * name
Name of the barrier.
Definition: testing.h:182
unsigned int number_to_be_reached
Number of commands which need to reach the barrier to change state.
Definition: testing.h:209
double percentage_to_be_reached
Percentage of of commands which need to reach the barrier to change state.
Definition: testing.h:203
static enum GNUNET_GenericReturnValue barrier_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "barrier" CMD, to other commands.
static void barrier_cleanup(void *cls)
Cleanup the state from a "barrier" CMD, and possibly cancel a pending operation thereof.
static void barrier_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.

References BarrierState::barrier, barrier_cleanup(), barrier_run(), barrier_traits(), GNUNET_assert, GNUNET_new, GNUNET_TESTING_command_new(), BarrierState::label, GNUNET_TESTING_Barrier::name, GNUNET_TESTING_Barrier::number_to_be_reached, and GNUNET_TESTING_Barrier::percentage_to_be_reached.

Here is the call graph for this function:

◆ GNUNET_TESTING_cmd_barrier_reached()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached ( const char *  label,
const char *  barrier_label,
unsigned int  asynchronous_finish,
unsigned int  node_number,
unsigned int  running_on_master,
GNUNET_TESTING_cmd_helper_write_cb  write_message 
)

If this command is executed the the process is signaling the master process that it reached a barrier.

If this command is synchronous it will block.

FIXME: Now this, as it returns a Command, seems to me like it should be part of the public API?

Parameters
labelname for command.
barrier_labelThe name of the barrier we waited for and which was reached.
asynchronous_finishIf GNUNET_YES this command will not block.
node_numberThe global number of the node the cmd runs on.
running_on_masterIs this cmd running on the master loop?
write_messageCallback to write messages to the master loop.
Returns
command.

If this command is executed the the process is signaling the master process that it reached a barrier.

Parameters
labelname for command.
barrier_labelThe name of the barrier we wait for (if finishing asynchronous) and which will be reached.
asynchronous_finishIf GNUNET_YES this command will not block.
node_numberThe global numer of the node the cmd runs on.
running_on_masterIs this cmd running on the master loop.
write_messageCallback to write messages to the master loop.
Returns
command.

Definition at line 207 of file testing_api_cmd_barrier_reached.c.

214{
215 struct BarrierReachedState *brs;
216
217 brs = GNUNET_new (struct BarrierReachedState);
218 brs->label = label;
219 brs->barrier_name = barrier_label;
228 &brs->ac);
229}
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
Struct with information for callbacks.
const char * barrier_name
The name of the barrier this commands wait (if finishing asynchronous) for or/and reaches.
const char * label
The label of this command.
unsigned int running_on_master
Is this cmd running on the master loop.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
unsigned int asynchronous_finish
If this command will block.
GNUNET_TESTING_cmd_helper_write_cb write_message
Callback to write messages to the master loop.
static void barrier_reached_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run the command.
static enum GNUNET_GenericReturnValue barrier_reached_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Offer internal data from a "batch" CMD, to other commands.
static void barrier_reached_cleanup(void *cls)
Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.

References BarrierReachedState::ac, BarrierReachedState::asynchronous_finish, BarrierReachedState::barrier_name, barrier_reached_cleanup(), barrier_reached_run(), barrier_reached_traits(), GNUNET_new, GNUNET_TESTING_command_new(), BarrierReachedState::label, BarrierReachedState::node_number, BarrierReachedState::running_on_master, write_message(), and BarrierReachedState::write_message.

Here is the call graph for this function: