CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
mutex.h File Reference

Mutexes. More...

Go to the source code of this file.

Data Structures

struct  mutex
 A sleeping mutual-exclusion lock. More...

Macros

#define WAIT_FOREVER   (-1)
 Negative timeout: wait without a bound.
#define NO_WAIT   0
 Timeout of zero: take the lock only when it is free.

Functions

void mutex_init (struct mutex *lock)
 Initialize a mutex.
int mutex_lock_timeout (struct mutex *lock, int timeout_ms)
 Take a mutex, waiting at most a bounded time.
void mutex_unlock (struct mutex *lock)
 Release a mutex.

Detailed Description

Mutexes.

WAIT_FOREVER (a negative timeout) waits without a bound; NO_WAIT takes the lock only when it is free. Like every mutex, the task that takes it must be the one that releases it.

Function Documentation

◆ mutex_init()

void mutex_init ( struct mutex * lock)

Initialize a mutex.

Parameters
[out]lockMutex structure to initialize.

◆ mutex_lock_timeout()

int mutex_lock_timeout ( struct mutex * lock,
int timeout_ms )

Take a mutex, waiting at most a bounded time.

Parameters
[in]lockMutex to take.
[in]timeout_msMilliseconds to wait; negative waits forever, 0 does not wait.
Returns
0 when the lock was taken, -ETIMEDOUT when it stayed busy, or -EINVAL for an uninitialized mutex.

◆ mutex_unlock()

void mutex_unlock ( struct mutex * lock)

Release a mutex.

Parameters
[in]lockMutex to release; must be held by the calling task.