Xenomai
3.0.5
|
Cobalt/POSIX mutual exclusion services. More...
Functions | |
int | pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) |
Initialize a mutex. More... | |
int | pthread_mutex_destroy (pthread_mutex_t *mutex) |
Destroy a mutex. More... | |
int | pthread_mutex_lock (pthread_mutex_t *mutex) |
Lock a mutex. More... | |
int | pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *to) |
Attempt, during a bounded time, to lock a mutex. More... | |
int | pthread_mutex_trylock (pthread_mutex_t *mutex) |
Attempt to lock a mutex. More... | |
int | pthread_mutex_unlock (pthread_mutex_t *mutex) |
Unlock a mutex. More... | |
int | pthread_mutexattr_init (pthread_mutexattr_t *attr) |
Initialize a mutex attributes object. More... | |
int | pthread_mutexattr_destroy (pthread_mutexattr_t *attr) |
Destroy a mutex attributes object. More... | |
int | pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type) |
Get the mutex type attribute from a mutex attributes object. More... | |
int | pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) |
Set the mutex type attribute of a mutex attributes object. More... | |
int | pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *proto) |
Get the protocol attribute from a mutex attributes object. More... | |
int | pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int proto) |
Set the protocol attribute of a mutex attributes object. More... | |
int | pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr, int *pshared) |
Get the process-shared attribute of a mutex attributes object. More... | |
int | pthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int pshared) |
Set the process-shared attribute of a mutex attributes object. More... | |
Cobalt/POSIX mutual exclusion services.
A mutex is a MUTual EXclusion device, and is useful for protecting shared data structures from concurrent modifications, and implementing critical sections and monitors.
A mutex has two possible states: unlocked (not owned by any thread), and locked (owned by one thread). A mutex can never be owned by two different threads simultaneously. A thread attempting to lock a mutex that is already locked by another thread is suspended until the owning thread unlocks the mutex first.
Before it can be used, a mutex has to be initialized with pthread_mutex_init(). An attribute object, which reference may be passed to this service, allows to select the features of the created mutex, namely its type (see pthread_mutexattr_settype()), the priority protocol it uses (see pthread_mutexattr_setprotocol()) and whether it may be shared between several processes (see pthread_mutexattr_setpshared()).
By default, Cobalt mutexes are of the normal type, use no priority protocol and may not be shared between several processes.
Note that only pthread_mutex_init() may be used to initialize a mutex, using the static initializer PTHREAD_MUTEX_INITIALIZER is not supported.
int pthread_mutex_destroy | ( | pthread_mutex_t * | mutex | ) |
Destroy a mutex.
This service destroys the mutex mx, if it is unlocked and not referenced by any condition variable. The mutex becomes invalid for all mutex services (they all return the EINVAL error) except pthread_mutex_init().
mutex | the mutex to be destroyed. |
int pthread_mutex_init | ( | pthread_mutex_t * | mutex, |
const pthread_mutexattr_t * | attr | ||
) |
Initialize a mutex.
This services initializes the mutex mx, using the mutex attributes object attr. If attr is NULL, default attributes are used (see pthread_mutexattr_init()).
mutex | the mutex to be initialized; |
attr | the mutex attributes object. |
int pthread_mutex_lock | ( | pthread_mutex_t * | mutex | ) |
Lock a mutex.
This service attempts to lock the mutex mx. If the mutex is free, it becomes locked. If it was locked by another thread than the current one, the current thread is suspended until the mutex is unlocked. If it was already locked by the current mutex, the behaviour of this service depends on the mutex type :
mutex | the mutex to be locked. |
References pthread_mutex_timedlock(), XNDEBUG, XNRELAX, and XNWEAK.
int pthread_mutex_timedlock | ( | pthread_mutex_t * | mutex, |
const struct timespec * | to | ||
) |
Attempt, during a bounded time, to lock a mutex.
This service is equivalent to pthread_mutex_lock(), except that if the mutex mx is locked by another thread than the current one, this service only suspends the current thread until the timeout specified by to expires.
mutex | the mutex to be locked; |
to | the timeout, expressed as an absolute value of the CLOCK_REALTIME clock. |
References XNDEBUG, XNRELAX, and XNWEAK.
Referenced by pthread_mutex_lock().
int pthread_mutex_trylock | ( | pthread_mutex_t * | mutex | ) |
Attempt to lock a mutex.
This service is equivalent to pthread_mutex_lock(), except that if the mutex mx is locked by another thread than the current one, this service returns immediately.
mutex | the mutex to be locked. |
int pthread_mutex_unlock | ( | pthread_mutex_t * | mutex | ) |
Unlock a mutex.
This service unlocks the mutex mx. If the mutex is of the PTHREAD_MUTEX_RECURSIVE type and the locking recursion count is greater than one, the lock recursion count is decremented and the mutex remains locked.
Attempting to unlock a mutex which is not locked or which is locked by another thread than the current one yields the EPERM error, whatever the mutex type attribute.
mutex | the mutex to be released. |
References pthread_mutexattr_destroy(), pthread_mutexattr_getprotocol(), pthread_mutexattr_getpshared(), pthread_mutexattr_gettype(), pthread_mutexattr_init(), pthread_mutexattr_setprotocol(), pthread_mutexattr_setpshared(), pthread_mutexattr_settype(), XNDEBUG, and XNWEAK.
int pthread_mutexattr_destroy | ( | pthread_mutexattr_t * | attr | ) |
Destroy a mutex attributes object.
This service destroys the mutex attributes object attr. The object becomes invalid for all mutex services (they all return EINVAL) except pthread_mutexattr_init().
attr | the initialized mutex attributes object to be destroyed. |
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_getprotocol | ( | const pthread_mutexattr_t * | attr, |
int * | proto | ||
) |
Get the protocol attribute from a mutex attributes object.
This service stores, at the address proto, the value of the protocol attribute in the mutex attributes object attr.
The protcol attribute may only be one of PTHREAD_PRIO_NONE or PTHREAD_PRIO_INHERIT. See pthread_mutexattr_setprotocol() for the meaning of these two constants.
attr | an initialized mutex attributes object; |
proto | address where the value of the protocol attribute will be stored on success. |
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_getpshared | ( | const pthread_mutexattr_t * | attr, |
int * | pshared | ||
) |
Get the process-shared attribute of a mutex attributes object.
This service stores, at the address pshared, the value of the pshared attribute in the mutex attributes object attr.
The pashared attribute may only be one of PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED. See pthread_mutexattr_setpshared() for the meaning of these two constants.
attr | an initialized mutex attributes object; |
pshared | address where the value of the pshared attribute will be stored on success. |
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_gettype | ( | const pthread_mutexattr_t * | attr, |
int * | type | ||
) |
Get the mutex type attribute from a mutex attributes object.
This service stores, at the address type, the value of the type attribute in the mutex attributes object attr.
See pthread_mutex_lock() and pthread_mutex_unlock() for a description of the values of the type attribute and their effect on a mutex.
attr | an initialized mutex attributes object, |
type | address where the type attribute value will be stored on success. |
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_init | ( | pthread_mutexattr_t * | attr | ) |
Initialize a mutex attributes object.
This services initializes the mutex attributes object attr with default values for all attributes. Default value are :
If this service is called specifying a mutex attributes object that was already initialized, the attributes object is reinitialized.
attr | the mutex attributes object to be initialized. |
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_setprotocol | ( | pthread_mutexattr_t * | attr, |
int | proto | ||
) |
Set the protocol attribute of a mutex attributes object.
This service set the type attribute of the mutex attributes object attr.
attr | an initialized mutex attributes object, |
proto | value of the protocol attribute, may be one of:
|
The value PTHREAD_PRIO_PROTECT (priority ceiling protocol) is unsupported.
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_setpshared | ( | pthread_mutexattr_t * | attr, |
int | pshared | ||
) |
Set the process-shared attribute of a mutex attributes object.
This service set the pshared attribute of the mutex attributes object attr.
attr | an initialized mutex attributes object. |
pshared | value of the pshared attribute, may be one of:
|
Referenced by pthread_mutex_unlock().
int pthread_mutexattr_settype | ( | pthread_mutexattr_t * | attr, |
int | type | ||
) |
Set the mutex type attribute of a mutex attributes object.
This service set the type attribute of the mutex attributes object attr.
See pthread_mutex_lock() and pthread_mutex_unlock() for a description of the values of the type attribute and their effect on a mutex.
The PTHREAD_MUTEX_DEFAULT default type is the same as PTHREAD_MUTEX_NORMAL. Note that using a recursive Cobalt mutex with a Cobalt condition variable is safe (see pthread_cond_wait() documentation).
attr | an initialized mutex attributes object, |
type | value of the type attribute. |
Referenced by pthread_mutex_unlock().