picofuse

Macros | Typedefs
Collaboration diagram for Wait Groups:

Macros

#define SYS_WAITGROUP_CAPACITY   32
 Maximum number of wait groups available in static-pool implementations.
 

Typedefs

typedef struct sys_waitgroup_t sys_waitgroup_t
 Wait group.
 

Lifecycle

sys_waitgroup_tsys_waitgroup_init (void)
 Initialize a new wait group. More...
 
void sys_waitgroup_deinit (sys_waitgroup_t *wg)
 Deinitialize a wait group. More...
 

Methods

bool sys_waitgroup_add (sys_waitgroup_t *wg, int delta)
 Add to the wait group counter. More...
 
bool sys_waitgroup_done (sys_waitgroup_t *wg)
 Decrement the wait group counter. More...
 
void sys_waitgroup_wait (sys_waitgroup_t *wg)
 Wait for a wait group to complete. More...
 

Detailed Description

Function Documentation

◆ sys_waitgroup_add()

bool sys_waitgroup_add ( sys_waitgroup_t wg,
int  delta 
)

Add to the wait group counter.

Parameters
wgPointer to the wait group
deltaNumber to add to the counter
Returns
true if successful, false on error

Increments the wait group counter by delta. This should be called before starting worker threads that the wait group should wait for. Implementations may reject negative deltas.

◆ sys_waitgroup_deinit()

void sys_waitgroup_deinit ( sys_waitgroup_t wg)

Deinitialize a wait group.

Parameters
wgPointer to the wait group to deinitialize

Releases all resources associated with the wait group and renders it unusable. The counter should be 0 and no threads should be waiting in sys_waitgroup_wait() when this function is called.

◆ sys_waitgroup_done()

bool sys_waitgroup_done ( sys_waitgroup_t wg)

Decrement the wait group counter.

Parameters
wgPointer to the wait group
Returns
true if successful, false on error

Decrements the wait group counter by 1. This should be called when a worker finishes its work. If the counter reaches 0, all threads waiting in sys_waitgroup_wait() will be released.

◆ sys_waitgroup_init()

sys_waitgroup_t* sys_waitgroup_init ( void  )

Initialize a new wait group.

Returns
Initialized wait group structure

Creates and initializes a new wait group for thread synchronization. The wait group counter starts at 0. The returned wait group is ready for use with sys_waitgroup_add(), sys_waitgroup_done(), and sys_waitgroup_wait(). Implementations that use a static pool may return NULL after SYS_WAITGROUP_CAPACITY wait groups have been allocated.

◆ sys_waitgroup_wait()

void sys_waitgroup_wait ( sys_waitgroup_t wg)

Wait for a wait group to complete.

Parameters
wgPointer to the wait group to wait on

Blocks until the wait group counter reaches 0, then returns. The counter should reach 0 through sys_waitgroup_done() calls from worker threads. Safe to call from multiple threads on the same wait group; all of them are released once the counter reaches 0. Does not deinitialize the wait group - call sys_waitgroup_deinit() once all waiters have returned.