Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
pthread.h
Go to the documentation of this file.
1 
4 #ifndef __PTHREAD_H__
5 #define __PTHREAD_H__
6 
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <sys/sched.h>
10 #include <time.h>
11 
12 #include <common/list.h>
13 
14 #define PTHREAD_ONCE_INIT \
15  { \
16  .wq = {.next = NULL, .prev = NULL}, .finished = false \
17  }
18 
19 #define PTHREAD_CREATE_DETACHED 0
20 #define PTHREAD_CREATE_JOINABLE 1
21 
22 #define PTHREAD_PRIO_NONE 0
23 #define PTHREAD_PRIO_INHERIT 1
24 
25 #define __SIZEOF_PTHREAD_MUTEXATTR_T 4 /* sizeof(struct mutex_attr) */
26 #define __SIZEOF_PTHREAD_MUTEX_T 16 /* sizeof(struct mutex) */
27 #define __SIZEOF_PTHREAD_ATTR_T 20 /* sizeof(struct thread_attr) */
28 #define __SIZEOF_PTHREAD_COND_T 8 /* sizeof(struct cond) */
29 #define __SIZEOF_PTHREAD_ONCE_T 12 /* sizeof(struct thread_once) */
30 
31 typedef uint32_t pthread_t;
32 typedef uint32_t pthread_condattr_t;
33 
34 typedef union {
35  char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
36  uint32_t __align;
38 
39 typedef union {
40  char __size[__SIZEOF_PTHREAD_MUTEX_T];
41  uint32_t __align;
43 
44 typedef union {
45  char __size[__SIZEOF_PTHREAD_ATTR_T];
46  uint32_t __align;
48 
49 typedef union {
50  char __size[__SIZEOF_PTHREAD_COND_T];
51  uint32_t __align;
53 
54 typedef union {
55  char __size[__SIZEOF_PTHREAD_ONCE_T];
56  uint32_t __align;
58 
65 
72 
80  const struct sched_param *param);
81 
89  struct sched_param *param);
90 
97 int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
98 
105 int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
106 
113 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);
114 
123  int *protocol);
124 
131 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
132 
139 int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
140 
147 int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
148 
156 int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
157 
164 int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
165 
173 int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr);
174 
184 int pthread_create(pthread_t *thread,
185  const pthread_attr_t *attr,
186  void *(*start_routine)(void *),
187  void *arg);
188 
194 pthread_t pthread_self(void);
195 
202 int pthread_join(pthread_t thread, void **retval);
203 
212 int pthread_detach(pthread_t thread);
213 
219 int pthread_cancel(pthread_t thread);
220 
228 int pthread_equal(pthread_t t1, pthread_t t2);
229 
238 int pthread_setschedparam(pthread_t thread,
239  int policy,
240  const struct sched_param *param);
241 
250 int pthread_getschedparam(pthread_t thread,
251  int *policy,
252  struct sched_param *param);
253 
259 int pthread_yield(void);
260 
267 int pthread_kill(pthread_t thread, int sig);
268 
274 void pthread_exit(void *retval);
275 
282 
289 
290 
298 
305 
312 
319 
328 
336  const struct timespec *abstime);
337 
345 int pthread_condattr_init(pthread_condattr_t *attr);
346 
352 int pthread_condattr_destroy(pthread_condattr_t *attr);
353 
361 int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t cond_attr);
362 
369 
376 
383 
391 
401  const struct timespec *abstime);
402 
410 int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
411 
412 #endif
int pthread_condattr_destroy(pthread_condattr_t *attr)
Destroy the attribute object of the conditional variable.
Definition: pthread.c:393
int pthread_attr_init(pthread_attr_t *attr)
Initialize a thread attribute object with default values.
Definition: pthread.c:13
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock the mutex.
Definition: pthread.c:357
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
Set the scheduling parameters of a thread specified with the thread ID.
Definition: pthread.c:251
int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
To ensure a piece of initialization code is executed at most once.
Definition: pthread.c:471
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol)
Get priority inheritance protocol of a mutex attriute object.
Definition: pthread.c:95
int pthread_cond_signal(pthread_cond_t *cond)
Restart one of the threads that are waiting on the condition variable.
Definition: pthread.c:425
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
Destroy the mutex attribute object.
Definition: pthread.c:283
void pthread_exit(void *retval)
Terminate the calling thread and returns a value via retval.
Definition: pthread.c:337
int pthread_mutex_trylock(pthread_mutex_t *mutex)
Lock the mutex. If the mutex object referenced by mutex is currently locked (by any thread,...
Definition: pthread.c:367
int pthread_join(pthread_t thread, void **retval)
Wait for a thread specified with the thread ID to terminate.
Definition: pthread.c:214
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
Set stack address parameter of a thread attriute object.
Definition: pthread.c:157
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t cond_attr)
Initializes the conditional variable with specified attributes.
Definition: pthread.c:402
int pthread_condattr_init(pthread_condattr_t *attr)
Initialize the attribute object of conditional variable with default values.
Definition: pthread.c:383
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
Get detach state parameter of a thread attriute object.
Definition: pthread.c:146
int pthread_mutex_destroy(pthread_mutex_t *mutex)
Destroy the mutex.
Definition: pthread.c:308
int pthread_attr_destroy(pthread_attr_t *attr)
Destroy the given thread attribute object.
Definition: pthread.c:27
pthread_t pthread_self(void)
Return the thread ID of the calling thread.
Definition: pthread.c:204
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
Set scheduling parameter of a thread attriute object.
Definition: pthread.c:38
int pthread_kill(pthread_t thread, int sig)
Send a signal to a thread specified with the thread ID.
Definition: pthread.c:332
int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
Lock the mutex with absolute timeout.
Definition: pthread.c:378
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize the mutex with specified attributes.
Definition: pthread.c:292
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
Set scheduling policy of a thread attriute object.
Definition: pthread.c:62
int pthread_detach(pthread_t thread)
Mark the thread identified by thread as detached. When a detached thread terminates,...
Definition: pthread.c:224
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
Set stack size parameter of a thread attriute object.
Definition: pthread.c:107
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Atomically unlock the mutex and wait for the condition variable to be signaled.
Definition: pthread.c:446
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Unlock the mutex.
Definition: pthread.c:347
int pthread_equal(pthread_t t1, pthread_t t2)
Compare thread IDs.
Definition: pthread.c:239
int pthread_cancel(pthread_t thread)
Send a cancellation request to a thread specified with the thread ID.
Definition: pthread.c:234
int pthread_cond_destroy(pthread_cond_t *cond)
Destroy the conditional variable.
Definition: pthread.c:411
int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
Get the scheduling parameters of a thread specified with the thread ID.
Definition: pthread.c:265
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime)
Wait on condition variable with absolute timeout.
Definition: pthread.c:458
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
Get stack address parameter of a thread attriute object.
Definition: pthread.c:171
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
Get stack size parameter of a thread attriute object.
Definition: pthread.c:118
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Start a new thread in the calling task.
Definition: pthread.c:196
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set detach state parameter of a thread attriute object.
Definition: pthread.c:129
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)
Set priority inheritance protocol of a mutex attriute object.
Definition: pthread.c:84
int pthread_yield(void)
To cause the calling thread to relinquish the CPU.
Definition: pthread.c:322
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
Get scheduling parameter of a thread attriute object.
Definition: pthread.c:73
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize the mutex attribute object with default values.
Definition: pthread.c:272
int pthread_cond_broadcast(pthread_cond_t *cond)
Restart all of the threads that are waiting on the condition variable.
Definition: pthread.c:435
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
Get scheduling parameter of a thread attriute object.
Definition: pthread.c:50
Definition: mutex.h:21
Definition: mutex.h:15
Definition: sched.h:12
Definition: time.h:16
Definition: pthread.h:44
Definition: pthread.h:49
Definition: pthread.h:39
Definition: pthread.h:34
Definition: pthread.h:54