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
pthread_compile_check.c File Reference
#include <pthread.h>
#include <errno.h>
#include <time.h>
Include dependency graph for pthread_compile_check.c:

Go to the source code of this file.

Functions

static void InitOnce (void)
static void KeyDestructor (void *value)
static void * ThreadEntry (void *arg)
int stk_pthread_compile_check (void)

Variables

static pthread_mutex_t g_Mutex = {0}
static pthread_cond_t g_Cond = {0}
static pthread_rwlock_t g_RwLock = {0}
static pthread_once_t g_Once = {0}
static pthread_key_t g_Key
static pthread_spinlock_t g_Spin
static pthread_barrier_t g_Barrier

Function Documentation

◆ InitOnce()

void InitOnce ( void )
static

Definition at line 47 of file pthread_compile_check.c.

48{
49}

Referenced by stk_pthread_compile_check().

Here is the caller graph for this function:

◆ KeyDestructor()

void KeyDestructor ( void * value)
static

Definition at line 51 of file pthread_compile_check.c.

52{
53 (void)value;
54}

Referenced by stk_pthread_compile_check().

Here is the caller graph for this function:

◆ stk_pthread_compile_check()

int stk_pthread_compile_check ( void )

Definition at line 61 of file pthread_compile_check.c.

62{
63 int rc = 0;
64
65 pthread_t thread;
66 pthread_attr_t attr;
68 struct timespec abstime;
69 void *retval = NULL;
70 int mode = 0;
71
72 abstime.tv_sec = 0;
73 abstime.tv_nsec = 0;
74
75 /* thread attributes and lifecycle */
76 rc |= pthread_attr_init(&attr);
80 rc |= pthread_attr_getprivileged_np(&attr, &mode);
81 rc |= pthread_create(&thread, &attr, ThreadEntry, NULL);
82 rc |= pthread_join(thread, &retval);
83 rc |= pthread_detach(thread);
84 rc |= pthread_equal(pthread_self(), thread);
85 rc |= pthread_yield();
86 rc |= pthread_attr_destroy(&attr);
87
88 /* mutex */
89 rc |= pthread_mutexattr_init(&mattr);
92 rc |= pthread_mutex_init(&g_Mutex, &mattr);
95 rc |= pthread_mutex_timedlock(&g_Mutex, &abstime);
98 rc |= pthread_mutexattr_destroy(&mattr);
99
100 /* condition variable */
101 rc |= pthread_cond_init(&g_Cond, NULL);
103 rc |= pthread_cond_timedwait(&g_Cond, &g_Mutex, &abstime);
107
108 /* read-write lock */
109 rc |= pthread_rwlock_init(&g_RwLock, NULL);
112 rc |= pthread_rwlock_timedrdlock(&g_RwLock, &abstime);
115 rc |= pthread_rwlock_timedwrlock(&g_RwLock, &abstime);
118
119 /* spinlock */
125
126 /* barrier */
127 rc |= pthread_barrier_init(&g_Barrier, NULL, 2U);
130
131 /* once and thread-specific data */
134 rc |= pthread_setspecific(g_Key, &rc);
135 rc |= (pthread_getspecific(g_Key) != NULL);
137 rc |= (int)PTHREAD_KEYS_MAX;
138
139 /* errno values the shim returns must come from <errno.h> */
140 rc |= (EINVAL | EBUSY | EAGAIN | EDEADLK | EPERM | ETIMEDOUT | ENOTSUP | ENOMEM);
141
142 pthread_exit(NULL);
143
144 return rc;
145}
static pthread_mutex_t g_Mutex
static void InitOnce(void)
static pthread_once_t g_Once
static pthread_spinlock_t g_Spin
static pthread_barrier_t g_Barrier
static void * ThreadEntry(void *arg)
static void KeyDestructor(void *value)
static pthread_rwlock_t g_RwLock
static pthread_cond_t g_Cond
static pthread_key_t g_Key
uintptr_t stk_word_t
CPU register type.
Definition stk_c.h:99
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
Try to acquire the write lock without blocking.
#define PTHREAD_KEYS_MAX
POSIX-standard name for STK_C_PTHREAD_KEYS_MAX (this file).
int pthread_attr_init(pthread_attr_t *attr)
Initialize a thread attributes object with default values (default stack size, no external stack,...
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock a mutex, blocking until it becomes available.
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
Initialize a read-write lock.
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Acquire the write lock with an absolute deadline.
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_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_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.
#define STK_C_PTHREAD_DEFAULT_STACK_WORDS
Default per-thread stack size in stk_word_t units, used when pthread_attr_t does not specify a stack ...
#define PTHREAD_PROCESS_PRIVATE
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_spin_lock(pthread_spinlock_t *lock)
Acquire the spinlock, spinning until available.
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.
#define PTHREAD_MUTEX_RECURSIVE
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize a mutex.
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
Destroy a read-write lock, releasing the underlying STK object.
int pthread_detach(pthread_t thread)
Mark a thread as detached.
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.
struct pthread_stk_ctrl_t * pthread_t
Opaque thread handle.
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
Set the requested stack size in bytes.
#define PTHREAD_BARRIER_SERIAL_THREAD
Returned by pthread_barrier_wait() to exactly one arbitrary caller per round; all others receive 0....
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.
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_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_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_cond_destroy(pthread_cond_t *cond)
Destroy a condition variable, releasing the underlying STK object.
int pthread_spin_init(pthread_spinlock_t *lock, int pshared)
Initialize a spinlock.
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
Try to acquire the read lock without blocking.
#define PTHREAD_MUTEX_ERRORCHECK
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_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.
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_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Create and start a new thread.
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED.
int pthread_barrier_destroy(pthread_barrier_t *barrier)
Destroy a barrier, releasing the underlying STK barrier object.
#define PTHREAD_CREATE_USER_NP
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_key_create(pthread_key_t *key, void(*destructor)(void *))
Allocate a new thread-specific data key.
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize a mutex attributes object with default values (PTHREAD_MUTEX_DEFAULT).
#define PTHREAD_CREATE_JOINABLE
int pthread_cond_broadcast(pthread_cond_t *cond)
Wake all threads waiting on cond (no effect if none is waiting).
Thread creation attributes.
Mutex attributes.

References g_Barrier, g_Cond, g_Key, g_Mutex, g_Once, g_RwLock, g_Spin, InitOnce(), KeyDestructor(), pthread_attr_destroy(), pthread_attr_getprivileged_np(), pthread_attr_init(), pthread_attr_setdetachstate(), pthread_attr_setprivileged_np(), pthread_attr_setstacksize(), pthread_barrier_destroy(), pthread_barrier_init(), PTHREAD_BARRIER_SERIAL_THREAD, pthread_barrier_wait(), pthread_cond_broadcast(), pthread_cond_destroy(), pthread_cond_init(), pthread_cond_signal(), pthread_cond_timedwait(), pthread_cond_wait(), pthread_create(), PTHREAD_CREATE_JOINABLE, PTHREAD_CREATE_USER_NP, pthread_detach(), pthread_equal(), pthread_exit(), pthread_getspecific(), pthread_join(), pthread_key_create(), pthread_key_delete(), PTHREAD_KEYS_MAX, pthread_mutex_destroy(), PTHREAD_MUTEX_ERRORCHECK, pthread_mutex_init(), pthread_mutex_lock(), PTHREAD_MUTEX_RECURSIVE, pthread_mutex_timedlock(), pthread_mutex_trylock(), pthread_mutex_unlock(), pthread_mutexattr_destroy(), pthread_mutexattr_init(), pthread_mutexattr_settype(), pthread_once(), PTHREAD_PROCESS_PRIVATE, pthread_rwlock_destroy(), pthread_rwlock_init(), pthread_rwlock_rdlock(), pthread_rwlock_timedrdlock(), pthread_rwlock_timedwrlock(), pthread_rwlock_tryrdlock(), pthread_rwlock_trywrlock(), pthread_rwlock_unlock(), pthread_rwlock_wrlock(), pthread_self(), pthread_setspecific(), pthread_spin_destroy(), pthread_spin_init(), pthread_spin_lock(), pthread_spin_trylock(), pthread_spin_unlock(), pthread_yield(), STK_C_PTHREAD_DEFAULT_STACK_WORDS, and ThreadEntry().

Here is the call graph for this function:

◆ ThreadEntry()

void * ThreadEntry ( void * arg)
static

Definition at line 56 of file pthread_compile_check.c.

57{
58 return arg;
59}

Referenced by stk_pthread_compile_check().

Here is the caller graph for this function:

Variable Documentation

◆ g_Barrier

pthread_barrier_t g_Barrier
static

Definition at line 45 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().

◆ g_Cond

pthread_cond_t g_Cond = {0}
static

Definition at line 40 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().

◆ g_Key

pthread_key_t g_Key
static

Definition at line 43 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().

◆ g_Mutex

pthread_mutex_t g_Mutex = {0}
static

Definition at line 39 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().

◆ g_Once

pthread_once_t g_Once = {0}
static

Definition at line 42 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().

◆ g_RwLock

pthread_rwlock_t g_RwLock = {0}
static

Definition at line 41 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().

◆ g_Spin

pthread_spinlock_t g_Spin
static

Definition at line 44 of file pthread_compile_check.c.

Referenced by stk_pthread_compile_check().