SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk_c_pthread.h
Go to the documentation of this file.
1/*
2 * SuperTinyKernel(TM) RTOS: Lightweight High-Performance Deterministic C++ RTOS for Embedded Systems.
3 *
4 * Source: https://github.com/SuperTinyKernel-RTOS
5 *
6 * Copyright (c) 2022-2026 Neutron Code Limited <stk@neutroncode.com>. All Rights Reserved.
7 * License: MIT License, see LICENSE for a full text.
8 */
9
10#ifndef STK_C_PTHREAD_H_
11#define STK_C_PTHREAD_H_
12
13// Undefine system headers:
14#undef _POSIX_THREADS
15
16// The toolchain's own pthread types must not be defined: this header provides them. All headers of the layer
17// install the guard below before any toolchain header is read, but a toolchain header which was included EARLIER
18// (<sys/types.h>, <pthread.h>, <signal.h> of the toolchain) has already defined them: reported clearly here.
19#if defined(_SYS__PTHREADTYPES_H_) && !defined(STK_C_PTHREADTYPES_GUARD)
20 #error "The toolchain's pthread types are already defined: include the POSIX layer's headers (pthread.h, time.h, signal.h, ...) before any toolchain header, and put the layer's include directory ahead of the toolchain's"
21#endif
22#ifndef _SYS__PTHREADTYPES_H_
23 #define _SYS__PTHREADTYPES_H_
24 #define STK_C_PTHREADTYPES_GUARD
25#endif
26
27// Self-contained: does not depend on the C API (stk_c.h). Only the kernel configuration is needed to size the
28// opaque storage of the C++ objects the shim constructs in place.
29#ifdef __cplusplus
30 #include <cstdint>
31 #include <cstddef>
32 #include <ctime>
33#else
34 #include <stdint.h>
35 #include <stddef.h>
36 #include <stdbool.h>
37 #include <time.h>
38#endif
39
40#include <stk_config.h>
41
42#include "sched.h" // struct sched_param, SCHED_*, sched_yield() and friends
43
44// must match the definition used by the C++ kernel API (stk_c.h and stk.h derive it the same way)
45#ifndef STK_SYNC_DEBUG_NAMES
46 #if STK_SEGGER_SYSVIEW
47 #define STK_SYNC_DEBUG_NAMES (1)
48 #else
49 #define STK_SYNC_DEBUG_NAMES (0)
50 #endif
51#endif
52
238
239#ifdef __cplusplus
240extern "C" {
241#endif
242
246typedef uintptr_t pthread_stk_word_t;
247
251#if defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__)
252 #define __stk_pthread_aligned __attribute__((aligned(sizeof(pthread_stk_word_t))))
253#else
254 #define __stk_pthread_aligned
255#endif
256
260#define STK_C_PTHREAD_MUTEX_WORDS (10U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))
261#define STK_C_PTHREAD_CV_WORDS (7U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))
262#define STK_C_PTHREAD_RWMUTEX_WORDS (17U + (STK_SYNC_DEBUG_NAMES ? 3U : 0U))
263#define STK_C_PTHREAD_BARRIER_WORDS (STK_C_PTHREAD_MUTEX_WORDS + STK_C_PTHREAD_CV_WORDS + 4U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))
264
269
273#define STK_C_PTHREAD_VERSION (0x20261004)
274
275// =============================================================================
276// Configuration macros (can be overridden before including this file)
277// =============================================================================
278
286#ifndef STK_C_PTHREAD_MAX_THREADS
287 #define STK_C_PTHREAD_MAX_THREADS (8U)
288#endif
289
298#ifndef STK_C_PTHREAD_DEFAULT_STACK_WORDS
299 #define STK_C_PTHREAD_DEFAULT_STACK_WORDS (1024U)
300#endif
301
306#ifndef STK_C_PTHREAD_REAPER_STACK_WORDS
307 #define STK_C_PTHREAD_REAPER_STACK_WORDS (256U)
308#endif
309
314#ifndef STK_C_PTHREAD_KEYS_MAX
315 #define STK_C_PTHREAD_KEYS_MAX (8U)
316#endif
317
318// =============================================================================
319// Bootstrap (STK-specific, not part of POSIX)
320// =============================================================================
321
338void stk_pthread_bind_kernel(void *kernel);
339
340// =============================================================================
341// Types
342// =============================================================================
343
347
351#ifndef STK_C_PTHREAD_NAME_MAX
352 #define STK_C_PTHREAD_NAME_MAX (16U)
353#endif
354
361#ifndef STK_C_PTHREAD_RUNTIME_PRIORITY
362 #define STK_C_PTHREAD_RUNTIME_PRIORITY (1)
363#endif
364
365#ifndef CLOCK_REALTIME
366 #define CLOCK_REALTIME (0)
367#endif
368#ifndef CLOCK_MONOTONIC
369 #define CLOCK_MONOTONIC (1)
370#endif
371
375#define PTHREAD_CANCEL_ENABLE (0)
376#define PTHREAD_CANCEL_DISABLE (1)
377#define PTHREAD_CANCEL_DEFERRED (0)
378#define PTHREAD_CANCEL_ASYNCHRONOUS (1)
379
383#define PTHREAD_CANCELED ((void *)(intptr_t)-1)
384
388#ifndef STK_C_PTHREAD_CLEANUP_MAX
389 #define STK_C_PTHREAD_CLEANUP_MAX (8U)
390#endif
391
395#define PTHREAD_INHERIT_SCHED (0)
396#define PTHREAD_EXPLICIT_SCHED (1)
397
401#define PTHREAD_SCOPE_SYSTEM (0)
402#define PTHREAD_SCOPE_PROCESS (1)
403
407#define PTHREAD_PRIO_NONE (0)
408#define PTHREAD_PRIO_INHERIT (1)
409#define PTHREAD_PRIO_PROTECT (2)
410
427
428#define PTHREAD_CREATE_JOINABLE (0)
429#define PTHREAD_CREATE_DETACHED (1)
430
435#define PTHREAD_CREATE_USER_NP (0)
436#define PTHREAD_CREATE_PRIVILEGED_NP (1)
437
455
456#define PTHREAD_MUTEX_NORMAL (0)
457#define PTHREAD_MUTEX_DEFAULT (PTHREAD_MUTEX_NORMAL)
458#define PTHREAD_MUTEX_ERRORCHECK (1)
459#define PTHREAD_MUTEX_RECURSIVE (2)
460
466#ifdef __cplusplus
467 #define STK_C_PTHREAD_ZERO_INIT {}
468#else
469 #define STK_C_PTHREAD_ZERO_INIT {0}
470#endif
471
483
484#define PTHREAD_MUTEX_INITIALIZER STK_C_PTHREAD_ZERO_INIT
485
492
503
504#define PTHREAD_COND_INITIALIZER STK_C_PTHREAD_ZERO_INIT
505
515
529
530#define PTHREAD_RWLOCK_INITIALIZER STK_C_PTHREAD_ZERO_INIT
531
532#define PTHREAD_PROCESS_PRIVATE (0)
533#define PTHREAD_PROCESS_SHARED (1)
534
548
555
566
572#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
573
586
587#define PTHREAD_ONCE_INIT STK_C_PTHREAD_ZERO_INIT
588
593typedef unsigned int pthread_key_t;
594
598#define PTHREAD_KEYS_MAX (STK_C_PTHREAD_KEYS_MAX)
599
606#define PTHREAD_DESTRUCTOR_ITERATIONS (4)
607
608// =============================================================================
609// Thread attributes
610// =============================================================================
611
617
622
630int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
631
639int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
640
648int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);
649
657int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize);
658
663int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
664
670int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
671
681
686int pthread_attr_getprivileged_np(const pthread_attr_t *attr, int *mode);
687
688// =============================================================================
689// Thread lifecycle
690// =============================================================================
691
705int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
706 void *(*start_routine)(void *), void *arg);
707
716int pthread_join(pthread_t thread, void **retval);
717
725int pthread_detach(pthread_t thread);
726
733void pthread_exit(void *retval);
734
741
747
755int pthread_yield(void);
756
757// =============================================================================
758// Mutex
759// =============================================================================
760
767
773
781
787int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
788
797
808
822
832
843
856int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);
857
858// =============================================================================
859// Condition variable
860// =============================================================================
861
868
874
882
891
910
927 const struct timespec *abstime);
928
936
942
943// =============================================================================
944// Read-write lock
945// =============================================================================
946
953
959
966
974
981
987
996int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
997
1004
1010
1019int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
1020
1027
1028// =============================================================================
1029// Spin lock
1030// =============================================================================
1031
1038int pthread_spin_init(pthread_spinlock_t *lock, int pshared);
1039
1047
1057
1064
1070
1071// =============================================================================
1072// Barrier
1073// =============================================================================
1074
1080
1086
1096 unsigned int count);
1097
1106
1115
1116// =============================================================================
1117// Once
1118// =============================================================================
1119
1129int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
1130
1131// =============================================================================
1132// Thread-specific data (keys)
1133// =============================================================================
1134
1142int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
1143
1153
1162int pthread_setspecific(pthread_key_t key, const void *value);
1163
1170
1171// -----------------------------------------------------------------------------
1172// Scheduling attributes, run-time scheduling and thread names
1173// -----------------------------------------------------------------------------
1174
1181int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);
1182
1186int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);
1187
1192int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
1193
1197int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
1198
1204int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
1205
1209int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
1210
1214int pthread_attr_setscope(pthread_attr_t *attr, int scope);
1215
1219int pthread_attr_getscope(const pthread_attr_t *attr, int *scope);
1220
1224int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
1225
1229int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize);
1230
1235int pthread_attr_setname_np(pthread_attr_t *attr, const char *name);
1236
1240int pthread_attr_getname_np(const pthread_attr_t *attr, char *name, size_t len);
1241
1245int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param);
1246
1254int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);
1255
1259int pthread_setschedprio(pthread_t thread, int prio);
1260
1265int pthread_setname_np(pthread_t thread, const char *name);
1266
1270int pthread_getname_np(pthread_t thread, char *name, size_t len);
1271
1275int pthread_setconcurrency(int level);
1276
1280int pthread_getconcurrency(void);
1281
1286int pthread_tryjoin_np(pthread_t thread, void **retval);
1287
1292int pthread_timedjoin_np(pthread_t thread, void **retval, const struct timespec *abstime);
1293
1294// -----------------------------------------------------------------------------
1295// Synchronization attributes (process-shared / protocol / clock)
1296// -----------------------------------------------------------------------------
1297
1304int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared);
1305int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
1306int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
1308int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared);
1310int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared);
1311
1318int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);
1319
1323int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol);
1324
1330int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id);
1331
1335int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id);
1336
1337// -----------------------------------------------------------------------------
1338// Clock-selecting timed waits (POSIX.1-2024)
1339// -----------------------------------------------------------------------------
1340
1345int pthread_mutex_clocklock(pthread_mutex_t *mutex, clockid_t clock_id, const struct timespec *abstime);
1346
1349int pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex, clockid_t clock_id,
1350 const struct timespec *abstime);
1351
1354int pthread_rwlock_clockrdlock(pthread_rwlock_t *rwlock, clockid_t clock_id, const struct timespec *abstime);
1355
1358int pthread_rwlock_clockwrlock(pthread_rwlock_t *rwlock, clockid_t clock_id, const struct timespec *abstime);
1359
1360// -----------------------------------------------------------------------------
1361// Cooperative cancellation
1362// -----------------------------------------------------------------------------
1363
1375int pthread_cancel(pthread_t thread);
1376
1381int pthread_setcancelstate(int state, int *oldstate);
1382
1386int pthread_setcanceltype(int type, int *oldtype);
1387
1390void pthread_testcancel(void);
1391
1396void pthread_cleanup_push(void (*routine)(void *), void *arg);
1397
1400void pthread_cleanup_pop(int execute);
1401
1408
1409// -----------------------------------------------------------------------------
1410// Terminating a thread by "signal", fork handlers
1411// -----------------------------------------------------------------------------
1412
1413// values of the signals which pthread_kill() understands (same as newlib and glibc: identical redefinition is allowed)
1414#ifndef SIGKILL
1415 #define SIGKILL 9
1416#endif
1417#ifndef SIGTERM
1418 #define SIGTERM 15
1419#endif
1420
1435int pthread_kill(pthread_t thread, int sig);
1436
1441int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void));
1442
1443#ifdef __cplusplus
1444}
1445#endif
1446
1448
1449#endif /* STK_C_PTHREAD_H_ */
POSIX-named scheduling API (<sched.h>) for STK: sched_yield(), sched_get_priority_min/max() and struc...
POSIX time extensions for STK: clock_gettime(), clock_getres(), nanosleep(), clock_nanosleep(),...
#define STK_C_PTHREAD_RWMUTEX_WORDS
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
Try to acquire the write lock without blocking.
int pthread_condattr_destroy(pthread_condattr_t *attr)
Destroy a condition variable attributes object (no-op).
int pthread_attr_init(pthread_attr_t *attr)
Initialize a thread attributes object with default values (default stack size, no external stack,...
#define STK_C_PTHREAD_CV_WORDS
int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
Get the clock stored in attr.
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock a mutex, blocking until it becomes available.
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
Change the policy/priority of a running thread.
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
Initialize a read-write lock.
int pthread_tryjoin_np(pthread_t thread, void **retval)
Try to join a thread without blocking (GNU extension).
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Acquire the write lock with an absolute deadline.
#define STK_C_PTHREAD_MUTEX_WORDS
Sizes (in pthread_stk_word_t units) of the opaque storage for the C++ sync objects.
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...
int pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex, clockid_t clock_id, const struct timespec *abstime)
pthread_cond_timedwait() with an explicit clock. See pthread_mutex_clocklock() for clock_id.
int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
#define STK_C_PTHREAD_NAME_MAX
Capacity of a thread name buffer including the terminating NUL (like Linux, 16).
int pthread_rwlock_clockwrlock(pthread_rwlock_t *rwlock, clockid_t clock_id, const struct timespec *abstime)
pthread_rwlock_timedwrlock() with an explicit clock. See pthread_mutex_clocklock() for clock_id.
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol)
Get the mutex protocol stored in attr.
int pthread_cond_signal(pthread_cond_t *cond)
Wake one thread waiting on cond (no effect if none is waiting).
int pthread_setspecific(pthread_key_t key, const void *value)
Set the calling thread's value for key.
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
Destroy a mutex attributes object (no-op; no owned resources).
void pthread_exit(void *retval)
Terminate the calling thread.
int pthread_mutex_trylock(pthread_mutex_t *mutex)
Try to lock a mutex without blocking.
int pthread_join(pthread_t thread, void **retval)
Block until the given joinable thread finishes, then reclaim its resources.
int pthread_attr_setscope(pthread_attr_t *attr, int scope)
Set the contention scope. Only PTHREAD_SCOPE_SYSTEM is supported.
int pthread_condattr_init(pthread_condattr_t *attr)
Initialize a condition variable attributes object (no settable properties).
int pthread_setcancelstate(int state, int *oldstate)
Enable or disable cancellation of the calling thread.
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
Get the current detach-state setting.
int pthread_spin_unlock(pthread_spinlock_t *lock)
Release a spinlock held by the calling thread.
int pthread_mutex_destroy(pthread_mutex_t *mutex)
Destroy a mutex, releasing the underlying STK mutex object.
int pthread_mutex_clocklock(pthread_mutex_t *mutex, clockid_t clock_id, const struct timespec *abstime)
pthread_mutex_timedlock() with an explicit clock.
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared)
int pthread_attr_destroy(pthread_attr_t *attr)
Destroy a thread attributes object (no-op; no owned resources).
pthread_t pthread_self(void)
Return the calling thread's own handle.
int pthread_attr_setname_np(pthread_attr_t *attr, const char *name)
Set the name of threads created with attr (non-portable, GNU-style).
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
Set the guard size. Accepted and stored, but STK has no guard pages: it has no effect.
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
Set the scheduling priority (task weight) of threads created with attr.
int pthread_spin_lock(pthread_spinlock_t *lock)
Acquire the spinlock, spinning until available.
int pthread_kill(pthread_t thread, int sig)
Send a "signal" to a thread. STK has no signals, three values are supported:
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
Acquire the lock for exclusive writing. Blocks until available.
int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
Lock with an absolute deadline.
void pthread_cleanup_push(void(*routine)(void *), void *arg)
Push a cleanup handler (run in LIFO order by pthread_exit() and by cancellation).
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
Get the attributes of a running thread (GNU extension).
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
Set/get the process-shared attribute of mutex, condition variable, rwlock and barrier attributes.
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize a mutex.
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
Destroy a read-write lock attributes object (no-op).
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
Destroy a read-write lock, releasing the underlying STK object.
int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched)
Get the inherit-scheduling mode stored in attr.
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
Set the scheduling policy stored in attr (SCHED_OTHER, SCHED_FIFO or SCHED_RR).
int pthread_setschedprio(pthread_t thread, int prio)
Change the priority of a running thread (the policy is kept). See pthread_setschedparam().
int pthread_detach(pthread_t thread)
Mark a thread as detached.
unsigned int pthread_key_t
A thread-specific data key.
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
Release a read or write hold, whichever the calling thread holds.
int pthread_attr_setprivileged_np(pthread_attr_t *attr, int mode)
Non-portable: select the STK access mode of threads created with attr.
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
Get the mutex type stored in attr.
struct pthread_stk_ctrl_t * pthread_t
Opaque thread handle.
int pthread_atfork(void(*prepare)(void), void(*parent)(void), void(*child)(void))
Register fork handlers. STK has no fork(): the handlers are never run, the call only exists so that c...
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
Set the requested stack size in bytes.
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
Set the mutex type.
int pthread_barrier_wait(pthread_barrier_t *barrier)
Block until count threads have called this function, then release them all together; the barrier rese...
int pthread_attr_getprivileged_np(const pthread_attr_t *attr, int *mode)
Non-portable: get the access mode set in attr.
int pthread_spin_destroy(pthread_spinlock_t *lock)
Destroy a spinlock.
#define __stk_pthread_aligned
Alignment attribute of the opaque object storage (one machine word).
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_getname_np(pthread_t thread, char *name, size_t len)
Get the name of a thread.
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_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize)
Supply an external, caller-owned stack buffer for the thread.
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Unlock a mutex held by the calling thread.
int pthread_equal(pthread_t t1, pthread_t t2)
Compare two thread handles for equality.
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
Initialize a read-write lock attributes object (no settable properties).
int pthread_cancel(pthread_t thread)
Request cancellation of a thread.
int pthread_barrierattr_init(pthread_barrierattr_t *attr)
Initialize a barrier attributes object (no settable properties).
int pthread_cond_destroy(pthread_cond_t *cond)
Destroy a condition variable, releasing the underlying STK object.
int pthread_timedjoin_np(pthread_t thread, void **retval, const struct timespec *abstime)
Join a thread, waiting until the absolute deadline abstime (GNU extension).
int pthread_setname_np(pthread_t thread, const char *name)
Set the name of a thread (shown by debug/trace tools), non-portable GNU-style.
int pthread_spin_init(pthread_spinlock_t *lock, int pshared)
Initialize a spinlock.
int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
Get the stored guard size (0 by default).
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
int pthread_setcanceltype(int type, int *oldtype)
Set the cancellation type. Only PTHREAD_CANCEL_DEFERRED is supported.
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
Try to acquire the read lock without blocking.
int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
Get the policy and priority (task weight) of a thread.
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
As pthread_cond_wait(), with an absolute deadline.
#define STK_C_PTHREAD_BARRIER_WORDS
uintptr_t pthread_stk_word_t
Native machine word used for stacks and opaque object storage (same as stk::Word).
int pthread_rwlock_clockrdlock(pthread_rwlock_t *rwlock, clockid_t clock_id, const struct timespec *abstime)
pthread_rwlock_timedrdlock() with an explicit clock. See pthread_mutex_clocklock() for clock_id.
int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
Destroy a barrier attributes object (no-op).
int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
Set the clock used by pthread_cond_timedwait() deadlines.
int pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
Get the contention scope (always PTHREAD_SCOPE_SYSTEM).
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, int *pshared)
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
Acquire the lock for shared reading. Blocks until available.
int pthread_spin_trylock(pthread_spinlock_t *lock)
Try to acquire the spinlock without blocking.
void * pthread_getspecific(pthread_key_t key)
Get the calling thread's value for key.
void stk_pthread_bind_kernel(void *kernel)
Bind the STK kernel instance that pthread_create() will add new threads to.
int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched)
Select whether a new thread inherits the priority of the creating thread.
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Initialize a condition variable.
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Acquire the read lock with an absolute deadline.
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
Get the stack size in bytes that threads created with attr will use.
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_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED.
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)
Set the mutex protocol.
int pthread_barrier_destroy(pthread_barrier_t *barrier)
Destroy a barrier, releasing the underlying STK barrier object.
int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
Get the previously-set external stack (stackaddr is NULL if none set).
int pthread_setconcurrency(int level)
Set the concurrency level hint. Accepted and ignored (STK always schedules kernel tasks).
int pthread_key_delete(pthread_key_t key)
Free a thread-specific data key.
int pthread_yield(void)
Voluntarily give up the CPU to another ready task (cooperative yield), then resume once rescheduled.
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
Get the scheduling policy stored in attr.
void pthread_testcancel(void)
Create a cancellation point: terminate the calling thread if a cancellation is pending and enabled.
int pthread_key_create(pthread_key_t *key, void(*destructor)(void *))
Allocate a new thread-specific data key.
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, int *pshared)
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize a mutex attributes object with default values (PTHREAD_MUTEX_DEFAULT).
int pthread_getconcurrency(void)
Get the concurrency level hint.
void pthread_cleanup_pop(int execute)
Pop the most recent cleanup handler, running it if execute is non-zero.
int pthread_cond_broadcast(pthread_cond_t *cond)
Wake all threads waiting on cond (no effect if none is waiting).
int pthread_attr_getname_np(const pthread_attr_t *attr, char *name, size_t len)
Get the name stored in attr.
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
Get the scheduling priority stored in attr.
int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared)
Scheduling parameters.
Definition sched.h:67
pthread_stk_word_t data[(10U+((0) ? 1U :0U))]
pthread_stk_word_t data[(7U+((0) ? 1U :0U))]
pthread_stk_word_t data[(17U+((0) ? 3U :0U))]
pthread_stk_word_t data[((10U+((0) ? 1U :0U))+(7U+((0) ? 1U :0U))+4U+((0) ? 1U :0U))]
Thread creation attributes.
int __scope
Always PTHREAD_SCOPE_SYSTEM.
size_t __stack_bytes
0 = use STK_C_PTHREAD_DEFAULT_STACK_WORDS.
int __detachstate
PTHREAD_CREATE_JOINABLE / _DETACHED.
int __policy
SCHED_OTHER (default) / SCHED_FIFO / SCHED_RR (informational).
pthread_stk_word_t * __ext_stack
Caller-supplied stack, or NULL.
char __name[(16U)]
Thread name, "" = default ("pthread").
int __inheritsched
PTHREAD_EXPLICIT_SCHED (default) / PTHREAD_INHERIT_SCHED.
int __privileged
PTHREAD_CREATE_USER_NP (default) / _PRIVILEGED_NP.
size_t __guardsize
Stored for pthread_attr_getguardsize(), has no effect.
int __priority
Task weight (sched_priority), used if __inheritsched is PTHREAD_EXPLICIT_SCHED.
Mutex attributes.
int __type
PTHREAD_MUTEX_NORMAL / DEFAULT / RECURSIVE / ERRORCHECK.
int __protocol
PTHREAD_PRIO_NONE (default) / PTHREAD_PRIO_INHERIT.
A pthread mutex.
pthread_stk_mutex_mem_t __mem
In-place storage for the STK mutex object.
int __type
PTHREAD_MUTEX_* type; 0 (NORMAL) when statically initialized.
void * __handle
Object constructed in __mem, or NULL if not yet constructed.
Condition variable attributes (currently no settable properties).
int __clock
CLOCK_REALTIME (default) / CLOCK_MONOTONIC: both are the same STK tick timeline.
A pthread condition variable.
pthread_stk_cv_mem_t __mem
In-place storage for the STK condition variable object.
void * __handle
Object constructed in __mem, or NULL if not yet constructed.
Read-write lock attributes (currently no settable properties).
int __reserved
Unused (no settable properties); reserved for future use.
A pthread read-write lock.
volatile bool __wrlocked
True while held for writing; selects Unlock() vs ReadUnlock() on release.
void * __handle
Object constructed in __mem, or NULL if not yet constructed.
pthread_stk_rwmutex_mem_t __mem
In-place storage for the STK rwmutex object.
A pthread spinlock.
pthread_stk_word_t data[1]
Storage for the non-recursive fast hw::SpinLock.
struct pthread_spinlock_t::@001015320316047075072233215330060151327030003304 __mem
In-place storage for the STK spinlock object.
void * __handle
Object constructed in __mem, or NULL if not yet constructed.
Barrier attributes (currently no settable properties).
int __reserved
Unused (no settable properties); reserved for future use.
A pthread barrier.
void * __handle
Object constructed in __mem, or NULL if not yet constructed.
pthread_stk_barrier_mem_t __mem
In-place storage for the STK barrier object.
A pthread_once() control object.
void * __handle
Guard mutex constructed in __mem, or NULL if not yet constructed.
pthread_stk_mutex_mem_t __mem
In-place storage for the guard mutex.
int __state
0 = not started, 1 = running, 2 = done.