FreeRTOS: POSIX
Return to main page ↑
FreeRTOS_POSIX_pthread_mutex.c File Reference

Implementation of mutex functions in pthread.h. More...

#include <stddef.h>
#include <string.h>
#include "FreeRTOS_POSIX.h"
#include "FreeRTOS_POSIX/errno.h"
#include "FreeRTOS_POSIX/pthread.h"
#include "FreeRTOS_POSIX/utils.h"

Functions

static void prvInitializeStaticMutex (pthread_mutex_internal_t *pxMutex)
 Initialize a PTHREAD_MUTEX_INITIALIZER mutex. More...
 
int pthread_mutex_destroy (pthread_mutex_t *mutex)
 Destroy a mutex. More...
 
int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
 Initialize 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 *abstime)
 Lock a mutex with timeout. More...
 
int pthread_mutex_trylock (pthread_mutex_t *mutex)
 Attempt to lock a mutex. Fail immediately if mutex is already locked. More...
 
int pthread_mutex_unlock (pthread_mutex_t *mutex)
 Unlock a mutex. More...
 
int pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
 Destroy the mutex attributes object. More...
 
int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
 Get the mutex type attribute. More...
 
int pthread_mutexattr_init (pthread_mutexattr_t *attr)
 Initialize the mutex attributes object. More...
 
int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
 Set the mutex type attribute. More...
 

Variables

static const pthread_mutexattr_internal_t xDefaultMutexAttributes
 Default pthread_mutexattr_t. More...
 

Detailed Description

Implementation of mutex functions in pthread.h.

Function Documentation

◆ prvInitializeStaticMutex()

static void prvInitializeStaticMutex ( pthread_mutex_internal_t *  pxMutex)
static

Initialize a PTHREAD_MUTEX_INITIALIZER mutex.

PTHREAD_MUTEX_INITIALIZER sets a flag for a mutex to be initialized later. This function performs the initialization.

Parameters
[in]pxMutexThe mutex to initialize.
Returns
nothing

◆ pthread_mutex_destroy()

int pthread_mutex_destroy ( pthread_mutex_t mutex)

Destroy a mutex.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html
Return values
0- Upon successful completion.
Note
If there exists a thread holding this mutex, this function returns 0 with mutex not being destroyed.

◆ pthread_mutex_init()

int pthread_mutex_init ( pthread_mutex_t mutex,
const pthread_mutexattr_t attr 
)

Initialize a mutex.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html
Return values
0- Upon successful completion.
ENOMEM- Insufficient memory exists to initialize the mutex structure.
EAGAIN- Unable to initialize the mutex structure member(s).

◆ pthread_mutex_lock()

int pthread_mutex_lock ( pthread_mutex_t mutex)

Lock a mutex.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
Return values
0- Upon successful completion.
EINVAL- the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
EDEADLK- The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.

◆ pthread_mutex_timedlock()

int pthread_mutex_timedlock ( pthread_mutex_t mutex,
const struct timespec abstime 
)

Lock a mutex with timeout.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html
Return values
0- Upon successful completion.
EINVAL- The abstime argument passed in does not refer to an initialized structure OR the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
EDEADLK- The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.
ETIMEDOUT- The mutex could not be locked before the specified timeout expired.

◆ pthread_mutex_trylock()

int pthread_mutex_trylock ( pthread_mutex_t mutex)

Attempt to lock a mutex. Fail immediately if mutex is already locked.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_trylock.html
Return values
0- Upon successful completion.
EINVAL- the abstime parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million.
EDEADLK- The mutex type is PTHREAD_MUTEX_ERRORCHECK and the current thread already owns the mutex.
EBUSY- The mutex could not be acquired because it was already locked.

◆ pthread_mutex_unlock()

int pthread_mutex_unlock ( pthread_mutex_t mutex)

Unlock a mutex.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_unlock.html
Return values
0- Upon successful completion.
EPERM- The mutex type is PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_RECURSIVE, and the current thread does not own the mutex.

◆ pthread_mutexattr_destroy()

int pthread_mutexattr_destroy ( pthread_mutexattr_t attr)

Destroy the mutex attributes object.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_destroy.html
Return values
0- Upon successful completion.

◆ pthread_mutexattr_gettype()

int pthread_mutexattr_gettype ( const pthread_mutexattr_t attr,
int *  type 
)

Get the mutex type attribute.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html
Return values
0- Upon successful completion.

◆ pthread_mutexattr_init()

int pthread_mutexattr_init ( pthread_mutexattr_t attr)

Initialize the mutex attributes object.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_init.html
Return values
0- Upon successful completion.
Note
Currently, only the type attribute is supported. Also see pthread_mutexattr_settype() and pthread_mutexattr_gettype().

◆ pthread_mutexattr_settype()

int pthread_mutexattr_settype ( pthread_mutexattr_t attr,
int  type 
)

Set the mutex type attribute.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_settype.html
Return values
0- Upon successful completion.
EINVAL- The value type is invalid.

Variable Documentation

◆ xDefaultMutexAttributes

const pthread_mutexattr_internal_t xDefaultMutexAttributes
static
Initial value:
=
{
}
#define PTHREAD_MUTEX_DEFAULT
Definition: pthread.h:72

Default pthread_mutexattr_t.