Nut/OS  4.10.3
API Reference
Recursive Mutex

Thread synchronization support. More...

Collaboration diagram for Recursive Mutex:

Data Structures

struct  _MUTEX
 Recursive mutex. More...

Typedefs

typedef struct _MUTEX MUTEX
 Recursive mutex type.

Functions

void NutMutexInit (MUTEX *mutex)
 Create a mutex.
void NutMutexLock (MUTEX *mutex)
 Lock a mutex.
int NutMutexUnlock (MUTEX *mutex)
 Unlock a mutex.
int NutMutexTrylock (MUTEX *mutex)
 Attempt to lock a mutex without blocking.
int NutMutexDestroy (MUTEX *mutex)
 Free resources allocated for a mutex.

Detailed Description

Thread synchronization support.

In addition to posting and waiting for events, Threads can use the provided recursive mutex funxtions to assert mutual access to shared data structures.

A recursive mutex is a mutex that can be locked several times by the thread that already owns the mutex.


Typedef Documentation

typedef struct _MUTEX MUTEX

Recursive mutex type.

Definition at line 75 of file mutex.h.


Function Documentation

void NutMutexInit ( MUTEX mutex)

Create a mutex.

The type for the mutex is recursive

Definition at line 80 of file mutex.c.

References _MUTEX::count, NUTASSERT, _MUTEX::qhp, and _MUTEX::thread.

Referenced by NutConditionInit().

void NutMutexLock ( MUTEX mutex)

Lock a mutex.

If the mutex is already locked by another thread, the thread will block until the mutex becomes available

Note:
: Should not be called from interrupt context

Definition at line 96 of file mutex.c.

References _MUTEX::count, NUT_WAIT_INFINITE, NUTASSERT, NutEventWaitNext(), _MUTEX::qhp, runningThread, and _MUTEX::thread.

Referenced by NutConditionLock(), NutConditionTimedWait(), NutConditionWait(), and NutMutexTrylock().

Here is the call graph for this function:

int NutMutexUnlock ( MUTEX mutex)

Unlock a mutex.

Return zero, if successful, otherwise the current thread does not hold a lock on mutex.

Note:
: Should not be called from interrupt context

Definition at line 130 of file mutex.c.

References _MUTEX::count, NUTASSERT, NutEventPost(), _MUTEX::qhp, runningThread, and _MUTEX::thread.

Referenced by NutConditionTimedWait(), NutConditionUnlock(), and NutConditionWait().

Here is the call graph for this function:

int NutMutexTrylock ( MUTEX mutex)

Attempt to lock a mutex without blocking.

Return zero, if successful, otherwise the mutex is already locked by another thread

Note:
: Should not be called from interrupt context

Definition at line 114 of file mutex.c.

References _MUTEX::count, NUTASSERT, NutMutexLock(), runningThread, and _MUTEX::thread.

Here is the call graph for this function:

int NutMutexDestroy ( MUTEX mutex)

Free resources allocated for a mutex.

Return zero, if successful, otherwise the mutex is locked by another thread

Definition at line 147 of file mutex.c.

References _MUTEX::count, NUTASSERT, runningThread, and _MUTEX::thread.

Referenced by NutConditionFree().