|
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_t * | sys_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... | |
| bool sys_waitgroup_add | ( | sys_waitgroup_t * | wg, |
| int | delta | ||
| ) |
Add to the wait group counter.
| wg | Pointer to the wait group |
| delta | Number to add to the counter |
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.
| void sys_waitgroup_deinit | ( | sys_waitgroup_t * | wg | ) |
Deinitialize a wait group.
| wg | Pointer 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.
| bool sys_waitgroup_done | ( | sys_waitgroup_t * | wg | ) |
Decrement the wait group counter.
| wg | Pointer to the wait group |
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_t* sys_waitgroup_init | ( | void | ) |
Initialize a new wait group.
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.
| void sys_waitgroup_wait | ( | sys_waitgroup_t * | wg | ) |
Wait for a wait group to complete.
| wg | Pointer 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.