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 #include <OS.h> 9 10 typedef thread_id pthread_t; 11 typedef struct _pthread_attr *pthread_attr_t; 12 typedef struct _pthread_mutex *pthread_mutex_t; 13 typedef struct _pthread_mutexattr *pthread_mutexattr_t; 14 typedef struct _pthread_cond *pthread_cond_t; 15 typedef struct _pthread_cond_attr *pthread_condattr_t; 16 typedef int pthread_key_t; 17 typedef struct _pthread_once pthread_once_t; 18 typedef struct _pthread_rwlock *pthread_rwlock_t; 19 typedef struct _pthread_rwlockattr *pthread_rwlockattr_t; 20 typedef struct _pthread_barrier *pthread_barrier_t; 21 typedef struct _pthread_barrierattr *pthread_barrierattr_t; 22 typedef struct _pthread_spinlock *pthread_spinlock_t; 23 24 struct pthread_once { 25 int state; 26 pthread_mutex_t mutex; 27 }; 28 29 30 enum pthread_mutex_type { 31 PTHREAD_MUTEX_DEFAULT, 32 PTHREAD_MUTEX_NORMAL, 33 PTHREAD_MUTEX_ERRORCHECK, 34 PTHREAD_MUTEX_RECURSIVE, 35 }; 36 37 enum pthread_process_shared { 38 PTHREAD_PROCESS_PRIVATE, 39 PTHREAD_PROCESS_SHARED, 40 }; 41 42 /* 43 * Flags for threads and thread attributes. 44 */ 45 #define PTHREAD_DETACHED 0x1 46 #define PTHREAD_SCOPE_SYSTEM 0x2 47 #define PTHREAD_INHERIT_SCHED 0x4 48 #define PTHREAD_NOFLOAT 0x8 49 50 #define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED 51 #define PTHREAD_CREATE_JOINABLE 0 52 #define PTHREAD_SCOPE_PROCESS 0 53 #define PTHREAD_EXPLICIT_SCHED 0 54 55 /* 56 * Flags for cancelling threads 57 */ 58 #define PTHREAD_CANCEL_ENABLE 0 59 #define PTHREAD_CANCEL_DISABLE 1 60 #define PTHREAD_CANCEL_DEFERRED 0 61 #define PTHREAD_CANCEL_ASYNCHRONOUS 2 62 #define PTHREAD_CANCELED ((void *) 1) 63 64 #define PTHREAD_COND_INITIALIZER NULL 65 66 #define PTHREAD_NEEDS_INIT 0 67 #define PTHREAD_DONE_INIT 1 68 #define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } 69 70 #define PTHREAD_BARRIER_SERIAL_THREAD -1 71 #define PTHREAD_PRIO_NONE 0 72 #define PTHREAD_PRIO_INHERIT 1 73 #define PTHREAD_PRIO_PROTECT 2 74 75 //extern pthread_mutexattr_t pthread_mutexattr_default; 76 77 #ifdef __cplusplus 78 extern "C" { 79 #endif 80 81 extern pthread_mutex_t _pthread_mutex_static_initializer(void); 82 extern pthread_mutex_t _pthread_recursive_mutex_static_initializer(void); 83 #define PTHREAD_MUTEX_INITIALIZER NULL 84 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ 85 pthread_recursive_mutex_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 /* misc. functions */ 111 extern int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)); 112 113 /* thread attributes functions */ 114 extern int pthread_attr_destroy(pthread_attr_t *attr); 115 extern int pthread_attr_init(pthread_attr_t *attr); 116 extern int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate); 117 extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); 118 119 extern int pthread_create(pthread_t *thread, const pthread_attr_t *attr, 120 void *(*start_routine)(void*), void *arg); 121 extern int pthread_detach(pthread_t thread); 122 extern int pthread_equal(pthread_t t1, pthread_t t2); 123 extern void pthread_exit(void *value_ptr); 124 extern int pthread_join(pthread_t thread, void **value_ptr); 125 extern pthread_t pthread_self(void); 126 127 extern int pthread_kill(pthread_t thread, int sig); 128 129 /* thread specific data functions */ 130 extern int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)); 131 extern int pthread_key_delete(pthread_key_t key); 132 extern void *pthread_getspecific(pthread_key_t key); 133 extern int pthread_setspecific(pthread_key_t key, const void *value); 134 135 #ifdef __cplusplus 136 } 137 #endif 138 139 #endif /* _PTHREAD_ */ 140