![]() |
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Minimal POSIX-threads-style interface for SuperTinyKernel RTOS. More...
Classes | |
| struct | pthread_attr_t |
| Thread creation attributes. More... | |
| struct | pthread_mutexattr_t |
| Mutex attributes. More... | |
| struct | pthread_mutex_t |
| A pthread mutex. More... | |
| struct | pthread_condattr_t |
| Condition variable attributes (currently no settable properties). More... | |
| struct | pthread_cond_t |
| A pthread condition variable. More... | |
| struct | pthread_rwlockattr_t |
| Read-write lock attributes (currently no settable properties). More... | |
| struct | pthread_rwlock_t |
| A pthread read-write lock. More... | |
| struct | pthread_spinlock_t |
| A pthread spinlock. More... | |
| struct | pthread_barrierattr_t |
| Barrier attributes (currently no settable properties). More... | |
| struct | pthread_barrier_t |
| A pthread barrier. More... | |
| struct | pthread_once_t |
| A pthread_once() control object. More... | |
Macros | |
| #define | STK_C_PTHREAD_MAX_THREADS (8U) |
| Maximum number of concurrently-alive pthread_t's (default: 8). | |
| #define | STK_C_PTHREAD_DEFAULT_STACK_WORDS (1024U) |
| Default per-thread stack size in stk_word_t units, used when pthread_attr_t does not specify a stack size or an external stack (default: 1024 words). | |
| #define | STK_C_PTHREAD_REAPER_STACK_WORDS (256U) |
| Stack size (in stk_word_t units) for the internal reaper task that reclaims detached-thread resources (default: 256 words). | |
| #define | STK_C_PTHREAD_KEYS_MAX (8U) |
| Maximum number of concurrently-alive pthread_key_t's (default: 8). | |
| #define | PTHREAD_CREATE_JOINABLE (0) |
| #define | PTHREAD_CREATE_DETACHED (1) |
| #define | PTHREAD_MUTEX_NORMAL (0) |
| #define | PTHREAD_MUTEX_DEFAULT (PTHREAD_MUTEX_NORMAL) |
| #define | PTHREAD_MUTEX_ERRORCHECK (1) |
| #define | PTHREAD_MUTEX_RECURSIVE (2) |
| #define | PTHREAD_MUTEX_INITIALIZER {0} |
| #define | PTHREAD_COND_INITIALIZER {0} |
| #define | PTHREAD_RWLOCK_INITIALIZER {0} |
| #define | PTHREAD_PROCESS_PRIVATE (0) |
| #define | PTHREAD_PROCESS_SHARED (1) |
| #define | PTHREAD_BARRIER_SERIAL_THREAD (-1) |
| Returned by pthread_barrier_wait() to exactly one arbitrary caller per round; all others receive 0. See "pthread_barrier_wait() note" in the file-level docs. | |
| #define | PTHREAD_ONCE_INIT {0} |
| #define | PTHREAD_KEYS_MAX (STK_C_PTHREAD_KEYS_MAX) |
| POSIX-standard name for STK_C_PTHREAD_KEYS_MAX (this file). | |
| #define | PTHREAD_DESTRUCTOR_ITERATIONS (4) |
| Maximum number of passes over a finishing thread's keys made while destructors keep setting new non-NULL values for their own key. See "pthread_key_t / thread-specific data limitation" in the file-level docs. | |
Typedefs | |
| typedef struct pthread_stk_ctrl_t * | pthread_t |
| Opaque thread handle. | |
| typedef struct pthread_attr_t | pthread_attr_t |
| Thread creation attributes. | |
| typedef struct pthread_mutexattr_t | pthread_mutexattr_t |
| Mutex attributes. | |
| typedef struct pthread_mutex_t | pthread_mutex_t |
| A pthread mutex. | |
| typedef struct pthread_condattr_t | pthread_condattr_t |
| Condition variable attributes (currently no settable properties). | |
| typedef struct pthread_cond_t | pthread_cond_t |
| A pthread condition variable. | |
| typedef struct pthread_rwlockattr_t | pthread_rwlockattr_t |
| Read-write lock attributes (currently no settable properties). | |
| typedef struct pthread_rwlock_t | pthread_rwlock_t |
| A pthread read-write lock. | |
| typedef struct pthread_spinlock_t | pthread_spinlock_t |
| A pthread spinlock. | |
| typedef struct pthread_barrierattr_t | pthread_barrierattr_t |
| Barrier attributes (currently no settable properties). | |
| typedef struct pthread_barrier_t | pthread_barrier_t |
| A pthread barrier. | |
| typedef struct pthread_once_t | pthread_once_t |
| A pthread_once() control object. | |
| typedef unsigned int | pthread_key_t |
| A thread-specific data key. | |
Functions | |
| void | stk_pthread_bind_kernel (stk_kernel_t *kernel) |
| Bind the STK kernel instance that pthread_create() will add new threads to. | |
| int | pthread_attr_init (pthread_attr_t *attr) |
| Initialize a thread attributes object with default values (default stack size, no external stack, joinable). | |
| int | pthread_attr_destroy (pthread_attr_t *attr) |
| Destroy a thread attributes object (no-op; no owned resources). | |
| int | pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) |
| Set the requested stack size in bytes. | |
| int | pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize) |
| Get the currently requested stack size in bytes (0 = default). | |
| int | pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, size_t stacksize) |
| Supply an external, caller-owned stack buffer for the thread. | |
| int | pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, size_t *stacksize) |
| Get the previously-set external stack (NULL/0 if none set). | |
| int | pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate) |
| Set PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED. | |
| int | pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate) |
| Get the current detach-state setting. | |
| int | pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) |
| Create and start a new thread. | |
| int | pthread_join (pthread_t thread, void **retval) |
| Block until the given joinable thread finishes, then reclaim its resources. | |
| int | pthread_detach (pthread_t thread) |
| Mark a thread as detached. | |
| void | pthread_exit (void *retval) |
| Terminate the calling thread. | |
| pthread_t | pthread_self (void) |
| Return the calling thread's own handle. | |
| int | pthread_equal (pthread_t t1, pthread_t t2) |
| Compare two thread handles for equality. | |
| int | pthread_yield (void) |
| Voluntarily give up the CPU to another ready task (cooperative yield), then resume once rescheduled. | |
| int | pthread_mutexattr_init (pthread_mutexattr_t *attr) |
| int | pthread_mutexattr_destroy (pthread_mutexattr_t *attr) |
| int | pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) |
| Set the mutex type. | |
| int | pthread_mutexattr_gettype (const pthread_mutexattr_t *attr, int *type) |
| int | pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) |
| Initialize a mutex. | |
| int | pthread_mutex_destroy (pthread_mutex_t *mutex) |
| int | pthread_mutex_lock (pthread_mutex_t *mutex) |
| int | pthread_mutex_trylock (pthread_mutex_t *mutex) |
| int | pthread_mutex_unlock (pthread_mutex_t *mutex) |
| int | pthread_mutex_timedlock (pthread_mutex_t *mutex, const struct timespec *abstime) |
| Lock with an absolute deadline. | |
| int | pthread_condattr_init (pthread_condattr_t *attr) |
| int | pthread_condattr_destroy (pthread_condattr_t *attr) |
| int | pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) |
| int | pthread_cond_destroy (pthread_cond_t *cond) |
| int | pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) |
| Atomically unlock mutex and wait for a signal; re-locks mutex before returning. | |
| int | pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) |
| As pthread_cond_wait(), with an absolute deadline. | |
| int | pthread_cond_signal (pthread_cond_t *cond) |
| int | pthread_cond_broadcast (pthread_cond_t *cond) |
| int | pthread_rwlockattr_init (pthread_rwlockattr_t *attr) |
| int | pthread_rwlockattr_destroy (pthread_rwlockattr_t *attr) |
| int | pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) |
| Initialize a read-write lock. | |
| int | pthread_rwlock_destroy (pthread_rwlock_t *rwlock) |
| int | pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) |
| Acquire the lock for shared reading. Blocks until available. | |
| int | pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) |
| Try to acquire the read lock without blocking. | |
| int | pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock, const struct timespec *abstime) |
| Acquire the read lock with an absolute deadline. | |
| int | pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) |
| Acquire the lock for exclusive writing. Blocks until available. | |
| int | pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock) |
| Try to acquire the write lock without blocking. | |
| int | pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, const struct timespec *abstime) |
| Acquire the write lock with an absolute deadline. | |
| int | pthread_rwlock_unlock (pthread_rwlock_t *rwlock) |
| Release a read or write hold, whichever the calling thread holds. | |
| int | pthread_spin_init (pthread_spinlock_t *lock, int pshared) |
| Initialize a spinlock. | |
| int | pthread_spin_destroy (pthread_spinlock_t *lock) |
| int | pthread_spin_lock (pthread_spinlock_t *lock) |
| Acquire the spinlock, spinning until available. | |
| int | pthread_spin_trylock (pthread_spinlock_t *lock) |
| Try to acquire the spinlock without blocking. | |
| int | pthread_spin_unlock (pthread_spinlock_t *lock) |
| int | pthread_barrierattr_init (pthread_barrierattr_t *attr) |
| int | pthread_barrierattr_destroy (pthread_barrierattr_t *attr) |
| int | pthread_barrier_init (pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count) |
| Initialize a barrier for count participating threads. | |
| int | pthread_barrier_destroy (pthread_barrier_t *barrier) |
| int | pthread_barrier_wait (pthread_barrier_t *barrier) |
| Block until count threads have called this function, then release them all together; the barrier resets for reuse. | |
| int | pthread_once (pthread_once_t *once_control, void(*init_routine)(void)) |
| Call init_routine exactly once for a given once_control, no matter how many threads call pthread_once() on it concurrently. | |
| int | pthread_key_create (pthread_key_t *key, void(*destructor)(void *)) |
| Allocate a new thread-specific data key. | |
| int | pthread_key_delete (pthread_key_t key) |
| Free a thread-specific data key. | |
| int | pthread_setspecific (pthread_key_t key, const void *value) |
| Set the calling thread's value for key. | |
| void * | pthread_getspecific (pthread_key_t key) |
| Get the calling thread's value for key. | |
Minimal POSIX-threads-style interface for SuperTinyKernel RTOS.
| #define PTHREAD_BARRIER_SERIAL_THREAD (-1) |
Returned by pthread_barrier_wait() to exactly one arbitrary caller per round; all others receive 0. See "pthread_barrier_wait() note" in the file-level docs.
Definition at line 339 of file stk_c_pthread.h.
Referenced by pthread_barrier_wait().
| #define PTHREAD_COND_INITIALIZER {0} |
Definition at line 273 of file stk_c_pthread.h.
| #define PTHREAD_CREATE_DETACHED (1) |
Definition at line 227 of file stk_c_pthread.h.
Referenced by pthread_attr_setdetachstate(), and pthread_create().
| #define PTHREAD_CREATE_JOINABLE (0) |
Definition at line 226 of file stk_c_pthread.h.
Referenced by pthread_attr_init(), and pthread_attr_setdetachstate().
| #define PTHREAD_DESTRUCTOR_ITERATIONS (4) |
Maximum number of passes over a finishing thread's keys made while destructors keep setting new non-NULL values for their own key. See "pthread_key_t / thread-specific data limitation" in the file-level docs.
Definition at line 373 of file stk_c_pthread.h.
Referenced by anonymous_namespace{stk_c_pthread.cpp}::RunKeyDestructors().
| #define PTHREAD_KEYS_MAX (STK_C_PTHREAD_KEYS_MAX) |
POSIX-standard name for STK_C_PTHREAD_KEYS_MAX (this file).
Definition at line 365 of file stk_c_pthread.h.
| #define PTHREAD_MUTEX_DEFAULT (PTHREAD_MUTEX_NORMAL) |
Definition at line 238 of file stk_c_pthread.h.
Referenced by pthread_mutexattr_init().
| #define PTHREAD_MUTEX_ERRORCHECK (1) |
Definition at line 239 of file stk_c_pthread.h.
| #define PTHREAD_MUTEX_INITIALIZER {0} |
Definition at line 253 of file stk_c_pthread.h.
| #define PTHREAD_MUTEX_NORMAL (0) |
Definition at line 237 of file stk_c_pthread.h.
Referenced by pthread_mutex_init(), and pthread_mutexattr_settype().
| #define PTHREAD_MUTEX_RECURSIVE (2) |
Definition at line 240 of file stk_c_pthread.h.
| #define PTHREAD_ONCE_INIT {0} |
Definition at line 354 of file stk_c_pthread.h.
| #define PTHREAD_PROCESS_PRIVATE (0) |
Definition at line 301 of file stk_c_pthread.h.
Referenced by pthread_spin_init().
| #define PTHREAD_PROCESS_SHARED (1) |
Definition at line 302 of file stk_c_pthread.h.
| #define PTHREAD_RWLOCK_INITIALIZER {0} |
Definition at line 299 of file stk_c_pthread.h.
| #define STK_C_PTHREAD_DEFAULT_STACK_WORDS (1024U) |
Default per-thread stack size in stk_word_t units, used when pthread_attr_t does not specify a stack size or an external stack (default: 1024 words).
Definition at line 173 of file stk_c_pthread.h.
| #define STK_C_PTHREAD_KEYS_MAX (8U) |
Maximum number of concurrently-alive pthread_key_t's (default: 8).
PTHREAD_KEYS_MAX. Definition at line 189 of file stk_c_pthread.h.
Referenced by pthread_getspecific(), pthread_key_create(), pthread_key_delete(), pthread_setspecific(), and anonymous_namespace{stk_c_pthread.cpp}::RunKeyDestructors().
| #define STK_C_PTHREAD_MAX_THREADS (8U) |
Maximum number of concurrently-alive pthread_t's (default: 8).
Definition at line 161 of file stk_c_pthread.h.
Referenced by anonymous_namespace{stk_c_pthread.cpp}::AcquireThreadSlot(), anonymous_namespace{stk_c_pthread.cpp}::DequeueReap(), anonymous_namespace{stk_c_pthread.cpp}::EnqueueReap(), anonymous_namespace{stk_c_pthread.cpp}::EnsureStackPool(), and anonymous_namespace{stk_c_pthread.cpp}::STK_BLOCKPOOL_STORAGE_DECL().
| #define STK_C_PTHREAD_REAPER_STACK_WORDS (256U) |
Stack size (in stk_word_t units) for the internal reaper task that reclaims detached-thread resources (default: 256 words).
Definition at line 181 of file stk_c_pthread.h.
Referenced by anonymous_namespace{stk_c_pthread.cpp}::EnsureReaper().
| typedef struct pthread_attr_t pthread_attr_t |
Thread creation attributes.
| typedef struct pthread_barrier_t pthread_barrier_t |
A pthread barrier.
| typedef struct pthread_barrierattr_t pthread_barrierattr_t |
Barrier attributes (currently no settable properties).
| typedef struct pthread_cond_t pthread_cond_t |
A pthread condition variable.
| typedef struct pthread_condattr_t pthread_condattr_t |
Condition variable attributes (currently no settable properties).
| typedef unsigned int pthread_key_t |
A thread-specific data key.
Definition at line 360 of file stk_c_pthread.h.
| typedef struct pthread_mutex_t pthread_mutex_t |
A pthread mutex.
| typedef struct pthread_mutexattr_t pthread_mutexattr_t |
Mutex attributes.
| typedef struct pthread_once_t pthread_once_t |
A pthread_once() control object.
| typedef struct pthread_rwlock_t pthread_rwlock_t |
A pthread read-write lock.
| typedef struct pthread_rwlockattr_t pthread_rwlockattr_t |
Read-write lock attributes (currently no settable properties).
| typedef struct pthread_spinlock_t pthread_spinlock_t |
A pthread spinlock.
| typedef struct pthread_stk_ctrl_t* pthread_t |
Opaque thread handle.
Definition at line 214 of file stk_c_pthread.h.
| int pthread_attr_destroy | ( | pthread_attr_t * | attr | ) |
Destroy a thread attributes object (no-op; no owned resources).
Definition at line 473 of file stk_c_pthread.cpp.
| int pthread_attr_getdetachstate | ( | const pthread_attr_t * | attr, |
| int * | detachstate ) |
Get the current detach-state setting.
Definition at line 526 of file stk_c_pthread.cpp.
References pthread_attr_t::__detachstate.
| int pthread_attr_getstack | ( | const pthread_attr_t * | attr, |
| void ** | stackaddr, | ||
| size_t * | stacksize ) |
Get the previously-set external stack (NULL/0 if none set).
Definition at line 505 of file stk_c_pthread.cpp.
References pthread_attr_t::__ext_stack, and pthread_attr_t::__stack_bytes.
| int pthread_attr_getstacksize | ( | const pthread_attr_t * | attr, |
| size_t * | stacksize ) |
Get the currently requested stack size in bytes (0 = default).
Definition at line 487 of file stk_c_pthread.cpp.
References pthread_attr_t::__stack_bytes, and anonymous_namespace{stk_c_pthread.cpp}::kDefaultStackBytes.
| int pthread_attr_init | ( | pthread_attr_t * | attr | ) |
Initialize a thread attributes object with default values (default stack size, no external stack, joinable).
Definition at line 463 of file stk_c_pthread.cpp.
References pthread_attr_t::__detachstate, pthread_attr_t::__ext_stack, pthread_attr_t::__stack_bytes, and PTHREAD_CREATE_JOINABLE.
| int pthread_attr_setdetachstate | ( | pthread_attr_t * | attr, |
| int | detachstate ) |
Set PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED.
Definition at line 514 of file stk_c_pthread.cpp.
References pthread_attr_t::__detachstate, PTHREAD_CREATE_DETACHED, and PTHREAD_CREATE_JOINABLE.
| int pthread_attr_setstack | ( | pthread_attr_t * | attr, |
| void * | stackaddr, | ||
| size_t | stacksize ) |
Supply an external, caller-owned stack buffer for the thread.
The buffer is never freed by this shim; the caller must keep it valid for the entire lifetime of the thread.
| [in] | stackaddr | Pointer to a stk_word_t-aligned buffer. |
| [in] | stacksize | Size of the buffer in bytes. |
Definition at line 495 of file stk_c_pthread.cpp.
References pthread_attr_t::__ext_stack, pthread_attr_t::__stack_bytes, and STK_ALIGN_MASK.
| int pthread_attr_setstacksize | ( | pthread_attr_t * | attr, |
| size_t | stacksize ) |
Set the requested stack size in bytes.
Definition at line 479 of file stk_c_pthread.cpp.
References pthread_attr_t::__stack_bytes.
| int pthread_barrier_destroy | ( | pthread_barrier_t * | barrier | ) |
Definition at line 1068 of file stk_c_pthread.cpp.
References pthread_barrier_t::__handle, and stk_barrier_destroy().
| int pthread_barrier_init | ( | pthread_barrier_t * | barrier, |
| const pthread_barrierattr_t * | attr, | ||
| unsigned int | count ) |
Initialize a barrier for count participating threads.
| [in] | attr | Optional, or NULL for defaults (no settable properties). |
| [in] | count | Number of threads that must call pthread_barrier_wait() before any of them is released. Must not be 0. |
Definition at line 1057 of file stk_c_pthread.cpp.
References pthread_barrier_t::__handle, pthread_barrier_t::__mem, and stk_barrier_create().
| int pthread_barrier_wait | ( | pthread_barrier_t * | barrier | ) |
Block until count threads have called this function, then release them all together; the barrier resets for reuse.
Definition at line 1080 of file stk_c_pthread.cpp.
References pthread_barrier_t::__handle, PTHREAD_BARRIER_SERIAL_THREAD, and stk_barrier_wait().
| int pthread_barrierattr_destroy | ( | pthread_barrierattr_t * | attr | ) |
Definition at line 1051 of file stk_c_pthread.cpp.
| int pthread_barrierattr_init | ( | pthread_barrierattr_t * | attr | ) |
Definition at line 1043 of file stk_c_pthread.cpp.
References pthread_barrierattr_t::__reserved.
| int pthread_cond_broadcast | ( | pthread_cond_t * | cond | ) |
Definition at line 874 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureCond(), and stk_cv_notify_all().
| int pthread_cond_destroy | ( | pthread_cond_t * | cond | ) |
Definition at line 835 of file stk_c_pthread.cpp.
References pthread_cond_t::__handle, and stk_cv_destroy().
| int pthread_cond_init | ( | pthread_cond_t * | cond, |
| const pthread_condattr_t * | attr ) |
Definition at line 827 of file stk_c_pthread.cpp.
References pthread_cond_t::__handle, pthread_cond_t::__mem, and stk_cv_create().
| int pthread_cond_signal | ( | pthread_cond_t * | cond | ) |
Definition at line 866 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureCond(), and stk_cv_notify_one().
| int pthread_cond_timedwait | ( | pthread_cond_t * | cond, |
| pthread_mutex_t * | mutex, | ||
| const struct timespec * | abstime ) |
As pthread_cond_wait(), with an absolute deadline.
Definition at line 855 of file stk_c_pthread.cpp.
References pthread_mutex_t::__handle, anonymous_namespace{stk_c_pthread.cpp}::EnsureCond(), stk_cv_wait(), and anonymous_namespace{stk_c_pthread.cpp}::TimespecToRelativeTimeout().
| int pthread_cond_wait | ( | pthread_cond_t * | cond, |
| pthread_mutex_t * | mutex ) |
Atomically unlock mutex and wait for a signal; re-locks mutex before returning.
Definition at line 847 of file stk_c_pthread.cpp.
References pthread_mutex_t::__handle, anonymous_namespace{stk_c_pthread.cpp}::EnsureCond(), stk_cv_wait(), and STK_WAIT_INFINITE.
| int pthread_condattr_destroy | ( | pthread_condattr_t * | attr | ) |
Definition at line 821 of file stk_c_pthread.cpp.
| int pthread_condattr_init | ( | pthread_condattr_t * | attr | ) |
Definition at line 813 of file stk_c_pthread.cpp.
References pthread_condattr_t::__reserved.
| int pthread_create | ( | pthread_t * | thread, |
| const pthread_attr_t * | attr, | ||
| void *(* | start_routine )(void *), | ||
| void * | arg ) |
Create and start a new thread.
| [out] | thread | Receives the new thread's handle on success. |
| [in] | attr | Optional attributes, or NULL for defaults. |
| [in] | start_routine | Thread entry function. |
| [in] | arg | Argument passed to start_routine. |
Definition at line 537 of file stk_c_pthread.cpp.
References pthread_attr_t::__detachstate, pthread_attr_t::__ext_stack, pthread_attr_t::__stack_bytes, anonymous_namespace{stk_c_pthread.cpp}::AcquireThreadSlot(), pthread_stk_ctrl_t::arg, pthread_stk_ctrl_t::busy, pthread_stk_ctrl_t::detached, pthread_stk_ctrl_t::done_event, pthread_stk_ctrl_t::done_event_mem, anonymous_namespace{stk_c_pthread.cpp}::EnsureReaper(), anonymous_namespace{stk_c_pthread.cpp}::EnsureStackPool(), free(), anonymous_namespace{stk_c_pthread.cpp}::kDefaultStackBytes, malloc(), PTHREAD_CREATE_DETACHED, anonymous_namespace{stk_c_pthread.cpp}::PthreadTrampoline(), pthread_stk_ctrl_t::retval, anonymous_namespace{stk_c_pthread.cpp}::s_BoundKernel, anonymous_namespace{stk_c_pthread.cpp}::s_StackPool, pthread_stk_ctrl_t::stack, pthread_stk_ctrl_t::stack_from_pool, pthread_stk_ctrl_t::stack_owned, pthread_stk_ctrl_t::start_routine, stk_blockpool_free(), stk_blockpool_try_alloc(), STK_C_ASSERT, stk_critical_section_enter(), stk_critical_section_exit(), stk_event_create(), stk_event_destroy(), stk_kernel_add_task(), stk_task_create_user(), and pthread_stk_ctrl_t::task.
| int pthread_detach | ( | pthread_t | thread | ) |
Mark a thread as detached.
A detached thread's resources are reclaimed automatically (by an internal reaper task) once it finishes; it must not be joined.
Definition at line 657 of file stk_c_pthread.cpp.
References pthread_stk_ctrl_t::detached, pthread_stk_ctrl_t::joined, anonymous_namespace{stk_c_pthread.cpp}::MaybeReap(), stk_critical_section_enter(), and stk_critical_section_exit().
Compare two thread handles for equality.
Definition at line 712 of file stk_c_pthread.cpp.
| void pthread_exit | ( | void * | retval | ) |
Terminate the calling thread.
| [in] | retval | Value made available to a joiner via pthread_join(), or discarded if the thread is detached. |
Definition at line 677 of file stk_c_pthread.cpp.
References pthread_stk_ctrl_t::done_event, pthread_stk_ctrl_t::finished, anonymous_namespace{stk_c_pthread.cpp}::MaybeReap(), pthread_stk_ctrl_t::retval, anonymous_namespace{stk_c_pthread.cpp}::RunKeyDestructors(), anonymous_namespace{stk_c_pthread.cpp}::s_BoundKernel, STK_C_ASSERT, stk_critical_section_enter(), stk_critical_section_exit(), stk_event_set(), stk_kernel_schedule_task_removal(), stk_sleep(), stk_tls_get(), STK_WAIT_INFINITE, and pthread_stk_ctrl_t::task.
| void * pthread_getspecific | ( | pthread_key_t | key | ) |
Get the calling thread's value for key.
Definition at line 1168 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::s_Keys, STK_C_PTHREAD_KEYS_MAX, stk_tls_get(), and pthread_stk_ctrl_t::tsd.
| int pthread_join | ( | pthread_t | thread, |
| void ** | retval ) |
Block until the given joinable thread finishes, then reclaim its resources.
| [in] | thread | Thread to join. |
| [out] | retval | Optional; receives the thread's return value / the value passed to pthread_exit(). |
Definition at line 629 of file stk_c_pthread.cpp.
References pthread_stk_ctrl_t::detached, pthread_stk_ctrl_t::done_event, pthread_stk_ctrl_t::joined, anonymous_namespace{stk_c_pthread.cpp}::ReleaseThreadResources(), pthread_stk_ctrl_t::retval, stk_critical_section_enter(), stk_critical_section_exit(), stk_event_wait(), STK_WAIT_INFINITE, pthread_stk_ctrl_t::task, and anonymous_namespace{stk_c_pthread.cpp}::WaitForTaskGone().
| int pthread_key_create | ( | pthread_key_t * | key, |
| void(* | destructor )(void *) ) |
Allocate a new thread-specific data key.
| [out] | key | Receives the new key on success. |
| [in] | destructor | Optional; called with a thread's non-NULL value for this key when that thread finishes. May be NULL. |
Definition at line 1116 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::KeyEntry::destructor, anonymous_namespace{stk_c_pthread.cpp}::s_Keys, STK_C_PTHREAD_KEYS_MAX, stk_critical_section_enter(), stk_critical_section_exit(), and anonymous_namespace{stk_c_pthread.cpp}::KeyEntry::used.
| int pthread_key_delete | ( | pthread_key_t | key | ) |
Free a thread-specific data key.
Does not run destructors and does not clear any thread's stored value for this key (matching POSIX); reusing a stale value after deletion is undefined behavior, as in real pthreads.
Definition at line 1139 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::KeyEntry::destructor, anonymous_namespace{stk_c_pthread.cpp}::s_Keys, STK_C_PTHREAD_KEYS_MAX, stk_critical_section_enter(), stk_critical_section_exit(), and anonymous_namespace{stk_c_pthread.cpp}::KeyEntry::used.
| int pthread_mutex_destroy | ( | pthread_mutex_t * | mutex | ) |
Definition at line 766 of file stk_c_pthread.cpp.
References pthread_mutex_t::__handle, and stk_mutex_destroy().
| int pthread_mutex_init | ( | pthread_mutex_t * | mutex, |
| const pthread_mutexattr_t * | attr ) |
Initialize a mutex.
| [in] | attr | Optional, or NULL for defaults. Only NORMAL/DEFAULT type is supported; any other type returns ENOTSUP and leaves the mutex uninitialized. |
Definition at line 757 of file stk_c_pthread.cpp.
References pthread_mutex_t::__handle, pthread_mutex_t::__mem, pthread_mutexattr_t::__type, PTHREAD_MUTEX_NORMAL, and stk_mutex_create().
| int pthread_mutex_lock | ( | pthread_mutex_t * | mutex | ) |
Definition at line 778 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureMutex(), and stk_mutex_lock().
| int pthread_mutex_timedlock | ( | pthread_mutex_t * | mutex, |
| const struct timespec * | abstime ) |
Lock with an absolute deadline.
Definition at line 802 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureMutex(), stk_mutex_timed_lock(), and anonymous_namespace{stk_c_pthread.cpp}::TimespecToRelativeTimeout().
| int pthread_mutex_trylock | ( | pthread_mutex_t * | mutex | ) |
Definition at line 786 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureMutex(), and stk_mutex_trylock().
| int pthread_mutex_unlock | ( | pthread_mutex_t * | mutex | ) |
Definition at line 793 of file stk_c_pthread.cpp.
References pthread_mutex_t::__handle, and stk_mutex_unlock().
| int pthread_mutexattr_destroy | ( | pthread_mutexattr_t * | attr | ) |
Definition at line 734 of file stk_c_pthread.cpp.
| int pthread_mutexattr_gettype | ( | const pthread_mutexattr_t * | attr, |
| int * | type ) |
Definition at line 749 of file stk_c_pthread.cpp.
References pthread_mutexattr_t::__type.
| int pthread_mutexattr_init | ( | pthread_mutexattr_t * | attr | ) |
Definition at line 726 of file stk_c_pthread.cpp.
References pthread_mutexattr_t::__type, and PTHREAD_MUTEX_DEFAULT.
| int pthread_mutexattr_settype | ( | pthread_mutexattr_t * | attr, |
| int | type ) |
Set the mutex type.
Definition at line 740 of file stk_c_pthread.cpp.
References pthread_mutexattr_t::__type, and PTHREAD_MUTEX_NORMAL.
| int pthread_once | ( | pthread_once_t * | once_control, |
| void(* | init_routine )(void) ) |
Call init_routine exactly once for a given once_control, no matter how many threads call pthread_once() on it concurrently.
Definition at line 1090 of file stk_c_pthread.cpp.
References pthread_once_t::__state, anonymous_namespace{stk_c_pthread.cpp}::EnsureOnceMutex(), stk_mutex_lock(), and stk_mutex_unlock().
| int pthread_rwlock_destroy | ( | pthread_rwlock_t * | rwlock | ) |
Definition at line 908 of file stk_c_pthread.cpp.
References pthread_rwlock_t::__handle, and stk_rwmutex_destroy().
| int pthread_rwlock_init | ( | pthread_rwlock_t * | rwlock, |
| const pthread_rwlockattr_t * | attr ) |
Initialize a read-write lock.
| [in] | attr | Optional, or NULL for defaults (no settable properties). |
Definition at line 899 of file stk_c_pthread.cpp.
References pthread_rwlock_t::__handle, pthread_rwlock_t::__mem, pthread_rwlock_t::__wrlocked, and stk_rwmutex_create().
| int pthread_rwlock_rdlock | ( | pthread_rwlock_t * | rwlock | ) |
Acquire the lock for shared reading. Blocks until available.
Blocks if a writer is currently active or writers are waiting (writer-preference policy; see stk_rwmutex_read_lock() in stk_c.h).
Definition at line 920 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureRWLock(), and stk_rwmutex_read_lock().
| int pthread_rwlock_timedrdlock | ( | pthread_rwlock_t * | rwlock, |
| const struct timespec * | abstime ) |
Acquire the read lock with an absolute deadline.
Definition at line 935 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureRWLock(), stk_rwmutex_timed_read_lock(), and anonymous_namespace{stk_c_pthread.cpp}::TimespecToRelativeTimeout().
| int pthread_rwlock_timedwrlock | ( | pthread_rwlock_t * | rwlock, |
| const struct timespec * | abstime ) |
Acquire the write lock with an absolute deadline.
Definition at line 962 of file stk_c_pthread.cpp.
References pthread_rwlock_t::__wrlocked, anonymous_namespace{stk_c_pthread.cpp}::EnsureRWLock(), stk_rwmutex_timed_lock(), and anonymous_namespace{stk_c_pthread.cpp}::TimespecToRelativeTimeout().
| int pthread_rwlock_tryrdlock | ( | pthread_rwlock_t * | rwlock | ) |
Try to acquire the read lock without blocking.
Definition at line 928 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::EnsureRWLock(), and stk_rwmutex_try_read_lock().
| int pthread_rwlock_trywrlock | ( | pthread_rwlock_t * | rwlock | ) |
Try to acquire the write lock without blocking.
Definition at line 952 of file stk_c_pthread.cpp.
References pthread_rwlock_t::__wrlocked, anonymous_namespace{stk_c_pthread.cpp}::EnsureRWLock(), and stk_rwmutex_trylock().
| int pthread_rwlock_unlock | ( | pthread_rwlock_t * | rwlock | ) |
Release a read or write hold, whichever the calling thread holds.
Definition at line 972 of file stk_c_pthread.cpp.
References pthread_rwlock_t::__handle, pthread_rwlock_t::__wrlocked, stk_rwmutex_read_unlock(), and stk_rwmutex_unlock().
| int pthread_rwlock_wrlock | ( | pthread_rwlock_t * | rwlock | ) |
Acquire the lock for exclusive writing. Blocks until available.
Blocks until all active readers have released their locks and no other writer is active.
Definition at line 943 of file stk_c_pthread.cpp.
References pthread_rwlock_t::__wrlocked, anonymous_namespace{stk_c_pthread.cpp}::EnsureRWLock(), and stk_rwmutex_lock().
| int pthread_rwlockattr_destroy | ( | pthread_rwlockattr_t * | attr | ) |
Definition at line 893 of file stk_c_pthread.cpp.
| int pthread_rwlockattr_init | ( | pthread_rwlockattr_t * | attr | ) |
Definition at line 885 of file stk_c_pthread.cpp.
References pthread_rwlockattr_t::__reserved.
| pthread_t pthread_self | ( | void | ) |
Return the calling thread's own handle.
Definition at line 707 of file stk_c_pthread.cpp.
References stk_tls_get().
| int pthread_setspecific | ( | pthread_key_t | key, |
| const void * | value ) |
Set the calling thread's value for key.
Definition at line 1157 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::s_Keys, STK_C_PTHREAD_KEYS_MAX, stk_tls_get(), and pthread_stk_ctrl_t::tsd.
| int pthread_spin_destroy | ( | pthread_spinlock_t * | lock | ) |
Definition at line 1005 of file stk_c_pthread.cpp.
References pthread_spinlock_t::__handle, and stk_spinlock_destroy().
| int pthread_spin_init | ( | pthread_spinlock_t * | lock, |
| int | pshared ) |
Initialize a spinlock.
| [in] | pshared | Must be PTHREAD_PROCESS_PRIVATE. |
Definition at line 996 of file stk_c_pthread.cpp.
References pthread_spinlock_t::__handle, pthread_spinlock_t::__mem, PTHREAD_PROCESS_PRIVATE, and stk_spinlock_create().
| int pthread_spin_lock | ( | pthread_spinlock_t * | lock | ) |
Acquire the spinlock, spinning until available.
Definition at line 1017 of file stk_c_pthread.cpp.
References pthread_spinlock_t::__handle, and stk_spinlock_lock().
| int pthread_spin_trylock | ( | pthread_spinlock_t * | lock | ) |
Try to acquire the spinlock without blocking.
Definition at line 1025 of file stk_c_pthread.cpp.
References pthread_spinlock_t::__handle, and stk_spinlock_trylock().
| int pthread_spin_unlock | ( | pthread_spinlock_t * | lock | ) |
Definition at line 1032 of file stk_c_pthread.cpp.
References pthread_spinlock_t::__handle, and stk_spinlock_unlock().
| int pthread_yield | ( | void | ) |
Voluntarily give up the CPU to another ready task (cooperative yield), then resume once rescheduled.
sched_yield()), but widely available as a GNU/BSD extension under this name. Definition at line 717 of file stk_c_pthread.cpp.
References stk_yield().
| void stk_pthread_bind_kernel | ( | stk_kernel_t * | kernel | ) |
Bind the STK kernel instance that pthread_create() will add new threads to.
Must be called exactly once, before the first pthread_create() call. The kernel must already be created (stk_kernel_create()) and initialized (stk_kernel_init()); it does not need to be started yet, but in practice pthread_create() will only usefully run new threads once stk_kernel_start() has been called on it.
| [in] | kernel | Kernel handle obtained from stk_kernel_create(). Must be a KERNEL_DYNAMIC kernel (threads need to be able to finish/return). |
Definition at line 453 of file stk_c_pthread.cpp.
References anonymous_namespace{stk_c_pthread.cpp}::s_BoundKernel, and STK_C_ASSERT.