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 struct _pthread *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_cond_attr *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_COND_INITIALIZER NULL 64 65 #define PTHREAD_NEEDS_INIT 0 66 #define PTHREAD_DONE_INIT 1 67 #define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } 68 69 #define PTHREAD_BARRIER_SERIAL_THREAD -1 70 #define PTHREAD_PRIO_NONE 0 71 #define PTHREAD_PRIO_INHERIT 1 72 #define PTHREAD_PRIO_PROTECT 2 73 74 //extern pthread_mutexattr_t pthread_mutexattr_default; 75 76 #ifdef __cplusplus 77 extern "C" { 78 #endif 79 80 extern pthread_mutex_t _pthread_mutex_static_initializer(void); 81 extern pthread_mutex_t _pthread_recursive_mutex_static_initializer(void); 82 #define PTHREAD_MUTEX_INITIALIZER \ 83 pthread_mutex_static_initializer(); 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 #ifdef __cplusplus 130 } 131 #endif 132 133 #endif /* _PTHREAD_ */ 134