Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
pthread.h File Reference
#include <kernel.h>
#include <wait_q.h>
#include <posix/time.h>
#include <posix/unistd.h>
#include "posix_types.h"
#include "posix_sched.h"
#include <posix/pthread_key.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  posix_thread
 

Macros

#define PTHREAD_CREATE_JOINABLE   PTHREAD_JOINABLE
 
#define PTHREAD_CREATE_DETACHED   PTHREAD_DETACHED
 
#define PTHREAD_CANCEL_ENABLE   (0U << _PTHREAD_CANCEL_POS)
 
#define PTHREAD_CANCEL_DISABLE   BIT(_PTHREAD_CANCEL_POS)
 
#define PTHREAD_ONCE_INIT   1
 
#define PTHREAD_COND_DEFINE(name)
 Declare a pthread condition variable. More...
 
#define PTHREAD_MUTEX_DEFINE(name)
 Declare a pthread mutex. More...
 
#define PTHREAD_MUTEX_NORMAL   0
 
#define PTHREAD_MUTEX_RECURSIVE   1
 
#define PTHREAD_MUTEX_ERRORCHECK   2
 
#define PTHREAD_MUTEX_DEFAULT   PTHREAD_MUTEX_NORMAL
 
#define PTHREAD_PRIO_NONE   0
 
#define PTHREAD_BARRIER_DEFINE(name, count)
 Declare a pthread barrier. More...
 
#define PTHREAD_BARRIER_SERIAL_THREAD   1
 

Enumerations

enum  pthread_state { PTHREAD_TERMINATED = 0 , PTHREAD_JOINABLE , PTHREAD_DETACHED , PTHREAD_EXITED }
 

Functions

static int pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *att)
 POSIX threading compatibility API. More...
 
static int pthread_cond_destroy (pthread_cond_t *cv)
 POSIX threading compatibility API. More...
 
int pthread_cond_signal (pthread_cond_t *cv)
 POSIX threading compatibility API. More...
 
int pthread_cond_broadcast (pthread_cond_t *cv)
 POSIX threading compatibility API. More...
 
int pthread_cond_wait (pthread_cond_t *cv, pthread_mutex_t *mut)
 POSIX threading compatibility API. More...
 
int pthread_cond_timedwait (pthread_cond_t *cv, pthread_mutex_t *mut, const struct timespec *abstime)
 POSIX threading compatibility API. More...
 
static int pthread_condattr_init (pthread_condattr_t *att)
 POSIX threading compatibility API. More...
 
static int pthread_condattr_destroy (pthread_condattr_t *att)
 POSIX threading compatibility API. More...
 
int pthread_mutex_destroy (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_lock (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_unlock (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_timedlock (pthread_mutex_t *m, const struct timespec *abstime)
 POSIX threading compatibility API. More...
 
int pthread_mutex_trylock (pthread_mutex_t *m)
 POSIX threading compatibility API. More...
 
int pthread_mutex_init (pthread_mutex_t *m, const pthread_mutexattr_t *att)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int protocol)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol)
 POSIX threading compatibility API. More...
 
int pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type)
 POSIX threading compatibility API. More...
 
static int pthread_mutexattr_init (pthread_mutexattr_t *m)
 POSIX threading compatibility API. More...
 
static int pthread_mutexattr_destroy (pthread_mutexattr_t *m)
 POSIX threading compatibility API. More...
 
int pthread_barrier_wait (pthread_barrier_t *b)
 POSIX threading compatibility API. More...
 
static int pthread_barrier_init (pthread_barrier_t *b, const pthread_barrierattr_t *attr, unsigned int count)
 POSIX threading compatibility API. More...
 
static int pthread_barrier_destroy (pthread_barrier_t *b)
 POSIX threading compatibility API. More...
 
static int pthread_barrierattr_init (pthread_barrierattr_t *b)
 POSIX threading compatibility API. More...
 
static int pthread_barrierattr_destroy (pthread_barrierattr_t *b)
 POSIX threading compatibility API. More...
 
static pthread_t pthread_self (void)
 Obtain ID of the calling thread. More...
 
static int pthread_equal (pthread_t pt1, pthread_t pt2)
 Compare thread IDs. More...
 
static int pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr)
 Destroy the read-write lock attributes object. More...
 
static int pthread_rwlockattr_init (pthread_rwlockattr_t *attr)
 initialize the read-write lock attributes object. More...
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 
int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 
int pthread_attr_init (pthread_attr_t *attr)
 
int pthread_attr_destroy (pthread_attr_t *attr)
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *schedparam)
 
int pthread_getschedparam (pthread_t pthread, int *policy, struct sched_param *param)
 
int pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
 
int pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, size_t stacksize)
 
int pthread_once (pthread_once_t *once, void(*initFunc)(void))
 
void pthread_exit (void *retval)
 
int pthread_join (pthread_t thread, void **status)
 
int pthread_cancel (pthread_t pthread)
 
int pthread_detach (pthread_t thread)
 
int pthread_create (pthread_t *newthread, const pthread_attr_t *attr, void *(*threadroutine)(void *), void *arg)
 
int pthread_setcancelstate (int state, int *oldstate)
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *schedparam)
 
int pthread_setschedparam (pthread_t pthread, int policy, const struct sched_param *param)
 
int pthread_rwlock_destroy (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
 
int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, const struct timespec *abstime)
 
int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, const struct timespec *abstime)
 
int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
 
int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
 
int pthread_key_create (pthread_key_t *key, void(*destructor)(void *))
 
int pthread_key_delete (pthread_key_t key)
 
int pthread_setspecific (pthread_key_t key, const void *value)
 
voidpthread_getspecific (pthread_key_t key)
 
int pthread_setname_np (pthread_t thread, const char *name)
 Set name of POSIX thread. More...
 
int pthread_getname_np (pthread_t thread, char *name, size_t len)
 Get name of POSIX thread and store in name buffer that is of size len. More...
 

Macro Definition Documentation

◆ PTHREAD_BARRIER_DEFINE

#define PTHREAD_BARRIER_DEFINE (   name,
  count 
)
Value:
struct pthread_barrier name = { \
.wait_q = Z_WAIT_Q_INIT(&name.wait_q), \
.max = count, \
}
ZTEST_BMEM int count
Definition: main.c:33

Declare a pthread barrier.

Declaration API for a pthread barrier. This is not a POSIX API, it's provided to better conform with Zephyr's allocation strategies for kernel objects.

Parameters
nameSymbol name of the barrier
countThread count, same as the "count" argument to pthread_barrier_init()

◆ PTHREAD_BARRIER_SERIAL_THREAD

#define PTHREAD_BARRIER_SERIAL_THREAD   1

◆ PTHREAD_CANCEL_DISABLE

#define PTHREAD_CANCEL_DISABLE   BIT(_PTHREAD_CANCEL_POS)

◆ PTHREAD_CANCEL_ENABLE

#define PTHREAD_CANCEL_ENABLE   (0U << _PTHREAD_CANCEL_POS)

◆ PTHREAD_COND_DEFINE

#define PTHREAD_COND_DEFINE (   name)
Value:
struct pthread_cond name = { \
.wait_q = Z_WAIT_Q_INIT(&name.wait_q), \
}

Declare a pthread condition variable.

Declaration API for a pthread condition variable. This is not a POSIX API, it's provided to better conform with Zephyr's allocation strategies for kernel objects.

Parameters
nameSymbol name of the condition variable

◆ PTHREAD_CREATE_DETACHED

#define PTHREAD_CREATE_DETACHED   PTHREAD_DETACHED

◆ PTHREAD_CREATE_JOINABLE

#define PTHREAD_CREATE_JOINABLE   PTHREAD_JOINABLE

◆ PTHREAD_MUTEX_DEFAULT

#define PTHREAD_MUTEX_DEFAULT   PTHREAD_MUTEX_NORMAL

◆ PTHREAD_MUTEX_DEFINE

#define PTHREAD_MUTEX_DEFINE (   name)
Value:
struct pthread_mutex name = \
{ \
.lock_count = 0, \
.wait_q = Z_WAIT_Q_INIT(&name.wait_q), \
.owner = NULL, \
}

Declare a pthread mutex.

Declaration API for a pthread mutex. This is not a POSIX API, it's provided to better conform with Zephyr's allocation strategies for kernel objects.

Parameters
nameSymbol name of the mutex

◆ PTHREAD_MUTEX_ERRORCHECK

#define PTHREAD_MUTEX_ERRORCHECK   2

◆ PTHREAD_MUTEX_NORMAL

#define PTHREAD_MUTEX_NORMAL   0

◆ PTHREAD_MUTEX_RECURSIVE

#define PTHREAD_MUTEX_RECURSIVE   1

◆ PTHREAD_ONCE_INIT

#define PTHREAD_ONCE_INIT   1

◆ PTHREAD_PRIO_NONE

#define PTHREAD_PRIO_NONE   0

Enumeration Type Documentation

◆ pthread_state

Enumerator
PTHREAD_TERMINATED 
PTHREAD_JOINABLE 
PTHREAD_DETACHED 
PTHREAD_EXITED 

Function Documentation

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t *  attr)

◆ pthread_attr_getdetachstate()

int pthread_attr_getdetachstate ( const pthread_attr_t *  attr,
int *  detachstate 
)

◆ pthread_attr_getschedparam()

int pthread_attr_getschedparam ( const pthread_attr_t *  attr,
struct sched_param schedparam 
)

◆ pthread_attr_getschedpolicy()

int pthread_attr_getschedpolicy ( const pthread_attr_t *  attr,
int *  policy 
)

◆ pthread_attr_getstack()

int pthread_attr_getstack ( const pthread_attr_t *  attr,
void **  stackaddr,
size_t *  stacksize 
)

◆ pthread_attr_getstacksize()

int pthread_attr_getstacksize ( const pthread_attr_t *  attr,
size_t *  stacksize 
)

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t *  attr)

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t *  attr,
int  detachstate 
)

◆ pthread_attr_setschedparam()

int pthread_attr_setschedparam ( pthread_attr_t *  attr,
const struct sched_param schedparam 
)

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t *  attr,
int  policy 
)

◆ pthread_attr_setstack()

int pthread_attr_setstack ( pthread_attr_t *  attr,
void stackaddr,
size_t  stacksize 
)

◆ pthread_barrier_destroy()

static int pthread_barrier_destroy ( pthread_barrier_t *  b)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_barrier_init()

static int pthread_barrier_init ( pthread_barrier_t *  b,
const pthread_barrierattr_t *  attr,
unsigned int  count 
)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_barrier_wait()

int pthread_barrier_wait ( pthread_barrier_t *  b)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_barrierattr_destroy()

static int pthread_barrierattr_destroy ( pthread_barrierattr_t *  b)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_barrierattr_init()

static int pthread_barrierattr_init ( pthread_barrierattr_t *  b)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_cancel()

int pthread_cancel ( pthread_t  pthread)

◆ pthread_cond_broadcast()

int pthread_cond_broadcast ( pthread_cond_t *  cv)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_destroy()

static int pthread_cond_destroy ( pthread_cond_t *  cv)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_init()

static int pthread_cond_init ( pthread_cond_t *  cv,
const pthread_condattr_t *  att 
)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_signal()

int pthread_cond_signal ( pthread_cond_t *  cv)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_timedwait()

int pthread_cond_timedwait ( pthread_cond_t *  cv,
pthread_mutex_t *  mut,
const struct timespec abstime 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_cond_wait()

int pthread_cond_wait ( pthread_cond_t *  cv,
pthread_mutex_t *  mut 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_condattr_destroy()

static int pthread_condattr_destroy ( pthread_condattr_t *  att)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_condattr_init()

static int pthread_condattr_init ( pthread_condattr_t *  att)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1.

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_create()

int pthread_create ( pthread_t *  newthread,
const pthread_attr_t *  attr,
void *(*)(void *)  threadroutine,
void arg 
)

◆ pthread_detach()

int pthread_detach ( pthread_t  thread)

◆ pthread_equal()

static int pthread_equal ( pthread_t  pt1,
pthread_t  pt2 
)
inlinestatic

Compare thread IDs.

See IEEE 1003.1

◆ pthread_exit()

void pthread_exit ( void retval)

◆ pthread_getname_np()

int pthread_getname_np ( pthread_t  thread,
char *  name,
size_t  len 
)

Get name of POSIX thread and store in name buffer that is of size len.

Non-portable, extension function that conforms with most other definitions of this function.

Parameters
threadPOSIX thread to obtain name information
nameDestination buffer
lenDestination buffer size
Return values
0Success
ESRCHThread does not exist
EINVALName buffer is NULL
Negativevalue if kernel function error

◆ pthread_getschedparam()

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

◆ pthread_getspecific()

void * pthread_getspecific ( pthread_key_t  key)

◆ pthread_join()

int pthread_join ( pthread_t  thread,
void **  status 
)

◆ pthread_key_create()

int pthread_key_create ( pthread_key_t *  key,
void(*)(void *)  destructor 
)

◆ pthread_key_delete()

int pthread_key_delete ( pthread_key_t  key)

◆ pthread_mutex_destroy()

int pthread_mutex_destroy ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_init()

int pthread_mutex_init ( pthread_mutex_t *  m,
const pthread_mutexattr_t *  att 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_lock()

int pthread_mutex_lock ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_timedlock()

int pthread_mutex_timedlock ( pthread_mutex_t *  m,
const struct timespec abstime 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_trylock()

int pthread_mutex_trylock ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutex_unlock()

int pthread_mutex_unlock ( pthread_mutex_t *  m)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_destroy()

static int pthread_mutexattr_destroy ( pthread_mutexattr_t *  m)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_mutexattr_getprotocol()

int pthread_mutexattr_getprotocol ( const pthread_mutexattr_t *  attr,
int *  protocol 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_gettype()

int pthread_mutexattr_gettype ( const pthread_mutexattr_t *  attr,
int *  type 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_init()

static int pthread_mutexattr_init ( pthread_mutexattr_t *  m)
inlinestatic

POSIX threading compatibility API.

See IEEE 1003.1

Note that pthread attribute structs are currently noops in Zephyr.

◆ pthread_mutexattr_setprotocol()

int pthread_mutexattr_setprotocol ( pthread_mutexattr_t *  attr,
int  protocol 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_mutexattr_settype()

int pthread_mutexattr_settype ( pthread_mutexattr_t *  attr,
int  type 
)

POSIX threading compatibility API.

See IEEE 1003.1

◆ pthread_once()

int pthread_once ( pthread_once_t *  once,
void(*)(void initFunc 
)

◆ pthread_rwlock_destroy()

int pthread_rwlock_destroy ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_init()

int pthread_rwlock_init ( pthread_rwlock_t *  rwlock,
const pthread_rwlockattr_t *  attr 
)

◆ pthread_rwlock_rdlock()

int pthread_rwlock_rdlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_timedrdlock()

int pthread_rwlock_timedrdlock ( pthread_rwlock_t *  rwlock,
const struct timespec abstime 
)

◆ pthread_rwlock_timedwrlock()

int pthread_rwlock_timedwrlock ( pthread_rwlock_t *  rwlock,
const struct timespec abstime 
)

◆ pthread_rwlock_tryrdlock()

int pthread_rwlock_tryrdlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_trywrlock()

int pthread_rwlock_trywrlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_unlock()

int pthread_rwlock_unlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlock_wrlock()

int pthread_rwlock_wrlock ( pthread_rwlock_t *  rwlock)

◆ pthread_rwlockattr_destroy()

static int pthread_rwlockattr_destroy ( pthread_rwlockattr_t *  attr)
inlinestatic

Destroy the read-write lock attributes object.

See IEEE 1003.1

◆ pthread_rwlockattr_init()

static int pthread_rwlockattr_init ( pthread_rwlockattr_t *  attr)
inlinestatic

initialize the read-write lock attributes object.

See IEEE 1003.1

◆ pthread_self()

static pthread_t pthread_self ( void  )
inlinestatic

Obtain ID of the calling thread.

The results of calling this API from threads not created with pthread_create() are undefined.

See IEEE 1003.1

◆ pthread_setcancelstate()

int pthread_setcancelstate ( int  state,
int *  oldstate 
)

◆ pthread_setname_np()

int pthread_setname_np ( pthread_t  thread,
const char *  name 
)

Set name of POSIX thread.

Non-portable, extension function that conforms with most other definitions of this function.

Parameters
threadPOSIX thread to set name
nameName string
Return values
0Success
ESRCHThread does not exist
EINVALName buffer is NULL
Negativevalue if kernel function error

◆ pthread_setschedparam()

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

◆ pthread_setspecific()

int pthread_setspecific ( pthread_key_t  key,
const void value 
)