Samsung Internal API reference  2.0
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 {
85 };
86 
91  atomic_t already_executed;
92 };
93 
96 #define PTHREAD_ONCE_INIT { ATOMIC_INITIALIZER }
97 
101  void *stackaddr;
102  unsigned int stacksize;
103  unsigned int guardsize;
104  unsigned int flags;
105 };
106 
108 enum
109 {
112 };
113 
117  atomic_t state;
118  unsigned attr;
119  unsigned count;
120  pthread_t caller_thread;
121 };
122 
126 
131  atomic_t status;
132 };
133 
137  /* Not implemented. */
138 };
139 
143 #define PTHREAD_COND_INITIALIZER { ATOMIC_INITIALIZER }
144 
147 typedef unsigned pthread_key_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
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
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 
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
Set the detach state attribute.
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...
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Release lock on currently locked mutex.
int pthread_detach(pthread_t thread)
Detach a thread.
pthread_t pthread_self(void)
Obtain ID of the calling thread.
uintptr_t pthread_t
Definition: pthread.h:66
Time header.
Definition: pthread.h:136
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
The pthread_attr_setstacksize() function sets size of stack.
struct pthread_impl pthread_impl_t
Definition: pthread.h:62
int pthread_cond_broadcast(pthread_cond_t *cond)
Wake up all threads locked by conditional variable cond.
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize)
The pthread_attr_setstack() function sets stack address and size.
Definition: pthread.h:130
uint32_t pthread_mutexattr_t
Definition: pthread.h:70
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().
int pthread_kill(pthread_t thread, int sig)
Send signal to specified thread.
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...
void * pthread_getspecific(pthread_key_t key)
Return the value currently bound to the specified key on behalf of the calling thread.
int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
The pthread_attr_getstack() function gets stack address and size.
Definition: pthread.h:83
int pthread_mutex_trylock(pthread_mutex_t *mutex)
Lock mutex or fail if mutex is already locked.
int pthread_attr_init(pthread_attr_t *attr)
The pthread_attr_init() function initialize attribute struct.
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
Get the detach state attribute.
int pthread_condattr_destroy(pthread_condattr_t *attr)
Destroy conditional variable attributes.
Definition: pthread.h:90
Definition: pthread.h:75
Definition: pthread.h:100
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...
int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
The pthread_attr_getguardsize() function gets size of guard.
Definition: pthread.h:77
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
Destroy attributes object and make all attribute values are uninitialized.
int pthread_mutex_destroy(pthread_mutex_t *mutex)
Destroy mutex object and make all associated data are uninitialized.
int pthread_attr_destroy(pthread_attr_t *attr)
The pthread_attr_destroy() function destroy attribute struct.
int pthread_equal(pthread_t t1, pthread_t t2)
Compare thread IDs.
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...
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
The pthread_attr_setguardsize() function sets size of guard.
_noreturn_ void pthread_exit(void *retval)
Terminate calling thread.
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
Get attributes of created thread.
Definition: pthread.h:111
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
The pthread_attr_setstackaddr() function gets stack address.
Definition: pthread.h:74
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().
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
Initialize mutex attributes object and initialize attributes with default values. ...
Definition: pthread.h:81
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Initialize conditional variable object cond with attributes given by attr parameter.
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
Set mutex type attribute associated with attr parameter.
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...
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.
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock mutex or wait while another thread is unlock currently locked mutex.
Definition: pthread.h:78
Definition: pthread.h:110
Definition: pthread.h:116
int pthread_cond_destroy(pthread_cond_t *cond)
Destroy conditional variable object and make it unitialized.
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
Get mutex type attribute associated with attr parameter.
Definition: pthread.h:76
int pthread_condattr_init(pthread_condattr_t *attr)
Initialize conditional variable attributes with default values.
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...
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.
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
The pthread_attr_getstacksize() function gets size of stack.
unsigned pthread_key_t
Definition: pthread.h:147
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
The pthread_attr_getstackaddr() function gets stack address.