Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
Data Structures | Macros | Typedefs | Functions
pthread.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/sched.h>
#include <common/list.h>
Include dependency graph for pthread.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  pthread_mutexattr_t
 
union  pthread_mutex_t
 
union  pthread_attr_t
 
union  pthread_cond_t
 
union  pthread_once_t
 

Macros

#define PTHREAD_ONCE_INIT
 
#define PTHREAD_CREATE_DETACHED   0
 
#define PTHREAD_CREATE_JOINABLE   1
 
#define PTHREAD_PRIO_NONE   0
 
#define PTHREAD_PRIO_INHERIT   1
 
#define __SIZEOF_PTHREAD_MUTEXATTR_T   4 /* sizeof(struct mutex_attr) */
 
#define __SIZEOF_PTHREAD_MUTEX_T   16 /* sizeof(struct mutex) */
 
#define __SIZEOF_PTHREAD_ATTR_T   20 /* sizeof(struct thread_attr) */
 
#define __SIZEOF_PTHREAD_COND_T   8 /* sizeof(struct cond) */
 
#define __SIZEOF_PTHREAD_ONCE_T   12 /* sizeof(struct thread_once) */
 

Typedefs

typedef uint32_t pthread_t
 
typedef uint32_t pthread_condattr_t
 

Functions

int pthread_attr_init (pthread_attr_t *attr)
 Initialize a thread attribute object with default values. More...
 
int pthread_attr_destroy (pthread_attr_t *attr)
 Destroy the given thread attribute object. More...
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)
 Set scheduling parameter of a thread attriute object. More...
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)
 Get scheduling parameter of a thread attriute object. More...
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 Set scheduling policy of a thread attriute object. More...
 
int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
 Get scheduling parameter of a thread attriute object. More...
 
int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int protocol)
 Set priority inheritance protocol of a mutex attriute object. More...
 
int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol)
 Get priority inheritance protocol of a mutex attriute object. More...
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 Set stack size parameter of a thread attriute object. More...
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 Get stack size parameter of a thread attriute object. More...
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 Set detach state parameter of a thread attriute object. More...
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 Get detach state parameter of a thread attriute object. More...
 
int pthread_attr_setstackaddr (pthread_attr_t *attr, void *stackaddr)
 Set stack address parameter of a thread attriute object. More...
 
int pthread_attr_getstackaddr (const pthread_attr_t *attr, void **stackaddr)
 Get stack address parameter of a thread attriute object. More...
 
int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
 Start a new thread in the calling task. More...
 
pthread_t pthread_self (void)
 Return the thread ID of the calling thread. More...
 
int pthread_join (pthread_t thread, void **retval)
 Wait for a thread specified with the thread ID to terminate. More...
 
int pthread_detach (pthread_t thread)
 Mark the thread identified by thread as detached. When a detached thread terminates, its resources are automatically released back to the system without the need for another thread to join with the terminated thread. More...
 
int pthread_cancel (pthread_t thread)
 Send a cancellation request to a thread specified with the thread ID. More...
 
int pthread_equal (pthread_t t1, pthread_t t2)
 Compare thread IDs. More...
 
int pthread_setschedparam (pthread_t thread, int policy, const struct sched_param *param)
 Set the scheduling parameters of a thread specified with the thread ID. More...
 
int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param)
 Get the scheduling parameters of a thread specified with the thread ID. More...
 
int pthread_yield (void)
 To cause the calling thread to relinquish the CPU. More...
 
int pthread_kill (pthread_t thread, int sig)
 Send a signal to a thread specified with the thread ID. More...
 
void pthread_exit (void *retval)
 Terminate the calling thread and returns a value via retval. More...
 
int pthread_mutexattr_init (pthread_mutexattr_t *attr)
 Initialize the mutex attribute object with default values. More...
 
int pthread_mutexattr_destroy (pthread_mutexattr_t *attr)
 Destroy the mutex attribute object. More...
 
int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
 Initialize the mutex with specified attributes. More...
 
int pthread_mutex_destroy (pthread_mutex_t *mutex)
 Destroy the mutex. More...
 
int pthread_mutex_unlock (pthread_mutex_t *mutex)
 Unlock the mutex. More...
 
int pthread_mutex_lock (pthread_mutex_t *mutex)
 Lock the mutex. More...
 
int pthread_mutex_trylock (pthread_mutex_t *mutex)
 Lock the mutex. If the mutex object referenced by mutex is currently locked (by any thread, including the current thread), the call shall return immediately. More...
 
int pthread_condattr_init (pthread_condattr_t *attr)
 Initialize the attribute object of conditional variable with default values. More...
 
int pthread_condattr_destroy (pthread_condattr_t *attr)
 Destroy the attribute object of the conditional variable. More...
 
int pthread_cond_init (pthread_cond_t *cond, pthread_condattr_t cond_attr)
 Initializes the conditional variable with specified attributes. More...
 
int pthread_cond_destroy (pthread_cond_t *cond)
 Destroy the conditional variable. More...
 
int pthread_cond_signal (pthread_cond_t *cond)
 Restart one of the threads that are waiting on the condition variable. More...
 
int pthread_cond_broadcast (pthread_cond_t *cond)
 Restart all of the threads that are waiting on the condition variable. More...
 
int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
 Atomically unlock the mutex and wait for the condition variable to be signaled. More...
 
int pthread_once (pthread_once_t *once_control, void(*init_routine)(void))
 To ensure a piece of initialization code is executed at most once. More...
 

Macro Definition Documentation

◆ PTHREAD_ONCE_INIT

#define PTHREAD_ONCE_INIT
Value:
{ \
.wq = {.next = NULL, .prev = NULL}, .finished = false \
}

Function Documentation

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t attr)

Destroy the given thread attribute object.

Parameters
attrThe thread attribute object to destroy.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_getdetachstate()

int pthread_attr_getdetachstate ( const pthread_attr_t attr,
int *  detachstate 
)

Get detach state parameter of a thread attriute object.

Parameters
attrThe attribute object to retrieve detach state.
detachstateFor returning the detach state from the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_getschedparam()

int pthread_attr_getschedparam ( const pthread_attr_t attr,
struct sched_param param 
)

Get scheduling parameter of a thread attriute object.

Parameters
attrThe attribute object to retrieve the scheduling parameter.
paramFor returning the scheduling parameter.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_getschedpolicy()

int pthread_attr_getschedpolicy ( const pthread_attr_t attr,
int *  policy 
)

Get scheduling parameter of a thread attriute object.

Parameters
attrThe attribute object to retrieve the scheduling policy.
paramFor returning the scheduling policy.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_getstackaddr()

int pthread_attr_getstackaddr ( const pthread_attr_t attr,
void **  stackaddr 
)

Get stack address parameter of a thread attriute object.

Parameters
attrThe attribute object to retrieve stack address.
detachstateFor returning the stack address from the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_getstacksize()

int pthread_attr_getstacksize ( const pthread_attr_t attr,
size_t *  stacksize 
)

Get stack size parameter of a thread attriute object.

Parameters
attrThe attribute object to retrieve stack size.
stacksizeFor returning the stack size from the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t attr)

Initialize a thread attribute object with default values.

Parameters
attrThe attribute object to initialize.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t attr,
int  detachstate 
)

Set detach state parameter of a thread attriute object.

Parameters
attrThe attribute object to set detach state.
detachstateThe detach state for setting the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_setschedparam()

int pthread_attr_setschedparam ( pthread_attr_t attr,
const struct sched_param param 
)

Set scheduling parameter of a thread attriute object.

Parameters
attrThe attribute object to set.
paramThe scheduling parameter for setting the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t attr,
int  policy 
)

Set scheduling policy of a thread attriute object.

Parameters
attrThe attribute object to set.
paramThe scheduling policy for setting the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_setstackaddr()

int pthread_attr_setstackaddr ( pthread_attr_t attr,
void *  stackaddr 
)

Set stack address parameter of a thread attriute object.

Parameters
attrThe attribute object to set stack address.
detachstateThe stack address for setting the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_attr_setstacksize()

int pthread_attr_setstacksize ( pthread_attr_t attr,
size_t  stacksize 
)

Set stack size parameter of a thread attriute object.

Parameters
attrThe attribute object to set.
paramThe stack size for setting the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_cancel()

int pthread_cancel ( pthread_t  thread)

Send a cancellation request to a thread specified with the thread ID.

Parameters
threadThe thread ID to provide.
Return values
int0 on success and nonzero error number on error.

◆ pthread_cond_broadcast()

int pthread_cond_broadcast ( pthread_cond_t cond)

Restart all of the threads that are waiting on the condition variable.

Parameters
condThe conditional variable to signal the state change.
Return values
int0 on success and nonzero error number on error.

◆ pthread_cond_destroy()

int pthread_cond_destroy ( pthread_cond_t cond)

Destroy the conditional variable.

Parameters
condThe conditional variable to destroy.
Return values
int0 on success and nonzero error number on error.

◆ pthread_cond_init()

int pthread_cond_init ( pthread_cond_t cond,
pthread_condattr_t  cond_attr 
)

Initializes the conditional variable with specified attributes.

Parameters
condThe conditional variable object to initialize.
cond_attrThe attribute object for initializing the conditional variable.
Return values
int0 on success and nonzero error number on error.

◆ pthread_cond_signal()

int pthread_cond_signal ( pthread_cond_t cond)

Restart one of the threads that are waiting on the condition variable.

Parameters
condThe conditional variable object to signal the state change.
Return values
int0 on success and nonzero error number on error.

◆ pthread_cond_wait()

int pthread_cond_wait ( pthread_cond_t cond,
pthread_mutex_t mutex 
)

Atomically unlock the mutex and wait for the condition variable to be signaled.

Parameters
condThe conditional variable object for waiting the state change.
Return values
int0 on success and nonzero error number on error.

◆ pthread_condattr_destroy()

int pthread_condattr_destroy ( pthread_condattr_t *  attr)

Destroy the attribute object of the conditional variable.

Parameters
attrThe attribute object of conditional variable to destroy.
Return values
int0 on success and nonzero error number on error.

◆ pthread_condattr_init()

int pthread_condattr_init ( pthread_condattr_t *  attr)

Initialize the attribute object of conditional variable with default values.

Parameters
attrThe attribute object of the conditional variable to initialize.
Return values
int0 on success and nonzero error number on error.

◆ pthread_create()

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

Start a new thread in the calling task.

Parameters
threadThe thread ID of the new thread to return.
attrThe attribute object for configuring the new thread.
start_routineThe function to be called after the thread is launched.
argThe sole argument of the start_routine to be provided.
Return values
int0 on success and nonzero error number on error.

◆ pthread_detach()

int pthread_detach ( pthread_t  thread)

Mark the thread identified by thread as detached. When a detached thread terminates, its resources are automatically released back to the system without the need for another thread to join with the terminated thread.

Parameters
threadThe thread ID to be provided.
Return values
int0 on success and nonzero error number on error.

◆ pthread_equal()

int pthread_equal ( pthread_t  t1,
pthread_t  t2 
)

Compare thread IDs.

Parameters
t1The first thread ID to be provided.
t2The second thread ID to be provided.
Return values
intIf the two thread IDs are equal, the function returns a nonzero value; otherwise, it returns 0.

◆ pthread_exit()

void pthread_exit ( void *  retval)

Terminate the calling thread and returns a value via retval.

Parameters
retvalThe return value pointer to provide.
Return values
None

◆ pthread_getschedparam()

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

Get the scheduling parameters of a thread specified with the thread ID.

Parameters
threadThe thread ID to provide.
policyNot used.
paramFor returning the scheduling parameter from the thread.
Return values
int0 on success and nonzero error number on error.

◆ pthread_join()

int pthread_join ( pthread_t  thread,
void **  retval 
)

Wait for a thread specified with the thread ID to terminate.

Parameters
threadThe thread ID to be provided.
retvalThe pointer to the return value pointer to provide.
Return values
int0 on success and nonzero error number on error.

◆ pthread_kill()

int pthread_kill ( pthread_t  thread,
int  sig 
)

Send a signal to a thread specified with the thread ID.

Parameters
threadThe thread ID to provide.
sigThe signal number to provide.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutex_destroy()

int pthread_mutex_destroy ( pthread_mutex_t mutex)

Destroy the mutex.

Parameters
mutexThe mutex to destroy.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutex_init()

int pthread_mutex_init ( pthread_mutex_t mutex,
const pthread_mutexattr_t attr 
)

Initialize the mutex with specified attributes.

Parameters
mutexThe mutex object to initialize.
attrThe attribute object for initializing the mutex.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutex_lock()

int pthread_mutex_lock ( pthread_mutex_t mutex)

Lock the mutex.

Parameters
mutexThe mutex to lock.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutex_trylock()

int pthread_mutex_trylock ( pthread_mutex_t mutex)

Lock the mutex. If the mutex object referenced by mutex is currently locked (by any thread, including the current thread), the call shall return immediately.

Parameters
mutexThe mutex to lock.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutex_unlock()

int pthread_mutex_unlock ( pthread_mutex_t mutex)

Unlock the mutex.

Parameters
mutexThe mutex to unlock.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutexattr_destroy()

int pthread_mutexattr_destroy ( pthread_mutexattr_t attr)

Destroy the mutex attribute object.

Parameters
attrThe mutex attribute object to destroy.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutexattr_getprotocol()

int pthread_mutexattr_getprotocol ( const pthread_mutexattr_t attr,
int *  protocol 
)

Get priority inheritance protocol of a mutex attriute object.

Parameters
attrThe attribute object to retrieve the priority inheritance protocol.
paramFor returning the priority inheritance protocol.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutexattr_init()

int pthread_mutexattr_init ( pthread_mutexattr_t attr)

Initialize the mutex attribute object with default values.

Parameters
attrThe mutex attribute object to initialize.
Return values
int0 on success and nonzero error number on error.

◆ pthread_mutexattr_setprotocol()

int pthread_mutexattr_setprotocol ( pthread_mutexattr_t attr,
int  protocol 
)

Set priority inheritance protocol of a mutex attriute object.

Parameters
attrThe attribute object to set.
paramThe protocol to set the attribute object.
Return values
int0 on success and nonzero error number on error.

◆ pthread_once()

int pthread_once ( pthread_once_t once_control,
void(*)(void)  init_routine 
)

To ensure a piece of initialization code is executed at most once.

Parameters
once_controlThe object to track the execution state of the init_routine.
init_routineThe function to be called for once.
Return values
int0 on success and nonzero error number on error.

◆ pthread_self()

pthread_t pthread_self ( void  )

Return the thread ID of the calling thread.

Parameters
None
Return values
pthread_tThe thread ID.

◆ pthread_setschedparam()

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

Set the scheduling parameters of a thread specified with the thread ID.

Parameters
threadThread ID to provide.
policyNot used.
paramThe scheduling parameter to set the thread.
Return values
int0 on success and nonzero error number on error.

◆ pthread_yield()

int pthread_yield ( void  )

To cause the calling thread to relinquish the CPU.

Parameters
None
Return values
int0 on success and nonzero error number on error.