kern/lock.h File Reference

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 is_held (struct lock *k)
void release (struct lock *k)

Detailed Description

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

Function Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
k Lock to check. Must be non-null.
Returns:
Non-zero if lock is held by current thread, zero otherwise.

void release ( struct lock *  k  ) 

Release the lock 'k'.

Parameters:
k Lock to release. Must be non-null.