1 /* 2 ** Distributed under the terms of the Haiku License. 3 */ 4 #ifndef _PTHREAD_H_ 5 #define _PTHREAD_H_ 6 7 #include <time.h> 8 9 typedef int pthread_t; 10 typedef struct _pthread_attr *pthread_attr_t; 11 typedef struct _pthread_mutex *pthread_mutex_t; 12 typedef struct _pthread_mutexattr *pthread_mutexattr_t; 13 typedef struct _pthread_cond *pthread_cond_t; 14 typedef struct _pthread_condattr *pthread_condattr_t; 15 typedef int pthread_key_t; 16 typedef struct _pthread_once pthread_once_t; 17 typedef struct _pthread_rwlock *pthread_rwlock_t; 18 typedef struct _pthread_rwlockattr *pthread_rwlockattr_t; 19 typedef struct _pthread_barrier *pthread_barrier_t; 20 typedef struct _pthread_barrierattr *pthread_barrierattr_t; 21 typedef struct _pthread_spinlock *pthread_spinlock_t; 22 23 struct _pthread_once { 24 int state; 25 pthread_mutex_t mutex; 26 }; 27 28 29 enum pthread_mutex_type { 30 PTHREAD_MUTEX_DEFAULT, 31 PTHREAD_MUTEX_NORMAL, 32 PTHREAD_MUTEX_ERRORCHECK, 33 PTHREAD_MUTEX_RECURSIVE, 34 }; 35 36 enum pthread_process_shared { 37 PTHREAD_PROCESS_PRIVATE, 38 PTHREAD_PROCESS_SHARED, 39 }; 40 41 /* 42 * Flags for threads and thread attributes. 43 */ 44 #define PTHREAD_DETACHED 0x1 45 #define PTHREAD_SCOPE_SYSTEM 0x2 46 #define PTHREAD_INHERIT_SCHED 0x4 47 #define PTHREAD_NOFLOAT 0x8 48 49 #define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED 50 #define PTHREAD_CREATE_JOINABLE 0 51 #define PTHREAD_SCOPE_PROCESS 0 52 #define PTHREAD_EXPLICIT_SCHED 0 53 54 /* 55 * Flags for cancelling threads 56 */ 57 #define PTHREAD_CANCEL_ENABLE 0 58 #define PTHREAD_CANCEL_DISABLE 1 59 #define PTHREAD_CANCEL_DEFERRED 0 60 #define PTHREAD_CANCEL_ASYNCHRONOUS 2 61 #define PTHREAD_CANCELED ((void *) 1) 62 63 #define PTHREAD_NEEDS_INIT 0 64 #define PTHREAD_DONE_INIT 1 65 #define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } 66 67 #define PTHREAD_BARRIER_SERIAL_THREAD -1 68 #define PTHREAD_PRIO_NONE 0 69 #define PTHREAD_PRIO_INHERIT 1 70 #define PTHREAD_PRIO_PROTECT 2 71 72 //extern pthread_mutexattr_t pthread_mutexattr_default; 73 74 #ifdef __cplusplus 75 extern "C" { 76 #endif 77 78 extern pthread_mutex_t _pthread_mutex_static_initializer(void); 79 extern pthread_mutex_t _pthread_recursive_mutex_static_initializer(void); 80 #define PTHREAD_MUTEX_INITIALIZER NULL 81 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ 82 pthread_recursive_mutex_static_initializer(); 83 84 extern pthread_cond_t _pthread_cond_static_initializer(void); 85 #define PTHREAD_COND_INITIALIZER _pthread_cond_static_initializer(); 86 87 /* mutex functions */ 88 extern int pthread_mutex_destroy(pthread_mutex_t *mutex); 89 extern int pthread_mutex_getprioceiling(pthread_mutex_t *mutex, int *_priorityCeiling); 90 extern int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); 91 extern int pthread_mutex_lock(pthread_mutex_t *mutex); 92 extern int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int newPriorityCeiling, 93 int *_oldPriorityCeiling); 94 extern int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *spec); 95 extern int pthread_mutex_trylock(pthread_mutex_t *mutex); 96 extern int pthread_mutex_unlock(pthread_mutex_t *mutex); 97 98 /* mutex attribute functions */ 99 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *mutexAttr); 100 extern int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mutexAttr, int *_priorityCeiling); 101 extern int pthread_mutexattr_getprotocol(pthread_mutexattr_t *mutexAttr, int *_protocol); 102 extern int pthread_mutexattr_getpshared(pthread_mutexattr_t *mutexAttr, int *_processShared); 103 extern int pthread_mutexattr_gettype(pthread_mutexattr_t *mutexAttr, int *_type); 104 extern int pthread_mutexattr_init(pthread_mutexattr_t *mutexAttr); 105 extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mutexAttr, int priorityCeiling); 106 extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *mutexAttr, int protocol); 107 extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *mutexAttr, int processShared); 108 extern int pthread_mutexattr_settype(pthread_mutexattr_t *mutexAttr, int type); 109 110 /* condition variable functions */ 111 extern int pthread_cond_destroy(pthread_cond_t *cond); 112 extern int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); 113 extern int pthread_cond_broadcast(pthread_cond_t *cond); 114 extern int pthread_cond_signal(pthread_cond_t *cond); 115 extern int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, 116 const struct timespec *abstime); 117 extern int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); 118 119 /* condition variable attribute functions */ 120 extern int pthread_condattr_destroy(pthread_condattr_t *condAttr); 121 extern int pthread_condattr_init(pthread_condattr_t *condAttr); 122 extern int pthread_condattr_getpshared(const pthread_condattr_t *condAttr, int *processShared); 123 extern int pthread_condattr_setpshared(pthread_condattr_t *condAttr, int processShared); 124 125 /* misc. functions */ 126 extern int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)); 127 extern int pthread_once(pthread_once_t *once_control, void (*init_routine)()); 128 129 /* thread attributes functions */ 130 extern int pthread_attr_destroy(pthread_attr_t *attr); 131 extern int pthread_attr_init(pthread_attr_t *attr); 132 extern int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); 133 extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); 134 135 extern int pthread_create(pthread_t *thread, const pthread_attr_t *attr, 136 void *(*start_routine)(void*), void *arg); 137 extern int pthread_detach(pthread_t thread); 138 extern int pthread_equal(pthread_t t1, pthread_t t2); 139 extern void pthread_exit(void *value_ptr); 140 extern int pthread_join(pthread_t thread, void **value_ptr); 141 extern pthread_t pthread_self(void); 142 143 extern int pthread_kill(pthread_t thread, int sig); 144 145 /* thread specific data functions */ 146 extern int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)); 147 extern int pthread_key_delete(pthread_key_t key); 148 extern void *pthread_getspecific(pthread_key_t key); 149 extern int pthread_setspecific(pthread_key_t key, const void *value); 150 151 #ifdef __cplusplus 152 } 153 #endif 154 155 #endif /* _PTHREAD_ */ 156