Locks. More...
Defines | |
#define | LOCK_MAX_ACQUIRES 255 |
Maximum number of recursive acquires. | |
Functions | |
void | init_lock (struct lock *k, const char *name) |
void | acquire (struct lock *k) |
int | try_acquire (struct lock *k) |
int | is_held (struct lock *k) |
void | release (struct lock *k) |
void | smash (struct lock *k) |
JoyOS includes a locking mechanism, useful when writing multi-threaded code. Locks allow sections of code to be protected, requiring a thread to acquire the lock before continuing. This allows multiple threads to to share a single resource (such as a variable, or a sensor). All of the Happyboard hardware drivers are locked to ensure thread-safe operation
void acquire | ( | struct lock * | k | ) |
Acquire the lock 'k'. If another thread holds the lock yield until it is available, then take it. A thread can recursively acquire the same lock multiple times, but it must release once for every acquire.
k | Lock to acquire. Must be non-null. |
void init_lock | ( | struct lock * | k, |
const char * | name | ||
) |
Initialize the lock 'k'. This routine must be called before lock 'k' is used.
k | Lock to initialize, must be non-null. |
name | Debugging name for lock. |
int is_held | ( | struct lock * | k | ) |
Checks to see if lock 'k' is held by the current thread.
k | Lock to check. Must be non-null. |
void release | ( | struct lock * | k | ) |
Release the lock 'k'.
k | Lock to release. Must be non-null. |
void smash | ( | struct lock * | k | ) |
Smash the lock 'k', releasing it. Should only ever be called by the kernel.
k | Lock to release. Must be non-null. |
int try_acquire | ( | struct lock * | k | ) |
Try to acquire the lock 'k'. If another thread holds the lock, return 0. If the lock was acquired, return 1.
k | Lock to acquire. Must be non-null. |