ao_sem.h
Counting semaphores

Notes

This module defines counting semaphores.

Include

ao_async.h
ao_list.h
ao_time.h
ao_uint.h
stdbool.h

Types

ao_sem_t

typedef struct ao_sem_t ao_sem_t;

Represents a counting semaphore.

ao_sem_take_t

typedef struct ao_sem_take_t ao_sem_take_t;

Represents the taking of a counting semaphore.

Structs

ao_sem_t

struct ao_sem_t
{
    ao_uint_t count;
    ao_list_t take;
};
count The count.
take The list of takings.

ao_sem_take_t

struct ao_sem_take_t
{
    ao_async_t     async;
    ao_uint_t      count;
    bool volatile  result;
    ao_sem_t *     sem;
    ao_list_node_t sem_take_node;
};
async The asynchronous event.
count The count to take.
result The result.
sem The counting semaphore.
sem_take_node The node for the counting semaphore’s list of takings.

Functions

ao_sem_give

void ao_sem_give(ao_sem_t * s, ao_uint_t count);

Gives a counting semaphore.

ao_sem_take

ao_sem_take_from

bool ao_sem_take     (ao_sem_t * s, ao_uint_t count, ao_time_t timeout);
bool ao_sem_take_from(ao_sem_t * s, ao_uint_t count, ao_time_t timeout, ao_time_t beginning);

Takes a counting semaphore in a blocking fashion with a timeout and an optional beginning.

ao_sem_take_forever

bool ao_sem_take_forever(ao_sem_t * s, ao_uint_t count);

Takes a counting semaphore indefinitely in a blocking fashion.

ao_sem_take_try

bool ao_sem_take_try(ao_sem_t * s, ao_uint_t count);

Takes a counting semaphore in a non-blocking fashion.

ao_sem_take_begin

ao_sem_take_end

void ao_sem_take_begin(ao_sem_take_t * t);
void ao_sem_take_end  (ao_sem_take_t * t);

Begins or ends, respectively, a taking of a counting semaphore.

External Links