3.3. Threads

int thread_get_packet_capture_cpu_count()

Get the number of thread to be used by the application for packet capture.

int thread_get_cpu_count()

Get the number of CPUs.

int thread_get_id()

Get current thread id.

3.3.1. Atomic

atomic_t

32 bit atomic integer.

uint32 atomic_inc(atomic_t *v)

Increment a counter v and return its new value atomically.

uint32 atomic_dec(atomic_t *v)

Decrement a counter v and return its new value atomically.

uint32 atomic_get(atomic_t *v)

Get the current value of the atomic counter v.

void atomic_set(atomic_t *v, uint32 x)

Set the current value of the atomic counter v to x.

3.3.2. Mutex

mutex_t

Mutex opaque type.

MUTEX_INIT

Initialize static mutex.

bool mutex_init(mutex_t *mutex, bool recursive)

Initialize a mutex mutex. With recursive, the mutex can be created recursive (ie. can be re-entered by the same thread).

Returns:True on success. Use clear_error() to get details about the error.
bool mutex_destroy(mutex_t *mutex)

Destroy a mutex.

Returns:True on success. Use clear_error() to get details about the error.
bool mutex_lock(mutex_t *mutex)

Lock a mutex.

Returns:True on success. Use clear_error() to get details about the error.
bool mutex_trylock(mutex_t *mutex)

Try to lock a mutex.

Returns:True if successful, False if the lock could not be taken. Use check_error() and clear_error() to get details about the error.
bool mutex_unlock(mutex_t *mutex)

Unlock a mutex.

Returns:True on success. Use clear_error() to get details about the error.

3.3.3. Semaphore

semaphore_t

Semaphore opaque type.

bool semaphore_init(semaphore_t *semaphore, uint32 initial)

Initialize a new semaphore with initial value of initial.

Returns:True on success. Use clear_error() to get details about the error.
bool semaphore_destroy(semaphore_t *semaphore)

Destroy a semaphore.

Returns:True on success. Use clear_error() to get details about the error.
bool semaphore_wait(semaphore_t *semaphore)

Wait on a semaphore.

Returns:True on success. Use clear_error() to get details about the error.
bool semaphore_post(semaphore_t *semaphore)

Post on a semaphore.

Returns:True on success. Use clear_error() to get details about the error.

3.3.4. Thread local storage

local_storage_t

Thread local storage opaque type.

bool local_storage_init(local_storage_t *key, void (*destructor)(void *))

Initialize thread local storage. The parameter destructor allows to set a cleanup function to call when the storage is destroyed.

Returns:True on success. Use clear_error() to get details about the error.
bool local_storage_destroy(local_storage_t *key)

Destroy a thread local storage.

Returns:True on success. Use clear_error() to get details about the error.
void *local_storage_get(local_storage_t *key)

Get the value of the thread local storage.

Returns:The value associated with the current thread.
bool local_storage_set(local_storage_t *key, const void *value)

Set the value of the thread local storage.

Returns:True on success. Use clear_error() to get details about the error.