| Samsung Internal API reference 2.0

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

pthread.h
Go to the documentation of this file.
1
9 #ifndef __PTHREAD_H__
10 #define __PTHREAD_H__
11
12 #include <atomic.h>
13 #include <compiler.h>
14 #include <core/page.h>
15 #include <dso_defs.h>
16 #include <stddef.h>
17 #include <stdint.h>
18 #include <time.h>
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /* uncomment line below for more debug output (and panics) */
25 /* #define PTHREAD_DEBUG 1 */
26
29 #define PTHREAD_STACK_MIN (PAGE_SIZE)
30
33 #define PTHREAD_GUARD_MIN (PAGE_SIZE)
34
37 #define PTHREAD_GUARD_MAX (PAGE_SIZE << 2)
38
41 #define MUTEX_STATE_UNLOCKED 0
42
44 #define MUTEX_STATE_LOCKED 1
45
48 #define PTHREAD_MUTEX_INITIALIZER \
49 { { MUTEX_STATE_UNLOCKED }, PTHREAD_MUTEX_DEFAULT, 0, 0 }
50
53 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
54 { { MUTEX_STATE_UNLOCKED }, PTHREAD_MUTEX_ERRORCHECK, 0, 0 }
55
58 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
59 { { MUTEX_STATE_UNLOCKED }, PTHREAD_MUTEX_RECURSIVE, 0, 0 }
60
62 typedef struct pthread_impl pthread_impl_t;
63
66 typedef uintptr_t pthread_t;
67
70 typedef uint32_t pthread_mutexattr_t;
71
73 enum {
74 PTHREAD_MUTEX_NORMAL = 0,
75 PTHREAD_MUTEX_RECURSIVE,
76 PTHREAD_MUTEX_ERRORCHECK,
77 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL,
78 PTHREAD_MUTEX_DESTROYED = -1,
81 PTHREAD_MUTEX_ERRORCHECK_NP = PTHREAD_MUTEX_ERRORCHECK,
83 PTHREAD_MUTEX_RECURSIVE_NP = PTHREAD_MUTEX_RECURSIVE,
85 };
86
90 struct __pthread_once_t {
91 atomic_t already_executed;
92 };
93
96 #define PTHREAD_ONCE_INIT { ATOMIC_INITIALIZER }
97
100 struct __pthread_attr_t {
101 void *stackaddr;
102 unsigned int stacksize;
103 unsigned int guardsize;
104 unsigned int flags;
105 };
106
108 enum
109 {
110 PTHREAD_CREATE_JOINABLE,
111 PTHREAD_CREATE_DETACHED,
112 };
113
116 struct __pthread_mutex_t {
117 atomic_t state;
118 unsigned attr;
119 unsigned count;
120 pthread_t caller_thread;
121 };
122
125 typedef struct __pthread_mutex_t pthread_mutex_t;
126
130 struct __pthread_cond_t {
131 atomic_t status;
132 };
133
136 struct __pthread_condattr_t {
137 /* Not implemented. */
138 };
139
143 #define PTHREAD_COND_INITIALIZER { ATOMIC_INITIALIZER }
144
147 typedef unsigned pthread_key_t;
150 typedef struct __pthread_attr_t pthread_attr_t;
153 typedef struct __pthread_once_t pthread_once_t;
156 typedef struct __pthread_cond_t pthread_cond_t;
159 typedef struct __pthread_cond_t pthread_condattr_t;
160
167 DSO_EXPORT int pthread_attr_init(pthread_attr_t *attr);
168
175 DSO_EXPORT int pthread_attr_destroy(pthread_attr_t *attr);
176
183 DSO_EXPORT int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
184
191 DSO_EXPORT int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize);
192
200 DSO_EXPORT int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
201
209 DSO_EXPORT int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
210
217 DSO_EXPORT int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr);
218
225 DSO_EXPORT int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
226
227
235 DSO_EXPORT int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize);
236
244 DSO_EXPORT int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);
245
246
282 DSO_EXPORT int
283 pthread_create(pthread_t *thread,
284 const pthread_attr_t *attr,
285 void *(*start_routine) (void *),
286 void *arg);
287
292 DSO_EXPORT _noreturn_ void pthread_exit(void *retval);
293
327 DSO_EXPORT int pthread_join(pthread_t thread, void **retval);
328
366 DSO_EXPORT int
367 pthread_once(pthread_once_t *once_control,
368 void (*init_routine)(void));
369
417 DSO_EXPORT void *pthread_getspecific(pthread_key_t key);
418
469 DSO_EXPORT int pthread_setspecific(pthread_key_t key, const void *value);
470
523 DSO_EXPORT int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
524
574 DSO_EXPORT int pthread_key_delete(pthread_key_t key);
575
604 DSO_EXPORT int pthread_mutexattr_init(pthread_mutexattr_t *attr);
605
634 DSO_EXPORT int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
635
654 DSO_EXPORT int
655 pthread_mutexattr_gettype(const pthread_mutexattr_t *attr,
656 int *type);
657
682 DSO_EXPORT int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
683
707 DSO_EXPORT int pthread_mutex_lock(pthread_mutex_t *mutex);
708
733 DSO_EXPORT int pthread_mutex_trylock(pthread_mutex_t *mutex);
734
755 DSO_EXPORT int pthread_mutex_unlock(pthread_mutex_t *mutex);
756
782 DSO_EXPORT int pthread_mutex_destroy(pthread_mutex_t *mutex);
783
815 DSO_EXPORT int
816 pthread_mutex_init(pthread_mutex_t *mutex,
817 const pthread_mutexattr_t *attr);
818
852 DSO_EXPORT int pthread_cond_destroy(pthread_cond_t *cond);
853
860 DSO_EXPORT int pthread_condattr_init(pthread_condattr_t *attr);
861
868 DSO_EXPORT int pthread_condattr_destroy(pthread_condattr_t *attr);
869
890 DSO_EXPORT int
891 pthread_cond_init(pthread_cond_t *cond,
892 const pthread_condattr_t *attr);
893
925 DSO_EXPORT int pthread_cond_signal(pthread_cond_t *cond);
926
956 DSO_EXPORT int pthread_cond_broadcast(pthread_cond_t *cond);
957
992 DSO_EXPORT int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
993
1032 DSO_EXPORT int pthread_cond_timedwait(pthread_cond_t *cond,
1033 pthread_mutex_t *mutex,
1034 const struct timespec *timeout);
1035
1047 DSO_EXPORT pthread_t pthread_self(void);
1048
1065 DSO_EXPORT int pthread_kill(pthread_t thread, int sig);
1066
1081 DSO_EXPORT int pthread_equal(pthread_t t1, pthread_t t2);
1082
1090 DSO_EXPORT int pthread_detach(pthread_t thread);
1091
1099 DSO_EXPORT int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
1100
1107 DSO_EXPORT int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
1108
1115 DSO_EXPORT int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr);
1116
1136 #define pthread_sigmask(how, set, oldset) sigprocmask(how, set, oldset)
1137
1138 #ifdef __cplusplus
1139 }
1140 #endif
1141
1142 #endif /* __PTHREAD_H__ */
1143
pthread_attr_setdetachstate
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set the detach state attribute.
pthread_cond_signal
int pthread_cond_signal(pthread_cond_t *cond)
Unblock at least one of the threads that are blocked on the specified condition variable cond (if any...
pthread_mutex_unlock
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Release lock on currently locked mutex.
pthread_detach
int pthread_detach(pthread_t thread)
Detach a thread.
pthread_self
pthread_t pthread_self(void)
Obtain ID of the calling thread.
pthread_t
uintptr_t pthread_t
Definition: pthread.h:66
time.h
Time header.
__pthread_condattr_t
Definition: pthread.h:136
pthread_attr_setstacksize
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
The pthread_attr_setstacksize() function sets size of stack.
pthread_impl_t
struct pthread_impl pthread_impl_t
Definition: pthread.h:62
pthread_cond_broadcast
int pthread_cond_broadcast(pthread_cond_t *cond)
Wake up all threads locked by conditional variable cond.
pthread_attr_setstack
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize)
The pthread_attr_setstack() function sets stack address and size.
__pthread_cond_t
Definition: pthread.h:130
pthread_mutexattr_t
uint32_t pthread_mutexattr_t
Definition: pthread.h:70
pthread_once
int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
If any thread in a process with a once_control parameter makes a call to pthread_once(), the first call will summon the init_routine(), but subsequent calls will not. The once_control parameter determines whether the associated initialization routine has been called. The init_routine() is complete upon return of pthread_once().
pthread_kill
int pthread_kill(pthread_t thread, int sig)
Send signal to specified thread.
pthread_key_delete
int pthread_key_delete(pthread_key_t key)
Delete data key and destructor associated with key. After key deletion there is no destructor will be...
pthread_getspecific
void * pthread_getspecific(pthread_key_t key)
Return the value currently bound to the specified key on behalf of the calling thread.
pthread_attr_getstack
int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
The pthread_attr_getstack() function gets stack address and size.
PTHREAD_MUTEX_RECURSIVE_NP
Definition: pthread.h:83
pthread_mutex_trylock
int pthread_mutex_trylock(pthread_mutex_t *mutex)
Lock mutex or fail if mutex is already locked.
pthread_attr_init
int pthread_attr_init(pthread_attr_t *attr)
The pthread_attr_init() function initialize attribute struct.
pthread_attr_getdetachstate
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
Get the detach state attribute.
pthread_condattr_destroy
int pthread_condattr_destroy(pthread_condattr_t *attr)
Destroy conditional variable attributes.
__pthread_once_t
Definition: pthread.h:90
PTHREAD_MUTEX_RECURSIVE
Definition: pthread.h:75
__pthread_attr_t
Definition: pthread.h:100
pthread_mutex_init
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize mutex object mutex with attributes given by attr parameter. If attr parameter is NULL then...
pthread_attr_getguardsize
int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
The pthread_attr_getguardsize() function gets size of guard.
PTHREAD_MUTEX_DEFAULT
Definition: pthread.h:77
pthread_mutexattr_destroy
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
Destroy attributes object and make all attribute values are uninitialized.
pthread_mutex_destroy
int pthread_mutex_destroy(pthread_mutex_t *mutex)
Destroy mutex object and make all associated data are uninitialized.
pthread_attr_destroy
int pthread_attr_destroy(pthread_attr_t *attr)
The pthread_attr_destroy() function destroy attribute struct.
pthread_equal
int pthread_equal(pthread_t t1, pthread_t t2)
Compare thread IDs.
pthread_create
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
The pthread_create() function starts a new thread in the calling process. The new thread starts execu...
pthread_attr_setguardsize
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
The pthread_attr_setguardsize() function sets size of guard.
pthread_exit
_noreturn_ void pthread_exit(void *retval)
Terminate calling thread.
pthread_getattr_np
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
Get attributes of created thread.
PTHREAD_CREATE_DETACHED
Definition: pthread.h:111
pthread_attr_setstackaddr
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
The pthread_attr_setstackaddr() function gets stack address.
PTHREAD_MUTEX_NORMAL
Definition: pthread.h:74
pthread_setspecific
int pthread_setspecific(pthread_key_t key, const void *value)
Associate a thread-specific value with a key obtained via a previous call to pthread_key_create().
pthread_mutexattr_init
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize mutex attributes object and initialize attributes with default values. ...
PTHREAD_MUTEX_ERRORCHECK_NP
Definition: pthread.h:81
pthread_cond_init
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Initialize conditional variable object cond with attributes given by attr parameter.
pthread_mutexattr_settype
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
Set mutex type attribute associated with attr parameter.
pthread_cond_wait
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Block on condition variable cond, while another thread will unblock this variable by pthread_cond_bro...
pthread_key_create
int pthread_key_create(pthread_key_t *key, void(*destructor)(void *))
Create data key for data manipulation functions (pthread_getspecific(), pthread_setspecific()). Multiple threads can call data manipulation functions with the same key. In this case all threads will have separate data.
pthread_mutex_lock
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock mutex or wait while another thread is unlock currently locked mutex.
PTHREAD_MUTEX_DESTROYED
Definition: pthread.h:78
PTHREAD_CREATE_JOINABLE
Definition: pthread.h:110
__pthread_mutex_t
Definition: pthread.h:116
pthread_cond_destroy
int pthread_cond_destroy(pthread_cond_t *cond)
Destroy conditional variable object and make it unitialized.
pthread_mutexattr_gettype
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
Get mutex type attribute associated with attr parameter.
PTHREAD_MUTEX_ERRORCHECK
Definition: pthread.h:76
pthread_condattr_init
int pthread_condattr_init(pthread_condattr_t *attr)
Initialize conditional variable attributes with default values.
pthread_cond_timedwait
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *timeout)
Block on condition variable cond, while another thread will unblock this variable by pthread_cond_bro...
pthread_join
int pthread_join(pthread_t thread, void **retval)
Wait for the thread specified by thread to terminate. If that thread has already terminated, then returns immediately. The thread specified by thread must be joinable.
pthread_attr_getstacksize
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
The pthread_attr_getstacksize() function gets size of stack.
pthread_key_t
unsigned pthread_key_t
Definition: pthread.h:147
pthread_attr_getstackaddr
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
The pthread_attr_getstackaddr() function gets stack address.