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 
11 #include <common/list.h>
12 
13 #define PTHREAD_ONCE_INIT \
14  { \
15  .wq = {.next = NULL, .prev = NULL}, .finished = false \
16  }
17 
18 #define PTHREAD_CREATE_DETACHED 0
19 #define PTHREAD_CREATE_JOINABLE 1
20 
21 #define PTHREAD_PRIO_NONE 0
22 #define PTHREAD_PRIO_INHERIT 1
23 
24 #define __SIZEOF_PTHREAD_MUTEXATTR_T 4 /* sizeof(struct mutex_attr) */
25 #define __SIZEOF_PTHREAD_MUTEX_T 16 /* sizeof(struct mutex) */
26 #define __SIZEOF_PTHREAD_ATTR_T 20 /* sizeof(struct thread_attr) */
27 #define __SIZEOF_PTHREAD_COND_T 8 /* sizeof(struct cond) */
28 #define __SIZEOF_PTHREAD_ONCE_T 12 /* sizeof(struct thread_once) */
29 
30 typedef uint32_t pthread_t;
31 typedef uint32_t pthread_condattr_t;
32 
33 typedef union {
34  char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
35  uint32_t __align;
37 
38 typedef union {
39  char __size[__SIZEOF_PTHREAD_MUTEX_T];
40  uint32_t __align;
42 
43 typedef union {
44  char __size[__SIZEOF_PTHREAD_ATTR_T];
45  uint32_t __align;
47 
48 typedef union {
49  char __size[__SIZEOF_PTHREAD_COND_T];
50  uint32_t __align;
52 
53 typedef union {
54  char __size[__SIZEOF_PTHREAD_ONCE_T];
55  uint32_t __align;
57 
64 
71 
79  const struct sched_param *param);
80 
88  struct sched_param *param);
89 
96 int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
97 
104 int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
105 
112 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);
113 
122  int *protocol);
123 
130 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
131 
138 int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
139 
146 int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
147 
155 int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
156 
163 int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
164 
172 int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr);
173 
183 int pthread_create(pthread_t *thread,
184  const pthread_attr_t *attr,
185  void *(*start_routine)(void *),
186  void *arg);
187 
193 pthread_t pthread_self(void);
194 
201 int pthread_join(pthread_t thread, void **retval);
202 
211 int pthread_detach(pthread_t thread);
212 
218 int pthread_cancel(pthread_t thread);
219 
227 int pthread_equal(pthread_t t1, pthread_t t2);
228 
237 int pthread_setschedparam(pthread_t thread,
238  int policy,
239  const struct sched_param *param);
240 
249 int pthread_getschedparam(pthread_t thread,
250  int *policy,
251  struct sched_param *param);
252 
258 int pthread_yield(void);
259 
266 int pthread_kill(pthread_t thread, int sig);
267 
273 void pthread_exit(void *retval);
274 
281 
288 
289 
297 
304 
311 
318 
327 
335 int pthread_condattr_init(pthread_condattr_t *attr);
336 
342 int pthread_condattr_destroy(pthread_condattr_t *attr);
343 
351 int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t cond_attr);
352 
359 
366 
373 
381 
389 int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
390 
391 #endif
int pthread_condattr_destroy(pthread_condattr_t *attr)
Destroy the attribute object of the conditional variable.
Definition: pthread.c:313
int pthread_attr_init(pthread_attr_t *attr)
Initialize a thread attribute object with default values.
Definition: pthread.c:12
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock the mutex.
Definition: pthread.c:293
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:214
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:355
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol)
Get priority inheritance protocol of a mutex attriute object.
Definition: pthread.c:94
int pthread_cond_signal(pthread_cond_t *cond)
Restart one of the threads that are waiting on the condition variable.
Definition: pthread.c:340
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
Destroy the mutex attribute object.
Definition: pthread.c:239
void pthread_exit(void *retval)
Terminate the calling thread and returns a value via retval.
Definition: pthread.c:283
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:298
int pthread_join(pthread_t thread, void **retval)
Wait for a thread specified with the thread ID to terminate.
Definition: pthread.c:194
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
Set stack address parameter of a thread attriute object.
Definition: pthread.c:156
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t cond_attr)
Initializes the conditional variable with specified attributes.
Definition: pthread.c:322
int pthread_condattr_init(pthread_condattr_t *attr)
Initialize the attribute object of conditional variable with default values.
Definition: pthread.c:303
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
Get detach state parameter of a thread attriute object.
Definition: pthread.c:145
int pthread_mutex_destroy(pthread_mutex_t *mutex)
Destroy the mutex.
Definition: pthread.c:264
int pthread_attr_destroy(pthread_attr_t *attr)
Destroy the given thread attribute object.
Definition: pthread.c:26
pthread_t pthread_self(void)
Return the thread ID of the calling thread.
Definition: pthread.c:189
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
Set scheduling parameter of a thread attriute object.
Definition: pthread.c:37
int pthread_kill(pthread_t thread, int sig)
Send a signal to a thread specified with the thread ID.
Definition: pthread.c:278
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize the mutex with specified attributes.
Definition: pthread.c:248
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
Set scheduling policy of a thread attriute object.
Definition: pthread.c:61
int pthread_detach(pthread_t thread)
Mark the thread identified by thread as detached. When a detached thread terminates,...
Definition: pthread.c:199
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
Set stack size parameter of a thread attriute object.
Definition: pthread.c:106
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:350
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Unlock the mutex.
Definition: pthread.c:288
int pthread_equal(pthread_t t1, pthread_t t2)
Compare thread IDs.
Definition: pthread.c:209
int pthread_cancel(pthread_t thread)
Send a cancellation request to a thread specified with the thread ID.
Definition: pthread.c:204
int pthread_cond_destroy(pthread_cond_t *cond)
Destroy the conditional variable.
Definition: pthread.c:331
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:221
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
Get stack address parameter of a thread attriute object.
Definition: pthread.c:170
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
Get stack size parameter of a thread attriute object.
Definition: pthread.c:117
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:181
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set detach state parameter of a thread attriute object.
Definition: pthread.c:128
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol)
Set priority inheritance protocol of a mutex attriute object.
Definition: pthread.c:83
int pthread_yield(void)
To cause the calling thread to relinquish the CPU.
Definition: pthread.c:273
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
Get scheduling parameter of a thread attriute object.
Definition: pthread.c:72
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize the mutex attribute object with default values.
Definition: pthread.c:228
int pthread_cond_broadcast(pthread_cond_t *cond)
Restart all of the threads that are waiting on the condition variable.
Definition: pthread.c:345
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
Get scheduling parameter of a thread attriute object.
Definition: pthread.c:49
Definition: mutex.h:21
Definition: mutex.h:15
Definition: sched.h:12
Definition: pthread.h:43
Definition: pthread.h:48
Definition: pthread.h:38
Definition: pthread.h:33
Definition: pthread.h:53