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

Implementation of thread 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"

Data Structures

struct  pthread_attr_internal_t
 Thread attribute object. More...
 
struct  pthread_internal_t
 Thread object. More...
 

Macros

#define pthreadDETACH_STATE_MASK   0x8000
 
#define pthreadSCHED_PRIORITY_MASK   0x7FFF
 
#define pthreadDETACH_STATE_SHIFT   15
 
#define pthreadGET_SCHED_PRIORITY(var)   ( ( var ) & ( pthreadSCHED_PRIORITY_MASK ) )
 
#define pthreadIS_JOINABLE(var)   ( ( ( var ) & ( pthreadDETACH_STATE_MASK ) ) == pthreadDETACH_STATE_MASK )
 

Functions

static void prvExitThread (void)
 Terminates the calling thread. More...
 
static void prvRunThread (void *pxArg)
 Wrapper function for the user's thread routine. More...
 
int pthread_attr_destroy (pthread_attr_t *attr)
 Destroy the thread attributes object. More...
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 Get detachstate attribute. More...
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)
 Get schedparam attribute. More...
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 Get stacksize attribute. More...
 
int pthread_attr_init (pthread_attr_t *attr)
 Initialize the thread attributes object. More...
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 Set detachstate attribute. More...
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)
 Set schedparam attribute. More...
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 Set the schedpolicy attribute. More...
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 Set stacksize attribute. More...
 
int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*startroutine)(void *), void *arg)
 Thread creation. More...
 
int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param)
 Dynamic thread scheduling parameters access. More...
 
int pthread_equal (pthread_t t1, pthread_t t2)
 Compare thread IDs. More...
 
void pthread_exit (void *value_ptr)
 Thread termination. More...
 
int pthread_join (pthread_t pthread, void **retval)
 Wait for thread termination. More...
 
pthread_t pthread_self (void)
 Get the calling thread ID. More...
 
int pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param)
 Dynamic thread scheduling parameters access. More...
 

Variables

static const pthread_attr_internal_t xDefaultThreadAttributes
 Default pthread_attr_t. More...
 

Detailed Description

Implementation of thread functions in pthread.h.

Function Documentation

◆ prvExitThread()

static void prvExitThread ( void  )
static

Terminates the calling thread.

For joinable threads, this function waits for pthread_join. Otherwise, it deletes the thread and frees up resources used by the thread.

Returns
This function does not return.

◆ prvRunThread()

static void prvRunThread ( void *  pxArg)
static

Wrapper function for the user's thread routine.

This function is executed as a FreeRTOS task function.

Parameters
[in]pxArgA pointer to a pthread_internal_t.
Returns
nothing

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t attr)

Destroy the thread attributes object.

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

◆ pthread_attr_getdetachstate()

int pthread_attr_getdetachstate ( const pthread_attr_t attr,
int *  detachstate 
)

Get detachstate attribute.

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

◆ pthread_attr_getschedparam()

int pthread_attr_getschedparam ( const pthread_attr_t attr,
struct sched_param param 
)

Get schedparam attribute.

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

◆ pthread_attr_getstacksize()

int pthread_attr_getstacksize ( const pthread_attr_t attr,
size_t *  stacksize 
)

Get stacksize attribute.

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

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t attr)

Initialize the thread attributes object.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_init.html
Return values
0- Upon successful completion.
Note
Currently, only stack size, sched_param, and detach state attributes are supported. Also see pthread_attr_get*() and pthread_attr_set*().

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t attr,
int  detachstate 
)

Set detachstate attribute.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setdetachstate.html
Return values
0- Upon successful completion
EINVAL- The value of detachstate is not valid. Currently, supported detach states are – PTHREAD_CREATE_DETACHED and PTHREAD_CREATE_JOINABLE.

◆ pthread_attr_setschedparam()

int pthread_attr_setschedparam ( pthread_attr_t attr,
const struct sched_param param 
)

Set schedparam attribute.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedparam.html
Return values
0- Upon successful completion.
EINVAL- The value of param is not valid.
ENOTSUP- An attempt was made to set the attribute to an unsupported value.

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t attr,
int  policy 
)

Set the schedpolicy attribute.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setschedpolicy.html

Return values
0- Upon successful completion.
Warning
This function is a stub and always returns 0.

◆ pthread_attr_setstacksize()

int pthread_attr_setstacksize ( pthread_attr_t attr,
size_t  stacksize 
)

Set stacksize attribute.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_setstacksize.html
Return values
0- Upon successful completion.
EINVAL- The value of stacksize is less than {PTHREAD_STACK_MIN}.

◆ pthread_create()

int pthread_create ( pthread_t thread,
const pthread_attr_t attr,
void *(*)(void *)  startroutine,
void *  arg 
)

Thread creation.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html
Return values
0- Upon successful completion.
EAGAIN- Insufficient memory for either thread structure or task creation.

◆ pthread_getschedparam()

int pthread_getschedparam ( pthread_t  thread,
int *  policy,
struct sched_param param 
)

Dynamic thread scheduling parameters access.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getschedparam.html
Return values
0- Upon successful completion.
Note
policy is always set to SCHED_OTHER by this function.

◆ pthread_equal()

int pthread_equal ( pthread_t  t1,
pthread_t  t2 
)

Compare thread IDs.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html
Return values
0- t1 and t2 are both not NULL && equal.
non-zero- otherwise.

◆ pthread_exit()

void pthread_exit ( void *  value_ptr)

Thread termination.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_exit.html
Return values
void- this function cannot return to its caller.

◆ pthread_join()

int pthread_join ( pthread_t  thread,
void **  retval 
)

Wait for thread termination.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_join.html
Return values
0- Upon successful completion.
EDEADLK- The value specified by the thread argument to pthread_join() does not refer to a joinable thread OR multiple simultaneous calls to pthread_join() specifying the same target thread OR the value specified by the thread argument to pthread_join() refers to the calling thread.

◆ pthread_self()

pthread_t pthread_self ( void  )

Get the calling thread ID.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_self.html
Return values
thethread ID of the calling thread.

◆ pthread_setschedparam()

int pthread_setschedparam ( pthread_t  thread,
int  policy,
const struct sched_param param 
)

Dynamic thread scheduling parameters access.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_setschedparam.html
Note
policy is ignored; only priority (param.sched_priority) may be changed.
Return values
0- Upon successful completion.

Variable Documentation

◆ xDefaultThreadAttributes

const pthread_attr_internal_t xDefaultThreadAttributes
static
Initial value:
=
{
.usStackSize = PTHREAD_STACK_MIN,
.usSchedPriorityDetachState = ( ( uint16_t ) tskIDLE_PRIORITY & pthreadSCHED_PRIORITY_MASK ) | ( PTHREAD_CREATE_JOINABLE << pthreadDETACH_STATE_SHIFT ),
}
#define PTHREAD_STACK_MIN
Definition: FreeRTOS_POSIX_portable_default.h:72
#define PTHREAD_CREATE_JOINABLE
Definition: pthread.h:46

Default pthread_attr_t.