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. | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
|
|
|
|
|
|
|
|
|
||||||||||||
|
|
|
|
|
|
|
|
|
|
Must init before use.
|
|
|
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.
|
|
|
This lock may be shared with other threads that have called rwlock_rdlock(). Does not block.
|
|
|
Only one thread will hold a write lock at a time. Does not block.
|
|
|
Release both read and write locks. Threads that are blocking on write locks will wake up before threads blocking on read locks.
|
|
|
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.
|
1.4.6