Thread Synchronization
[Kernel API]


Data Structures

struct  mos_mutex_s
 Mutex data structure. More...
struct  mos_rwlock_t
 Rwlock data structure. More...
struct  mos_sem_t
 Semaphore data structure. More...

Mutex

The Mutex is a standard thread synchronization construct. A thread may lock or unlock a mutex; only one thread may have a mutex locked at once, and only that thread is allowed to unlock the mutex.

#define MUTEX_LOCKED   1
 mos_mutex_try_lock() failed: Mutex is locked by another thread.
#define MUTEX_OK   0
 mos_mutex_try_lock() succeeded: Mutex is now locked by this thread.
#define mos_fast_mutex_lock()   mos_disable_ints()
#define mos_fast_mutex_unlock(handle)   mos_enable_ints(handle)
typedef mos_mutex_s mos_mutex_t
 Mutex data structure.
void mos_mutex_init (mos_mutex_t *mt)
 Initialize a mutex. You must initialize a mutex before using it.
void mos_mutex_lock (mos_mutex_t *mt)
 Lock a mutex. Blocks the thread if the mutex is already locked.
void mos_mutex_unlock (mos_mutex_t *mt)
 Unlock a mutex so another thread can enter the protected area of code.
int8_t mos_mutex_try_lock (mos_mutex_t *mt)
 Try to lock a mutex, but do not block if it is already owned.

Read-Write Lock

The Read-Write lock allows cross-thread passing of data, allowing a thread to lock either for reading or writing.

#define RWLOCK_LOCKED   1
 This is returned from the rw_try_ functions if the RWLock is locked.
#define RWLOCK_OK   0
 This is returned from the rw_try_ functions if the RWLock was acquired.
void rwlock_init (mos_rwlock_t *lock)
 Initialize a read-write lock.
void rwlock_rdlock (mos_rwlock_t *lock)
 Lock a read-write lock for reading.
uint8_t rwlock_tryrdlock (mos_rwlock_t *lock)
 Lock a read-write lock for reading if it is free.
void rwlock_wrlock (mos_rwlock_t *lock)
 Lock a read-write lock for writing.
uint8_t rwlock_trywrlock (mos_rwlock_t *lock)
 Lock a read-write lock for writing if it is free.
void rwlock_unlock (mos_rwlock_t *lock)
 Unlock a read-write lock.

Semaphore

The Semaphore is a standard thread synchronization construct. A thread may post or wait on a semaphore; posting to a semaphore increments it's internal value. Waiting on a semaphore waits until the internal value is non-zero, then decrements it.

#define SEM_SUCCESS   0
 mos_sem_try_wait() succeeded in decrementing semaphore.
#define SEM_FAIL   1
 mos_sem_try_wait() failed in decrementing semaphore (ie mos_sem_wait() would have blocked).
void mos_sem_init (mos_sem_t *s, int value)
 Initialize a semaphore.
void mos_sem_post (mos_sem_t *s)
 Post to the semaphore. Increments the internal value of the semaphore,.
void mos_sem_post_dispatch (mos_sem_t *s)
 Post to a semaphore and wake up the next thread that is blocked on the semaphore.
void mos_sem_select_post (mos_sem_t *s, uint16_t thread)
 Post to a semaphore and select which thread that is blocked on the semaphore should wake up next.
void mos_sem_wait (mos_sem_t *s)
 Wait on a semaphore. Decrements the interal value of the semaphore if it is non-zero. If the value is zero, blocks until it isn't zero.
uint8_t mos_sem_try_wait (mos_sem_t *s)
 Test the semaphore and decrement if possible, otherwise return.

Detailed Description

This group contains information on thread synchronization primitives such as mutexes and semaphores.

Define Documentation

 
#define mos_fast_mutex_lock  )     mos_disable_ints()
 

Deprecated:
Simply disables interrupts. Returns a handle.

Definition at line 98 of file mutex.h.

#define mos_fast_mutex_unlock handle   )     mos_enable_ints(handle)
 

Deprecated:
Re-enables interrupts. Pass the handle returned from most_fast_mutex_lock().

Definition at line 101 of file mutex.h.


Function Documentation

void mos_mutex_init mos_mutex_t mt  ) 
 

Parameters:
mt A pointer to the mutex to initialize.

void mos_mutex_lock mos_mutex_t mt  ) 
 

Parameters:
mt A pointer to the mutex to lock.

int8_t mos_mutex_try_lock mos_mutex_t mt  ) 
 

Parameters:
mt A pointer to the mutex to attempt to lock.
Returns:
MUTEX_LOCKED if another thread already has a lock, MUTEX_OK otherwise.

void mos_mutex_unlock mos_mutex_t mt  ) 
 

Parameters:
mt A pointer to the mutex to unlock.

void mos_sem_init mos_sem_t s,
int  value
 

Parameters:
s A pointer to the semaphore to initialize.
value Initial value to give the semaphore. Usually zero.

void mos_sem_post mos_sem_t s  ) 
 

Parameters:
s A pointer to the semaphore to post.

void mos_sem_post_dispatch mos_sem_t s  ) 
 

Parameters:
s Semaphore to post.

void mos_sem_select_post mos_sem_t s,
uint16_t  thread
 

Parameters:
s A pointer to the semaphore to post. the thread id of the thread to wake up next.

uint8_t mos_sem_try_wait mos_sem_t s  ) 
 

Parameters:
s Semaphore
Returns:
SEM_SUCCESS or SEM_FAIL

void mos_sem_wait mos_sem_t s  ) 
 

Parameters:
s A pointer to the semaphore to wait on.

void rwlock_init mos_rwlock_t lock  ) 
 

Must init before use.

Parameters:
lock Read-write lock to init

void rwlock_rdlock mos_rwlock_t lock  ) 
 

This lock may be shared with other threads that have called rwlock_rdlock(). Blocks the thread if the read-write lock is already locked for writing.

Parameters:
lock Read-write lock to lock

uint8_t rwlock_tryrdlock mos_rwlock_t lock  ) 
 

This lock may be shared with other threads that have called rwlock_rdlock(). Does not block.

Parameters:
lock Read-write lock to lock
Returns:
RWLOCK_LOCKED if another thread already has a lock, else RWLOCK_OK

uint8_t rwlock_trywrlock mos_rwlock_t lock  ) 
 

Only one thread will hold a write lock at a time. Does not block.

Parameters:
lock Read-write lock to lock
Returns:
RWLOCK_LOCKED if another thread already has a lock, else RWLOCK_OK

void rwlock_unlock mos_rwlock_t lock  ) 
 

Release both read and write locks. Threads that are blocking on write locks will wake up before threads blocking on read locks.

Parameters:
lock Read-write lock to unlock

void rwlock_wrlock mos_rwlock_t lock  ) 
 

Only one thread will hold a write lock at a time. Blocks the thread if the read-write lock is already locked for reading or writing.

Parameters:
lock Read-write lock to lock


Generated on Mon Nov 23 06:26:00 2009 for MANTIS by  doxygen 1.4.6