2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2011-03-31 03:42:50 +02:00
|
|
|
* include/pthread.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2011-03-31 03:42:50 +02:00
|
|
|
#ifndef __INCLUDE_PTHREAD_H
|
|
|
|
#define __INCLUDE_PTHREAD_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-11-03 01:21:46 +01:00
|
|
|
#include <nuttx/config.h> /* Default settings */
|
|
|
|
#include <nuttx/compiler.h> /* Compiler settings, noreturn_function */
|
2009-12-15 00:32:23 +01:00
|
|
|
|
2016-11-03 01:21:46 +01:00
|
|
|
#include <sys/types.h> /* Needed for general types */
|
|
|
|
#include <stdint.h> /* C99 fixed width integer types */
|
|
|
|
#include <stdbool.h> /* C99 boolean types */
|
|
|
|
#include <unistd.h> /* For getpid */
|
|
|
|
#include <signal.h> /* Needed for sigset_t, includes this file */
|
|
|
|
#include <time.h> /* Needed for struct timespec */
|
2021-05-14 04:03:23 +02:00
|
|
|
#include <semaphore.h> /* For sem_t and SEM_PRIO_* defines */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-02-28 17:21:05 +01:00
|
|
|
#ifdef CONFIG_PTHREAD_SPINLOCKS
|
|
|
|
/* The architecture specific spinlock.h header file must provide the
|
|
|
|
* following:
|
|
|
|
*
|
|
|
|
* SP_LOCKED - A definition of the locked state value (usually 1)
|
|
|
|
* SP_UNLOCKED - A definition of the unlocked state value (usually 0)
|
|
|
|
* spinlock_t - The type of a spinlock memory object.
|
|
|
|
*
|
|
|
|
* SP_LOCKED and SP_UNLOCKED must constants of type spinlock_t.
|
|
|
|
*/
|
|
|
|
|
|
|
|
# include <arch/spinlock.h>
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2014-09-28 18:15:33 +02:00
|
|
|
* Pre-processor Definitions
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Standard POSIX switches */
|
|
|
|
|
|
|
|
#ifndef _POSIX_THREADS
|
2012-12-21 22:30:33 +01:00
|
|
|
# define _POSIX_THREADS
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif
|
2012-12-21 22:30:33 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#ifndef _POSIX_THREAD_ATTR_STACKSIZE
|
2012-12-21 22:30:33 +01:00
|
|
|
# define _POSIX_THREAD_ATTR_STACKSIZE
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif
|
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
/* Values for the process shared (pshared) attribute */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
#define PTHREAD_PROCESS_PRIVATE 0
|
|
|
|
#define PTHREAD_PROCESS_SHARED 1
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-05-31 19:13:08 +02:00
|
|
|
/* Values for the mutext type attribute:
|
|
|
|
*
|
|
|
|
* PTHREAD_MUTEX_NORMAL: This type of mutex does not detect deadlock. A thread
|
|
|
|
* attempting to relock this mutex without first unlocking it will deadlock.
|
2019-02-24 21:40:11 +01:00
|
|
|
* Attempting to unlock a mutex locked by a different thread results in
|
|
|
|
* undefined behavior. Attempting to unlock an unlocked mutex results in
|
|
|
|
* undefined behavior.
|
2008-05-31 19:13:08 +02:00
|
|
|
* PTHREAD_MUTEX_ERRORCHECK
|
2019-02-24 21:40:11 +01:00
|
|
|
* This type of mutex provides error checking. A thread attempting to relock
|
|
|
|
* this mutex without first unlocking it will return with an error. A thread
|
|
|
|
* attempting to unlock a mutex which another thread has locked will return
|
|
|
|
* with an error. A thread attempting to unlock an unlocked mutex will return
|
|
|
|
* with an error.
|
2008-05-31 19:13:08 +02:00
|
|
|
* PTHREAD_MUTEX_RECURSIVE
|
2019-02-24 21:40:11 +01:00
|
|
|
* A thread attempting to relock this mutex without first unlocking it will
|
|
|
|
* succeed in locking the mutex. The relocking deadlock which can occur with
|
|
|
|
* mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex.
|
|
|
|
* Multiple locks of this mutex require the same number of unlocks to release
|
|
|
|
* the mutex before another thread can acquire the mutex. A thread attempting
|
|
|
|
* to unlock a mutex which another thread has locked will return with an error.
|
|
|
|
* A thread attempting to unlock an unlocked mutex will return with an error.
|
2008-05-31 19:13:08 +02:00
|
|
|
* PTHREAD_MUTEX_DEFAULT
|
2019-02-24 21:40:11 +01:00
|
|
|
* An implementation is allowed to map this mutex to one of the other mutex
|
|
|
|
* types.
|
2008-05-31 19:13:08 +02:00
|
|
|
*/
|
|
|
|
|
2016-11-05 18:06:52 +01:00
|
|
|
#define PTHREAD_MUTEX_NORMAL 0
|
|
|
|
#define PTHREAD_MUTEX_ERRORCHECK 1
|
|
|
|
#define PTHREAD_MUTEX_RECURSIVE 2
|
|
|
|
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
|
2008-05-31 19:13:08 +02:00
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
/* Valid ranges for the pthread stacksize attribute */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
#define PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN
|
|
|
|
#define PTHREAD_STACK_DEFAULT CONFIG_PTHREAD_STACK_DEFAULT
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
/* Values for the pthread inheritsched attribute */
|
|
|
|
|
|
|
|
#define PTHREAD_INHERIT_SCHED 0
|
|
|
|
#define PTHREAD_EXPLICIT_SCHED 1
|
|
|
|
|
2020-08-19 17:32:48 +02:00
|
|
|
/* Detach state */
|
|
|
|
|
|
|
|
#define PTHREAD_CREATE_JOINABLE 0
|
|
|
|
#define PTHREAD_CREATE_DETACHED 1
|
|
|
|
|
2016-11-03 01:21:46 +01:00
|
|
|
/* Default priority */
|
2007-03-24 00:22:22 +01:00
|
|
|
|
|
|
|
#define PTHREAD_DEFAULT_PRIORITY 100
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-12-09 14:23:00 +01:00
|
|
|
/* Cancellation states used by pthread_setcancelstate() */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
#define PTHREAD_CANCEL_ENABLE (0)
|
|
|
|
#define PTHREAD_CANCEL_DISABLE (1)
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-12-09 14:23:00 +01:00
|
|
|
/* Cancellation types used by pthread_setcanceltype() */
|
|
|
|
|
|
|
|
#define PTHREAD_CANCEL_DEFERRED (0)
|
|
|
|
#define PTHREAD_CANCEL_ASYNCHRONOUS (1)
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Thread return value when a pthread is canceled */
|
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
#define PTHREAD_CANCELED ((FAR void*)ERROR)
|
|
|
|
|
|
|
|
/* Used to initialize a pthread_once_t */
|
|
|
|
|
2009-12-15 00:32:23 +01:00
|
|
|
#define PTHREAD_ONCE_INIT (false)
|
2007-03-24 00:22:22 +01:00
|
|
|
|
2019-10-17 19:00:14 +02:00
|
|
|
/* This is returned by pthread_barrier_wait. It must not match any errno
|
|
|
|
* in errno.h
|
|
|
|
*/
|
2007-03-24 00:22:22 +01:00
|
|
|
|
|
|
|
#define PTHREAD_BARRIER_SERIAL_THREAD 0x1000
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-11-03 01:21:46 +01:00
|
|
|
/* Values for protocol mutex attribute */
|
2016-11-02 16:05:18 +01:00
|
|
|
|
|
|
|
#define PTHREAD_PRIO_NONE SEM_PRIO_NONE
|
|
|
|
#define PTHREAD_PRIO_INHERIT SEM_PRIO_INHERIT
|
|
|
|
#define PTHREAD_PRIO_PROTECT SEM_PRIO_PROTECT
|
|
|
|
|
2017-03-27 02:37:24 +02:00
|
|
|
/* Values for robust argument of pthread_mutexattr_get/setrobust
|
|
|
|
*
|
|
|
|
* PTHREAD_MUTEX_STALLED - No special actions are taken if the owner of the
|
|
|
|
* mutex is terminated while holding the mutex lock. This can lead to
|
|
|
|
* deadlocks if no other thread can unlock the mutex. This is the standard
|
|
|
|
* default value (NuttX permits you to override that default behavior
|
|
|
|
* with a configuration option).
|
|
|
|
*
|
|
|
|
* PTHREAD_MUTEX_ROBUST - If the process containing the owning thread of a
|
|
|
|
* robust mutex terminates while holding the mutex lock, the next thread
|
|
|
|
* that acquires the mutex will be notified about the termination by the
|
|
|
|
* return value EOWNERDEAD from the locking function. If the owning thread
|
|
|
|
* of a robust mutex terminates while holding the mutex lock, the next
|
|
|
|
* thread that attempts to acquire the mutex may be notified about the
|
|
|
|
* termination by the return value EOWNERDEAD. The notified thread can
|
|
|
|
* then attempt to make the state protected by the mutex consistent again,
|
|
|
|
* and if successful can mark the mutex state as consistent by calling
|
|
|
|
* pthread_mutex_consistent(). After a subsequent successful call to
|
|
|
|
* pthread_mutex_unlock(), the mutex lock will be released and can be used
|
|
|
|
* normally by other threads. If the mutex is unlocked without a call to
|
|
|
|
* pthread_mutex_consistent(), it will be in a permanently unusable state
|
|
|
|
* and all attempts to lock the mutex will fail with the error
|
|
|
|
* ENOTRECOVERABLE. The only permissible operation on such a mutex is
|
|
|
|
* pthread_mutex_destroy().
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PTHREAD_MUTEX_STALLED 0
|
|
|
|
#define PTHREAD_MUTEX_ROBUST 1
|
|
|
|
|
2017-03-26 20:46:57 +02:00
|
|
|
/* Values for struct pthread_mutex_s flags. These are non-standard and
|
|
|
|
* intended only for internal use within the OS.
|
|
|
|
*/
|
|
|
|
|
2017-03-27 02:37:24 +02:00
|
|
|
#define _PTHREAD_MFLAGS_ROBUST (1 << 0) /* Robust (NORMAL) mutex */
|
|
|
|
#define _PTHREAD_MFLAGS_INCONSISTENT (1 << 1) /* Mutex is in an inconsistent state */
|
2017-03-27 16:50:45 +02:00
|
|
|
#define _PTHREAD_MFLAGS_NRECOVERABLE (1 << 2) /* Inconsistent mutex has been unlocked */
|
2017-03-26 20:46:57 +02:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2015-08-03 19:01:41 +02:00
|
|
|
* Public Type Definitions
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2012-12-21 22:30:33 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-02-18 00:21:28 +01:00
|
|
|
#endif
|
|
|
|
|
2011-03-31 03:42:50 +02:00
|
|
|
/* pthread-specific types */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_KEY_T_DEFINED
|
2015-12-30 20:20:31 +01:00
|
|
|
typedef int pthread_key_t;
|
|
|
|
#define __PTHREAD_KEY_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_ADDR_T_DEFINED
|
2015-12-30 20:20:31 +01:00
|
|
|
typedef FAR void *pthread_addr_t;
|
|
|
|
#define __PTHREAD_ADDR_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-08-27 01:28:21 +02:00
|
|
|
typedef CODE pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
|
2013-03-16 18:37:40 +01:00
|
|
|
typedef pthread_startroutine_t pthread_func_t;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-06-29 16:26:29 +02:00
|
|
|
typedef void (*pthread_trampoline_t)(pthread_startroutine_t, pthread_addr_t);
|
|
|
|
|
2009-03-09 00:33:41 +01:00
|
|
|
struct pthread_attr_s
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2015-07-23 21:16:32 +02:00
|
|
|
uint8_t priority; /* Priority of the pthread */
|
|
|
|
uint8_t policy; /* Pthread scheduler policy */
|
2015-07-23 21:26:41 +02:00
|
|
|
uint8_t inheritsched; /* Inherit parent priority/policy? */
|
2020-08-19 17:32:48 +02:00
|
|
|
uint8_t detachstate; /* Initialize to the detach state */
|
2015-07-23 21:16:32 +02:00
|
|
|
#ifdef CONFIG_SCHED_SPORADIC
|
2015-07-23 21:26:41 +02:00
|
|
|
uint8_t low_priority; /* Low scheduling priority */
|
2015-07-23 21:16:32 +02:00
|
|
|
uint8_t max_repl; /* Maximum pending replenishments */
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 00:33:35 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
cpu_set_t affinity; /* Set of permitted CPUs for the thread */
|
|
|
|
#endif
|
|
|
|
|
2018-08-23 17:48:53 +02:00
|
|
|
FAR void *stackaddr; /* Address of memory to be used as stack */
|
2015-07-23 21:16:32 +02:00
|
|
|
size_t stacksize; /* Size of the stack allocated for the pthread */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_SPORADIC
|
|
|
|
struct timespec repl_period; /* Replenishment period */
|
|
|
|
struct timespec budget; /* Initial budget */
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_ATTR_T_DEFINED
|
2009-03-09 00:33:41 +01:00
|
|
|
typedef struct pthread_attr_s pthread_attr_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_ATTR_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_T_DEFINED
|
2007-02-20 23:39:56 +01:00
|
|
|
typedef pid_t pthread_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-08-12 11:45:35 +02:00
|
|
|
struct pthread_condattr_s
|
|
|
|
{
|
|
|
|
clockid_t clockid;
|
|
|
|
};
|
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_CONDATTR_T_DEFINED
|
2020-08-12 11:45:35 +02:00
|
|
|
typedef struct pthread_condattr_s pthread_condattr_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_CONDATTR_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
struct pthread_cond_s
|
|
|
|
{
|
|
|
|
sem_t sem;
|
2020-08-12 11:45:35 +02:00
|
|
|
clockid_t clockid;
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_COND_T_DEFINED
|
2007-02-18 00:21:28 +01:00
|
|
|
typedef struct pthread_cond_s pthread_cond_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_COND_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2020-08-12 11:45:35 +02:00
|
|
|
#define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME }
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
struct pthread_mutexattr_s
|
|
|
|
{
|
2017-03-27 02:37:24 +02:00
|
|
|
uint8_t pshared : 1; /* PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED */
|
2016-11-02 16:05:18 +01:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2017-03-27 02:37:24 +02:00
|
|
|
uint8_t proto : 2; /* See PTHREAD_PRIO_* definitions */
|
2016-11-02 16:05:18 +01:00
|
|
|
#endif
|
2017-03-27 17:08:14 +02:00
|
|
|
#ifdef CONFIG_PTHREAD_MUTEX_TYPES
|
2017-03-27 02:37:24 +02:00
|
|
|
uint8_t type : 2; /* Type of the mutex. See PTHREAD_MUTEX_* definitions */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PTHREAD_MUTEX_BOTH
|
|
|
|
uint8_t robust : 1; /* PTHREAD_MUTEX_STALLED or PTHREAD_MUTEX_ROBUST */
|
2008-05-31 19:13:08 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_MUTEXATTR_T_DEFINED
|
2007-02-18 00:21:28 +01:00
|
|
|
typedef struct pthread_mutexattr_s pthread_mutexattr_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_MUTEXATTR_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
struct pthread_mutex_s
|
|
|
|
{
|
2017-03-27 01:37:28 +02:00
|
|
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
2017-03-26 20:46:57 +02:00
|
|
|
/* Supports a singly linked list */
|
|
|
|
|
|
|
|
FAR struct pthread_mutex_s *flink;
|
2017-03-27 01:37:28 +02:00
|
|
|
#endif
|
2017-03-26 20:46:57 +02:00
|
|
|
|
|
|
|
/* Payload */
|
|
|
|
|
2016-11-02 16:05:18 +01:00
|
|
|
sem_t sem; /* Semaphore underlying the implementation of the mutex */
|
2017-03-26 20:46:57 +02:00
|
|
|
pid_t pid; /* ID of the holder of the mutex */
|
2017-03-27 01:37:28 +02:00
|
|
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
2017-03-26 22:04:07 +02:00
|
|
|
uint8_t flags; /* See _PTHREAD_MFLAGS_* */
|
2017-03-27 01:37:28 +02:00
|
|
|
#endif
|
2017-03-27 17:08:14 +02:00
|
|
|
#ifdef CONFIG_PTHREAD_MUTEX_TYPES
|
2016-11-02 16:05:18 +01:00
|
|
|
uint8_t type; /* Type of the mutex. See PTHREAD_MUTEX_* definitions */
|
2017-03-26 20:46:57 +02:00
|
|
|
int16_t nlocks; /* The number of recursive locks held */
|
2008-05-31 19:13:08 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_MUTEX_T_DEFINED
|
2007-02-18 00:21:28 +01:00
|
|
|
typedef struct pthread_mutex_s pthread_mutex_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_MUTEX_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2008-05-31 19:13:08 +02:00
|
|
|
|
2017-03-28 17:07:32 +02:00
|
|
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
|
|
|
# ifdef CONFIG_PTHREAD_MUTEX_DEFAULT_UNSAFE
|
|
|
|
# define __PTHREAD_MUTEX_DEFAULT_FLAGS 0
|
|
|
|
# else
|
|
|
|
# define __PTHREAD_MUTEX_DEFAULT_FLAGS _PTHREAD_MFLAGS_ROBUST
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_PTHREAD_MUTEX_TYPES) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
|
|
|
|
# define PTHREAD_MUTEX_INITIALIZER {NULL, SEM_INITIALIZER(1), -1, \
|
|
|
|
__PTHREAD_MUTEX_DEFAULT_FLAGS, \
|
|
|
|
PTHREAD_MUTEX_DEFAULT, 0}
|
2020-06-10 08:08:32 +02:00
|
|
|
# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
|
|
|
|
{NULL, SEM_INITIALIZER(1), -1, \
|
|
|
|
__PTHREAD_MUTEX_DEFAULT_FLAGS, \
|
|
|
|
PTHREAD_MUTEX_RECURSIVE, 0}
|
2017-03-28 17:07:32 +02:00
|
|
|
#elif defined(CONFIG_PTHREAD_MUTEX_TYPES)
|
|
|
|
# define PTHREAD_MUTEX_INITIALIZER {SEM_INITIALIZER(1), -1, \
|
|
|
|
PTHREAD_MUTEX_DEFAULT, 0}
|
2020-06-10 08:08:32 +02:00
|
|
|
# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
|
|
|
|
{SEM_INITIALIZER(1), -1, \
|
|
|
|
PTHREAD_MUTEX_RECURSIVE, 0}
|
2017-03-28 17:07:32 +02:00
|
|
|
#elif !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
|
|
|
|
# define PTHREAD_MUTEX_INITIALIZER {NULL, SEM_INITIALIZER(1), -1,\
|
|
|
|
__PTHREAD_MUTEX_DEFAULT_FLAGS}
|
2008-05-31 19:13:08 +02:00
|
|
|
#else
|
2017-03-28 17:07:32 +02:00
|
|
|
# define PTHREAD_MUTEX_INITIALIZER {SEM_INITIALIZER(1), -1}
|
2008-05-31 19:13:08 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
struct pthread_barrierattr_s
|
|
|
|
{
|
|
|
|
int pshared;
|
|
|
|
};
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_BARRIERATTR_T_DEFINED
|
2007-03-24 00:22:22 +01:00
|
|
|
typedef struct pthread_barrierattr_s pthread_barrierattr_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_BARRIERATTR_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-03-24 00:22:22 +01:00
|
|
|
|
|
|
|
struct pthread_barrier_s
|
|
|
|
{
|
|
|
|
sem_t sem;
|
|
|
|
unsigned int count;
|
|
|
|
};
|
2015-12-30 20:20:31 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_BARRIER_T_DEFINED
|
2007-03-24 00:22:22 +01:00
|
|
|
typedef struct pthread_barrier_s pthread_barrier_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_BARRIER_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-03-24 00:22:22 +01:00
|
|
|
|
2019-01-27 18:34:39 +01:00
|
|
|
#ifndef __PTHREAD_ONCE_T_DEFINED
|
2009-12-15 00:32:23 +01:00
|
|
|
typedef bool pthread_once_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
#define __PTHREAD_ONCE_T_DEFINED 1
|
2019-01-27 18:34:39 +01:00
|
|
|
#endif
|
2007-03-24 00:22:22 +01:00
|
|
|
|
2017-04-07 15:03:00 +02:00
|
|
|
struct pthread_rwlock_s
|
|
|
|
{
|
2019-10-17 19:00:14 +02:00
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_cond_t cv;
|
|
|
|
unsigned int num_readers;
|
|
|
|
unsigned int num_writers;
|
|
|
|
bool write_in_progress;
|
2017-04-07 15:03:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct pthread_rwlock_s pthread_rwlock_t;
|
|
|
|
|
|
|
|
typedef int pthread_rwlockattr_t;
|
|
|
|
|
|
|
|
#define PTHREAD_RWLOCK_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, \
|
|
|
|
PTHREAD_COND_INITIALIZER, \
|
2017-04-08 20:34:08 +02:00
|
|
|
0, 0, false}
|
2017-04-07 15:03:00 +02:00
|
|
|
|
2019-02-28 17:21:05 +01:00
|
|
|
#ifdef CONFIG_PTHREAD_SPINLOCKS
|
|
|
|
/* This (non-standard) structure represents a pthread spinlock */
|
|
|
|
|
|
|
|
struct pthread_spinlock_s
|
|
|
|
{
|
|
|
|
volatile spinlock_t sp_lock; /* Indicates if the spinlock is locked or
|
2019-10-17 19:00:14 +02:00
|
|
|
* not. See the values SP_LOCKED and
|
2019-02-28 17:21:05 +01:00
|
|
|
* SP_UNLOCKED. */
|
|
|
|
pthread_t sp_holder; /* ID of the thread that holds the spinlock */
|
|
|
|
};
|
2020-09-24 10:58:12 +02:00
|
|
|
#ifndef __PTHREAD_SPINLOCK_T_DEFINED
|
2019-02-28 17:21:05 +01:00
|
|
|
/* It is referenced via this standard type */
|
|
|
|
|
|
|
|
typedef FAR struct pthread_spinlock_s pthread_spinlock_t;
|
|
|
|
#define __PTHREAD_SPINLOCK_T_DEFINED 1
|
|
|
|
#endif
|
2019-10-17 19:00:14 +02:00
|
|
|
#endif /* CONFIG_PTHREAD_SPINLOCKS */
|
2019-02-28 17:21:05 +01:00
|
|
|
|
2016-12-08 16:27:13 +01:00
|
|
|
#ifdef CONFIG_PTHREAD_CLEANUP
|
|
|
|
/* This type describes the pthread cleanup callback (non-standard) */
|
|
|
|
|
|
|
|
typedef CODE void (*pthread_cleanup_t)(FAR void *arg);
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 01:13:06 +01:00
|
|
|
/* Forward references */
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
struct sched_param; /* Defined in sched.h */
|
|
|
|
|
|
|
|
/********************************************************************************
|
2015-08-03 19:01:41 +02:00
|
|
|
* Public Function Prototypes
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-03-24 00:22:22 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Initializes a thread attributes object (attr) with default values for all of
|
|
|
|
* the individual attributes used by a given implementation.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_attr_init(FAR pthread_attr_t *attr);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* An attributes object can be deleted when it is no longer needed. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-05-06 11:24:42 +02:00
|
|
|
int pthread_attr_destroy(FAR pthread_attr_t *attr);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Set or obtain the default scheduling algorithm */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_attr_setschedpolicy(FAR pthread_attr_t *attr, int policy);
|
2020-05-06 11:24:42 +02:00
|
|
|
int pthread_attr_getschedpolicy(FAR const pthread_attr_t *attr, FAR int *policy);
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_attr_setschedparam(FAR pthread_attr_t *attr,
|
|
|
|
FAR const struct sched_param *param);
|
2014-09-08 14:21:48 +02:00
|
|
|
int pthread_attr_getschedparam(FAR const pthread_attr_t *attr,
|
2012-12-21 22:30:33 +01:00
|
|
|
FAR struct sched_param *param);
|
|
|
|
int pthread_attr_setinheritsched(FAR pthread_attr_t *attr,
|
|
|
|
int inheritsched);
|
|
|
|
int pthread_attr_getinheritsched(FAR const pthread_attr_t *attr,
|
|
|
|
FAR int *inheritsched);
|
2020-08-19 17:32:48 +02:00
|
|
|
int pthread_attr_getdetachstate(FAR const pthread_attr_t *attr,
|
|
|
|
FAR int *detachstate);
|
|
|
|
int pthread_attr_setdetachstate(FAR pthread_attr_t *attr,
|
|
|
|
int detachstate);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-19 22:57:07 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Set or obtain thread affinity attributes */
|
|
|
|
|
|
|
|
int pthread_attr_setaffinity_np(FAR pthread_attr_t *attr,
|
|
|
|
size_t cpusetsize,
|
|
|
|
FAR const cpu_set_t *cpuset);
|
|
|
|
int pthread_attr_getaffinity_np(FAR const pthread_attr_t *attr,
|
|
|
|
size_t cpusetsize, cpu_set_t *cpuset);
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Set or obtain the default stack size */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-04-04 18:33:57 +02:00
|
|
|
int pthread_attr_setstacksize(FAR pthread_attr_t *attr, size_t stacksize);
|
2020-05-06 11:24:42 +02:00
|
|
|
int pthread_attr_getstacksize(FAR const pthread_attr_t *attr,
|
|
|
|
FAR size_t *stackaddr);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-04-04 18:30:46 +02:00
|
|
|
/* Set or obtain stack address and size attributes */
|
2018-08-23 17:48:53 +02:00
|
|
|
|
|
|
|
int pthread_attr_setstack(FAR pthread_attr_t *attr,
|
|
|
|
FAR void *stackaddr, long stacksize);
|
|
|
|
int pthread_attr_getstack(FAR pthread_attr_t *attr,
|
|
|
|
FAR void **stackaddr, FAR long *stacksize);
|
|
|
|
|
2022-02-05 10:06:51 +01:00
|
|
|
/* Set or get the name of a thread */
|
|
|
|
|
|
|
|
int pthread_setname_np(pthread_t thread, FAR const char *name);
|
|
|
|
int pthread_getname_np(pthread_t thread, FAR char *name, size_t len);
|
|
|
|
|
2019-04-04 18:30:46 +02:00
|
|
|
/* Get run-time stack address and size */
|
|
|
|
|
2019-06-03 21:06:58 +02:00
|
|
|
FAR void *pthread_get_stackaddr_np(pthread_t thread);
|
|
|
|
ssize_t pthread_get_stacksize_np(pthread_t thread);
|
2019-04-04 18:30:46 +02:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* To create a thread object and runnable thread, a routine must be specified
|
|
|
|
* as the new thread's start routine. An argument may be passed to this
|
|
|
|
* routine, as an untyped address; an untyped address may also be returned as
|
|
|
|
* the routine's value. An attributes object may be used to specify details
|
|
|
|
* about the kind of thread being created.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-09-08 14:21:48 +02:00
|
|
|
int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr,
|
2012-12-21 22:30:33 +01:00
|
|
|
pthread_startroutine_t startroutine, pthread_addr_t arg);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread object may be "detached" to specify that the return value and
|
|
|
|
* completion status will not be requested.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_detach(pthread_t thread);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread may terminate it's own execution or the execution of another
|
|
|
|
* thread.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
void pthread_exit(pthread_addr_t value) noreturn_function;
|
|
|
|
int pthread_cancel(pthread_t thread);
|
|
|
|
int pthread_setcancelstate(int state, FAR int *oldstate);
|
2016-12-09 14:23:00 +01:00
|
|
|
int pthread_setcanceltype(int type, FAR int *oldtype);
|
2012-12-21 22:30:33 +01:00
|
|
|
void pthread_testcancel(void);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* A thread may set up cleanup functions to execute when the thread exits or
|
2016-12-08 16:27:13 +01:00
|
|
|
* is canceled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PTHREAD_CLEANUP
|
|
|
|
void pthread_cleanup_pop(int execute);
|
|
|
|
void pthread_cleanup_push(pthread_cleanup_t routine, FAR void *arg);
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread can await termination of another thread and retrieve the return
|
|
|
|
* value of the thread.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_join(pthread_t thread, FAR pthread_addr_t *value);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread may tell the scheduler that its processor can be made available. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
void pthread_yield(void);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread may obtain a copy of its own thread handle. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-11-15 07:37:20 +01:00
|
|
|
#define pthread_self() ((pthread_t)gettid())
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Compare two thread IDs. */
|
2007-03-16 23:44:04 +01:00
|
|
|
|
2015-06-16 16:27:38 +02:00
|
|
|
#define pthread_equal(t1,t2) ((t1) == (t2))
|
2007-03-16 23:44:04 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Thread scheduling parameters */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_getschedparam(pthread_t thread, FAR int *policy,
|
|
|
|
FAR struct sched_param *param);
|
|
|
|
int pthread_setschedparam(pthread_t thread, int policy,
|
|
|
|
FAR const struct sched_param *param);
|
|
|
|
int pthread_setschedprio(pthread_t thread, int prio);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-02-20 21:57:05 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-02-19 22:57:07 +01:00
|
|
|
/* Thread affinity */
|
|
|
|
|
|
|
|
int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize,
|
|
|
|
FAR const cpu_set_t *cpuset);
|
|
|
|
int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize,
|
|
|
|
FAR cpu_set_t *cpuset);
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Thread-specific Data Interfaces */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_key_create(FAR pthread_key_t *key,
|
2019-02-24 21:40:11 +01:00
|
|
|
CODE void (*destructor)(FAR void *));
|
2014-09-08 14:21:48 +02:00
|
|
|
int pthread_setspecific(pthread_key_t key, FAR const void *value);
|
2012-12-21 22:30:33 +01:00
|
|
|
FAR void *pthread_getspecific(pthread_key_t key);
|
|
|
|
int pthread_key_delete(pthread_key_t key);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Create, operate on, and destroy mutex attributes. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_mutexattr_init(FAR pthread_mutexattr_t *attr);
|
|
|
|
int pthread_mutexattr_destroy(FAR pthread_mutexattr_t *attr);
|
2014-09-08 14:21:48 +02:00
|
|
|
int pthread_mutexattr_getpshared(FAR const pthread_mutexattr_t *attr,
|
2012-12-21 22:30:33 +01:00
|
|
|
FAR int *pshared);
|
|
|
|
int pthread_mutexattr_setpshared(FAR pthread_mutexattr_t *attr,
|
|
|
|
int pshared);
|
2020-05-06 11:24:42 +02:00
|
|
|
int pthread_mutexattr_gettype(FAR const pthread_mutexattr_t *attr,
|
|
|
|
FAR int *type);
|
|
|
|
int pthread_mutexattr_settype(FAR pthread_mutexattr_t *attr, int type);
|
2016-11-05 18:06:52 +01:00
|
|
|
int pthread_mutexattr_getprotocol(FAR const pthread_mutexattr_t *attr,
|
|
|
|
FAR int *protocol);
|
|
|
|
int pthread_mutexattr_setprotocol(FAR pthread_mutexattr_t *attr,
|
|
|
|
int protocol);
|
2017-03-27 02:37:24 +02:00
|
|
|
int pthread_mutexattr_getrobust(FAR const pthread_mutexattr_t *attr,
|
|
|
|
FAR int *robust);
|
|
|
|
int pthread_mutexattr_setrobust(FAR pthread_mutexattr_t *attr,
|
|
|
|
int robust);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* The following routines create, delete, lock and unlock mutexes. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_mutex_init(FAR pthread_mutex_t *mutex,
|
2014-09-08 14:21:48 +02:00
|
|
|
FAR const pthread_mutexattr_t *attr);
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_mutex_destroy(FAR pthread_mutex_t *mutex);
|
|
|
|
int pthread_mutex_lock(FAR pthread_mutex_t *mutex);
|
2019-02-24 21:04:24 +01:00
|
|
|
int pthread_mutex_timedlock(FAR pthread_mutex_t *mutex,
|
2019-02-24 21:40:11 +01:00
|
|
|
FAR const struct timespec *abs_timeout);
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_mutex_trylock(FAR pthread_mutex_t *mutex);
|
|
|
|
int pthread_mutex_unlock(FAR pthread_mutex_t *mutex);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-03-27 01:37:28 +02:00
|
|
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
2017-03-26 18:35:23 +02:00
|
|
|
/* Make sure that the pthread mutex is in a consistent state */
|
|
|
|
|
|
|
|
int pthread_mutex_consistent(FAR pthread_mutex_t *mutex);
|
2017-03-27 01:37:28 +02:00
|
|
|
#endif
|
2017-03-26 18:35:23 +02:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Operations on condition variables */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_condattr_init(FAR pthread_condattr_t *attr);
|
|
|
|
int pthread_condattr_destroy(FAR pthread_condattr_t *attr);
|
2020-08-12 11:45:35 +02:00
|
|
|
int pthread_condattr_getclock(FAR const pthread_condattr_t *attr,
|
|
|
|
clockid_t *clock_id);
|
|
|
|
int pthread_condattr_setclock(FAR pthread_condattr_t *attr,
|
|
|
|
clockid_t clock_id);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread can create and delete condition variables. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2019-02-24 21:40:11 +01:00
|
|
|
int pthread_cond_init(FAR pthread_cond_t *cond,
|
|
|
|
FAR const pthread_condattr_t *attr);
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_cond_destroy(FAR pthread_cond_t *cond);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread can signal to and broadcast on a condition variable. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_cond_broadcast(FAR pthread_cond_t *cond);
|
|
|
|
int pthread_cond_signal(FAR pthread_cond_t *cond);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread can wait for a condition variable to be signalled or broadcast. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* A thread can perform a timed wait on a condition variable. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_cond_timedwait(FAR pthread_cond_t *cond,
|
|
|
|
FAR pthread_mutex_t *mutex,
|
|
|
|
FAR const struct timespec *abstime);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-07-27 07:46:03 +02:00
|
|
|
int pthread_cond_clockwait(FAR pthread_cond_t *cond,
|
|
|
|
FAR pthread_mutex_t *mutex,
|
|
|
|
clockid_t clockid,
|
|
|
|
FAR const struct timespec *abstime);
|
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
/* Barrier attributes */
|
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr);
|
|
|
|
int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr);
|
|
|
|
int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr,
|
|
|
|
FAR int *pshared);
|
|
|
|
int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr,
|
|
|
|
int pshared);
|
2007-03-24 00:22:22 +01:00
|
|
|
|
|
|
|
/* Barriers */
|
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_barrier_destroy(FAR pthread_barrier_t *barrier);
|
|
|
|
int pthread_barrier_init(FAR pthread_barrier_t *barrier,
|
2017-04-07 15:03:00 +02:00
|
|
|
FAR const pthread_barrierattr_t *attr,
|
|
|
|
unsigned int count);
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_barrier_wait(FAR pthread_barrier_t *barrier);
|
2007-03-24 00:22:22 +01:00
|
|
|
|
|
|
|
/* Pthread initialization */
|
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_once(FAR pthread_once_t *once_control,
|
2019-10-17 19:00:14 +02:00
|
|
|
CODE void (*init_routine)(void));
|
2007-03-24 00:22:22 +01:00
|
|
|
|
2017-04-07 15:03:00 +02:00
|
|
|
/* Pthread rwlock */
|
|
|
|
|
|
|
|
int pthread_rwlock_destroy(FAR pthread_rwlock_t *rw_lock);
|
|
|
|
int pthread_rwlock_init(FAR pthread_rwlock_t *rw_lock,
|
|
|
|
FAR const pthread_rwlockattr_t *attr);
|
|
|
|
int pthread_rwlock_rdlock(pthread_rwlock_t *lock);
|
|
|
|
int pthread_rwlock_timedrdlock(FAR pthread_rwlock_t *lock,
|
|
|
|
FAR const struct timespec *abstime);
|
2020-07-27 07:46:03 +02:00
|
|
|
int pthread_rwlock_clockrdlock(FAR pthread_rwlock_t *lock,
|
|
|
|
clockid_t clockid,
|
|
|
|
FAR const struct timespec *abstime);
|
2017-04-07 15:03:00 +02:00
|
|
|
int pthread_rwlock_tryrdlock(FAR pthread_rwlock_t *lock);
|
|
|
|
int pthread_rwlock_wrlock(FAR pthread_rwlock_t *lock);
|
|
|
|
int pthread_rwlock_timedwrlock(FAR pthread_rwlock_t *lock,
|
|
|
|
FAR const struct timespec *abstime);
|
2020-07-27 07:46:03 +02:00
|
|
|
int pthread_rwlock_clockwrlock(FAR pthread_rwlock_t *lock,
|
|
|
|
clockid_t clockid,
|
|
|
|
FAR const struct timespec *abstime);
|
2017-04-07 15:03:00 +02:00
|
|
|
int pthread_rwlock_trywrlock(FAR pthread_rwlock_t *lock);
|
|
|
|
int pthread_rwlock_unlock(FAR pthread_rwlock_t *lock);
|
|
|
|
|
2007-03-24 00:22:22 +01:00
|
|
|
/* Pthread signal management APIs */
|
|
|
|
|
2012-12-21 22:30:33 +01:00
|
|
|
int pthread_kill(pthread_t thread, int sig);
|
|
|
|
int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
|
2007-03-24 00:22:22 +01:00
|
|
|
|
2019-02-28 17:21:05 +01:00
|
|
|
#ifdef CONFIG_PTHREAD_SPINLOCKS
|
|
|
|
/* Pthread spinlocks */
|
|
|
|
|
|
|
|
int pthread_spin_init(FAR pthread_spinlock_t *lock, int pshared);
|
|
|
|
int pthread_spin_destroy(FAR pthread_spinlock_t *lock);
|
|
|
|
int pthread_spin_lock(FAR pthread_spinlock_t *lock);
|
|
|
|
int pthread_spin_trylock(FAR pthread_spinlock_t *lock);
|
|
|
|
int pthread_spin_unlock(FAR pthread_spinlock_t *lock);
|
|
|
|
#endif
|
|
|
|
|
2021-11-22 07:00:24 +01:00
|
|
|
int pthread_atfork(CODE void (*prepare)(void),
|
|
|
|
CODE void (*parent)(void),
|
|
|
|
CODE void (*child)(void));
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-30 22:01:14 +01:00
|
|
|
/********************************************************************************
|
|
|
|
* Minimal Type Definitions
|
|
|
|
********************************************************************************/
|
|
|
|
|
2015-12-30 20:20:31 +01:00
|
|
|
#else /* __INCLUDE_PTHREAD_H */
|
|
|
|
|
2020-05-06 11:24:42 +02:00
|
|
|
/********************************************************************************
|
|
|
|
* Included Files
|
|
|
|
********************************************************************************/
|
|
|
|
|
2015-12-30 20:20:31 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-05-06 11:24:42 +02:00
|
|
|
/********************************************************************************
|
|
|
|
* Public Type Definitions
|
|
|
|
********************************************************************************/
|
|
|
|
|
2015-12-31 16:05:35 +01:00
|
|
|
/* Avoid circular dependencies by assuring that simple type definitions are
|
|
|
|
* available in any inclusion ordering.
|
2015-12-30 20:20:31 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_KEY_T_DEFINED
|
|
|
|
typedef int pthread_key_t;
|
|
|
|
# define __PTHREAD_KEY_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_ADDR_T_DEFINED
|
|
|
|
typedef FAR void *pthread_addr_t;
|
|
|
|
# define __PTHREAD_ADDR_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_ATTR_T_DEFINED
|
|
|
|
struct pthread_attr_s;
|
|
|
|
typedef struct pthread_attr_s pthread_attr_t;
|
|
|
|
# define __PTHREAD_ATTR_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_T_DEFINED
|
|
|
|
typedef pid_t pthread_t;
|
|
|
|
# define __PTHREAD_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_CONDATTR_T_DEFINED
|
2020-08-12 11:45:35 +02:00
|
|
|
typedef struct pthread_condattr_s pthread_condattr_t;
|
2015-12-30 20:20:31 +01:00
|
|
|
# define __PTHREAD_CONDATTR_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_COND_T_DEFINED
|
|
|
|
struct pthread_cond_s;
|
|
|
|
typedef struct pthread_cond_s pthread_cond_t;
|
|
|
|
# define __PTHREAD_COND_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_MUTEXATTR_T_DEFINED
|
|
|
|
struct pthread_mutexattr_s;
|
|
|
|
typedef struct pthread_mutexattr_s pthread_mutexattr_t;
|
|
|
|
# define __PTHREAD_MUTEXATTR_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_MUTEX_T_DEFINED
|
|
|
|
struct pthread_mutex_s;
|
|
|
|
typedef struct pthread_mutex_s pthread_mutex_t;
|
|
|
|
# define __PTHREAD_MUTEX_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_BARRIERATTR_T_DEFINED
|
|
|
|
struct pthread_barrierattr_s;
|
|
|
|
typedef struct pthread_barrierattr_s pthread_barrierattr_t;
|
|
|
|
# define __PTHREAD_BARRIERATTR_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __PTHREAD_BARRIER_T_DEFINED
|
|
|
|
struct pthread_barrier_s;
|
|
|
|
typedef struct pthread_barrier_s pthread_barrier_t;
|
|
|
|
# define __PTHREAD_BARRIER_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
2019-02-28 17:21:05 +01:00
|
|
|
#ifdef CONFIG_PTHREAD_SPINLOCKS
|
|
|
|
#ifndef __PTHREAD_SPINLOCK_T_DEFINED
|
|
|
|
struct pthread_spinlock_s;
|
|
|
|
typedef FAR struct pthread_spinlock_s pthread_spinlock_t;
|
|
|
|
#define __PTHREAD_SPINLOCK_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_PTHREAD_SPINLOCKS */
|
|
|
|
|
2015-12-30 20:20:31 +01:00
|
|
|
#ifndef __PTHREAD_ONCE_T_DEFINED
|
|
|
|
typedef bool pthread_once_t;
|
|
|
|
# define __PTHREAD_ONCE_T_DEFINED 1
|
|
|
|
#endif
|
|
|
|
|
2011-03-31 03:42:50 +02:00
|
|
|
#endif /* __INCLUDE_PTHREAD_H */
|