Xenomai
3.1
|
Cobalt/POSIX mutual exclusion services. More...
Functions | |
int | pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) |
Initialize a mutex. More... | |
static int | __attribute__ ((cold)) |
Test if a mutex structure contains a valid autoinitializer. 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_mutex_setprioceiling (pthread_mutex_t *__restrict mutex, int prioceiling, int *__restrict old_ceiling) |
Set a mutex's priority ceiling. More... | |
int | pthread_mutex_getprioceiling (pthread_mutex_t *__restrict mutex, int *__restrict prioceiling) |
Get a mutex's priority ceiling. 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 pthread_mutex_init() should be used to initialize a mutex, using the static initializer PTHREAD_MUTEX_INITIALIZER will delay the initialization to the first method called on the mutex and will most likely introduce switches to secondary mode. The documentation (and specifically api-tags) of the mutex services assumes a mutex was explicitly initialised with pthread_mutex_init().
|
static |
Test if a mutex structure contains a valid autoinitializer.
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_getprioceiling | ( | pthread_mutex_t *__restrict | mutex, |
int *__restrict | prioceiling | ||
) |
Get a mutex's priority ceiling.
This routine retrieves the priority ceiling value of the specified mutex.
mutex | the target mutex. |
prioceiling | on success, the current ceiling value is copied to this address. |
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. |
int pthread_mutex_setprioceiling | ( | pthread_mutex_t *__restrict | mutex, |
int | prioceiling, | ||
int *__restrict | old_ceiling | ||
) |
Set a mutex's priority ceiling.
This routine acquires the specified mutex, then changes the associated priority ceiling value and releases it. prioceiling must be between the values returned by sched_get_priority_min() and sched_get_priority_max(), inclusive.
The Cobalt implementation applies the priority ceiling protocol using the previous ceiling value during this operation. The new priority ceiling will apply next time the mutex transitions from the unlocked to locked state.
mutex | the target mutex. |
prioceiling | the new ceiling value. |
old_ceiling | on success and if this parameter is non-NULL, the previous ceiling value is copied to this address. |
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. |
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. If mutex is of the PTHREAD_MUTEX_RECURSIVE 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. |
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. |
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 be one of PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT. See pthread_mutexattr_setprotocol() for the meaning of these constants.
attr | an initialized mutex attributes object; |
proto | address where the value of the protocol attribute will be stored on success. |
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. |
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. |
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. |
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:
|
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:
|
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. |