GNUnet 0.21.1
testing_api_cmd_barrier_reached.c File Reference

Command to signal barrier was reached. More...

#include "platform.h"
#include "gnunet_testing_lib.h"
#include "testing_api_loop.h"
#include "testing_cmds.h"
Include dependency graph for testing_api_cmd_barrier_reached.c:

Go to the source code of this file.

Data Structures

struct  BarrierReachedState
 Struct with information for callbacks. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void barrier_reached_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run the command. More...
 
static void barrier_reached_cleanup (void *cls)
 Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof. More...
 
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. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_barrier_reached (const char *label, const char *barrier_label)
 If this command is executed the the process is signaling the master process that it reached a barrier. More...
 

Detailed Description

Command to signal barrier was reached.

Author
t3sserakt

Definition in file testing_api_cmd_barrier_reached.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 34 of file testing_api_cmd_barrier_reached.c.

Function Documentation

◆ barrier_reached_run()

static void barrier_reached_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

Run the command.

Parameters
clsclosure.
isthe interpreter state.

Definition at line 67 of file testing_api_cmd_barrier_reached.c.

69{
70 struct BarrierReachedState *brs = cls;
71 struct GNUNET_TESTING_Barrier *barrier;
72
74 brs->barrier_name);
75 if (NULL == barrier)
76 {
78 "No barrier `%s'\n",
79 brs->barrier_name);
81 return;
82 }
83 if (barrier->satisfied)
84 {
86 return;
87 }
88 if (barrier->inherited)
89 {
91 .header.size = htons (sizeof (cbr)),
93 };
94
96 &cbr.barrier_key);
98 &cbr.header);
99 return;
100 }
101 barrier->reached++;
102 if (barrier->reached == barrier->expected_reaches)
103 {
105 .header.size = htons (sizeof (cbs)),
107 };
108
110 &cbs.barrier_key);
111 barrier->satisfied = true;
113 &cbs.header);
114 }
115 if (barrier->satisfied)
116 {
118 for (unsigned int i = 0; i<barrier->cnt_waiting; i++)
120 GNUNET_array_grow (barrier->waiting,
121 barrier->cnt_waiting,
122 0);
123 return;
124 }
126 barrier->cnt_waiting,
127 &brs->ac);
128}
static struct GNUNET_TESTING_Interpreter * is
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
#define GNUNET_log(kind,...)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE
Struct with information for callbacks.
const char * barrier_name
The name of the barrier this commands wait (if finishing asynchronous) for or/and reaches.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
An entry for a barrier list.
bool inherited
Did we inherit the barrier from our parent loop?
unsigned int reached
Number of times the barrier has been reached.
unsigned int expected_reaches
Number of total commands expected to be reached by the barrier.
struct GNUNET_TESTING_AsyncContext ** waiting
Context of barrier reached commands of our local interpreter that are currently blocked on this barri...
unsigned int cnt_waiting
Length of the waiting array.
bool satisfied
Did we reach expected_reaches? Used in particular if inherited is true and we cannot compute locally.
Child to parent: I reached the given barrier, increment the counter (or pass to grandparent).
Definition: testing_cmds.h:75
struct GNUNET_ShortHashCode barrier_key
Definition: testing_cmds.h:77
struct GNUNET_MessageHeader header
Definition: testing_cmds.h:76
Parent to child: this barrier was satisfied.
Definition: testing_cmds.h:97
struct GNUNET_MessageHeader header
Definition: testing_cmds.h:98
struct GNUNET_ShortHashCode barrier_key
Definition: testing_cmds.h:99
void GNUNET_TESTING_barrier_name_hash_(const char *barrier_name, struct GNUNET_ShortHashCode *bkey)
struct GNUNET_TESTING_Barrier * GNUNET_TESTING_get_barrier_(struct GNUNET_TESTING_Interpreter *is, const char *barrier_name)
void GNUNET_TESTING_loop_notify_parent_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
Send message to our parent.
void GNUNET_TESTING_loop_notify_children_(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_MessageHeader *hdr)
Send message to all netjail children (if there are any).

References BarrierReachedState::ac, GNUNET_TESTING_CommandBarrierReached::barrier_key, GNUNET_TESTING_CommandBarrierSatisfied::barrier_key, BarrierReachedState::barrier_name, GNUNET_TESTING_Barrier::cnt_waiting, GNUNET_TESTING_Barrier::expected_reaches, GNUNET_array_append, GNUNET_array_grow, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_CROSSABLE, GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED, GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), GNUNET_TESTING_barrier_name_hash_(), GNUNET_TESTING_get_barrier_(), GNUNET_TESTING_loop_notify_children_(), GNUNET_TESTING_loop_notify_parent_(), GNUNET_TESTING_CommandBarrierReached::header, GNUNET_TESTING_CommandBarrierSatisfied::header, GNUNET_TESTING_Barrier::inherited, is, GNUNET_TESTING_Barrier::reached, GNUNET_TESTING_Barrier::satisfied, GNUNET_MessageHeader::size, and GNUNET_TESTING_Barrier::waiting.

Referenced by GNUNET_TESTING_cmd_barrier_reached().

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

◆ barrier_reached_cleanup()

static void barrier_reached_cleanup ( void *  cls)
static

Cleanup the state from a "barrier reached" CMD, and possibly cancel a pending operation thereof.

Parameters
clsclosure.

Definition at line 138 of file testing_api_cmd_barrier_reached.c.

139{
140 struct BarrierReachedState *brs = cls;
141
142 GNUNET_free (brs);
143}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

Referenced by GNUNET_TESTING_cmd_barrier_reached().

Here is the caller graph for this function:

◆ barrier_reached_traits()

static enum GNUNET_GenericReturnValue barrier_reached_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

Offer internal data from a "batch" CMD, to other commands.

Parameters
clsclosure.
[out]retresult.
traitname of the trait.
indexindex number of the object to offer.
Returns
GNUNET_OK on success.

Definition at line 156 of file testing_api_cmd_barrier_reached.c.

160{
161 struct GNUNET_TESTING_Trait traits[] = {
163 };
164
166 ret,
167 trait,
168 index);
169}
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, and traits().

Referenced by GNUNET_TESTING_cmd_barrier_reached().

Here is the call graph for this function:
Here is the caller 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 
)

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.

Parameters
labelname for command.
barrier_labelThe name of the barrier we waited for and which was reached.
Returns
command.

Definition at line 173 of file testing_api_cmd_barrier_reached.c.

176{
177 struct BarrierReachedState *brs;
178
179 brs = GNUNET_new (struct BarrierReachedState);
180 brs->label = label;
181 brs->barrier_name = barrier_label;
183 brs,
184 label,
188 &brs->ac);
189}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(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 that may be asynchronous.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * label
The label of this command.
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::barrier_name, barrier_reached_cleanup(), barrier_reached_run(), barrier_reached_traits(), GNUNET_new, GNUNET_TESTING_command_new_ac(), and BarrierReachedState::label.

Here is the call graph for this function: