1 /* pthread.h 2 * 3 * Written by Joel Sherrill <joel@OARcorp.com>. 4 * 5 * COPYRIGHT (c) 1989-2000. 6 * On-Line Applications Research Corporation (OAR). 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose without fee is hereby granted, provided that this entire notice 10 * is included in all copies of any software which is or includes a copy 11 * or modification of this software. 12 * 13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION 15 * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS 16 * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 * 18 * $Id: pthread.h,v 1.3 2002/10/08 13:03:07 joel Exp $ 19 */ 20 21 #ifndef __PTHREAD_h 22 #define __PTHREAD_h 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #include <unistd.h> 29 30 #if defined(_POSIX_THREADS) 31 32 #include <sys/types.h> 33 #include <time.h> 34 #include <sys/sched.h> 35 36 /* Register Fork Handlers, P1003.1c/Draft 10, P1003.1c/Draft 10, p. 27 37 38 If an OS does not support processes, then it falls under this provision 39 and may not provide pthread_atfork(): 40 41 "Either the implementation shall support the pthread_atfork() function 42 as described above or the pthread_atfork() funciton shall not be 43 provided." 44 45 NOTE: RTEMS does not provide pthread_atfork(). */ 46 47 #if !defined(__rtems__) 48 #warning "Add pthread_atfork() prototype" 49 #endif 50 51 /* Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 */ 52 53 int _EXFUN(pthread_mutexattr_init, (pthread_mutexattr_t *attr)); 54 int _EXFUN(pthread_mutexattr_destroy, (pthread_mutexattr_t *attr)); 55 int _EXFUN(pthread_mutexattr_getpshared, 56 (const pthread_mutexattr_t *attr, int *pshared)); 57 int _EXFUN(pthread_mutexattr_setpshared, 58 (pthread_mutexattr_t *attr, int pshared)); 59 60 /* Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 */ 61 62 int _EXFUN(pthread_mutex_init, 63 (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)); 64 int _EXFUN(pthread_mutex_destroy, (pthread_mutex_t *mutex)); 65 66 /* This is used to statically initialize a pthread_mutex_t. Example: 67 68 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 69 */ 70 71 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) 72 73 /* Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 74 NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 */ 75 76 int _EXFUN(pthread_mutex_lock, (pthread_mutex_t *mutex)); 77 int _EXFUN(pthread_mutex_trylock, (pthread_mutex_t *mutex)); 78 int _EXFUN(pthread_mutex_unlock, (pthread_mutex_t *mutex)); 79 80 #if defined(_POSIX_TIMEOUTS) 81 82 int _EXFUN(pthread_mutex_timedlock, 83 (pthread_mutex_t *mutex, const struct timespec *timeout)); 84 85 #endif /* _POSIX_TIMEOUTS */ 86 87 /* Condition Variable Initialization Attributes, P1003.1c/Draft 10, p. 96 */ 88 89 int _EXFUN(pthread_condattr_init, (pthread_condattr_t *attr)); 90 int _EXFUN(pthread_condattr_destroy, (pthread_condattr_t *attr)); 91 int _EXFUN(pthread_condattr_getpshared, 92 (const pthread_condattr_t *attr, int *pshared)); 93 int _EXFUN(pthread_condattr_setpshared, 94 (pthread_condattr_t *attr, int pshared)); 95 96 /* Initializing and Destroying a Condition Variable, P1003.1c/Draft 10, p. 87 */ 97 98 int _EXFUN(pthread_cond_init, 99 (pthread_cond_t *cond, const pthread_condattr_t *attr)); 100 int _EXFUN(pthread_cond_destroy, (pthread_cond_t *mutex)); 101 102 /* This is used to statically initialize a pthread_cond_t. Example: 103 104 pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 105 */ 106 107 #define PTHREAD_COND_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) 108 109 /* Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 */ 110 111 int _EXFUN(pthread_cond_signal, (pthread_cond_t *cond)); 112 int _EXFUN(pthread_cond_broadcast, (pthread_cond_t *cond)); 113 114 /* Waiting on a Condition, P1003.1c/Draft 10, p. 105 */ 115 116 int _EXFUN(pthread_cond_wait, 117 (pthread_cond_t *cond, pthread_mutex_t *mutex)); 118 119 int _EXFUN(pthread_cond_timedwait, 120 (pthread_cond_t *cond, pthread_mutex_t *mutex, 121 const struct timespec *abstime)); 122 123 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) 124 125 /* Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 */ 126 127 int _EXFUN(pthread_attr_setscope, 128 (pthread_attr_t *attr, int contentionscope)); 129 int _EXFUN(pthread_attr_getscope, 130 (const pthread_attr_t *attr, int *contentionscope)); 131 int _EXFUN(pthread_attr_setinheritsched, 132 (pthread_attr_t *attr, int inheritsched)); 133 int _EXFUN(pthread_attr_getinheritsched, 134 (const pthread_attr_t *attr, int *inheritsched)); 135 int _EXFUN(pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy)); 136 int _EXFUN(pthread_attr_getschedpolicy, 137 (const pthread_attr_t *attr, int *policy)); 138 139 #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */ 140 141 int _EXFUN(pthread_attr_setschedparam, 142 (pthread_attr_t *attr, const struct sched_param *param)); 143 int _EXFUN(pthread_attr_getschedparam, 144 (const pthread_attr_t *attr, struct sched_param *param)); 145 146 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) 147 148 /* Dynamic Thread Scheduling Parameters Access, P1003.1c/Draft 10, p. 124 */ 149 150 int _EXFUN(pthread_getschedparam, 151 (pthread_t thread, int *policy, struct sched_param *param)); 152 int _EXFUN(pthread_setschedparam, 153 (pthread_t thread, int policy, struct sched_param *param)); 154 155 #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */ 156 157 #if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT) 158 159 /* Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 */ 160 161 int _EXFUN(pthread_mutexattr_setprotocol, 162 (pthread_mutexattr_t *attr, int protocol)); 163 int _EXFUN(pthread_mutexattr_getprotocol, 164 (const pthread_mutexattr_t *attr, int *protocol)); 165 int _EXFUN(pthread_mutexattr_setprioceiling, 166 (pthread_mutexattr_t *attr, int prioceiling)); 167 int _EXFUN(pthread_mutexattr_getprioceiling, 168 (const pthread_mutexattr_t *attr, int *prioceiling)); 169 170 #endif /* _POSIX_THREAD_PRIO_INHERIT || _POSIX_THREAD_PRIO_PROTECT */ 171 172 #if defined(_POSIX_THREAD_PRIO_PROTECT) 173 174 /* Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 */ 175 176 int _EXFUN(pthread_mutex_setprioceiling, 177 (pthread_mutex_t *mutex, int prioceiling, int *old_ceiling)); 178 int _EXFUN(pthread_mutex_getprioceiling, 179 (pthread_mutex_t *mutex, int *prioceiling)); 180 181 #endif /* _POSIX_THREAD_PRIO_PROTECT */ 182 183 /* Thread Creation Attributes, P1003.1c/Draft 10, p, 140 */ 184 185 int _EXFUN(pthread_attr_init, (pthread_attr_t *attr)); 186 int _EXFUN(pthread_attr_destroy, (pthread_attr_t *attr)); 187 int _EXFUN(pthread_attr_getstacksize, 188 (const pthread_attr_t *attr, size_t *stacksize)); 189 int _EXFUN(pthread_attr_setstacksize, 190 (pthread_attr_t *attr, size_t stacksize)); 191 int _EXFUN(pthread_attr_getstackaddr, 192 (const pthread_attr_t *attr, void **stackaddr)); 193 int _EXFUN(pthread_attr_setstackaddr, 194 (pthread_attr_t *attr, void *stackaddr)); 195 int _EXFUN(pthread_attr_getdetachstate, 196 (const pthread_attr_t *attr, int *detachstate)); 197 int _EXFUN(pthread_attr_setdetachstate, 198 (pthread_attr_t *attr, int detachstate)); 199 200 /* Thread Creation, P1003.1c/Draft 10, p. 144 */ 201 202 int _EXFUN(pthread_create, 203 (pthread_t *thread, const pthread_attr_t *attr, 204 void *(*start_routine)( void * ), void *arg)); 205 206 /* Wait for Thread Termination, P1003.1c/Draft 10, p. 147 */ 207 208 int _EXFUN(pthread_join, (pthread_t thread, void **value_ptr)); 209 210 /* Detaching a Thread, P1003.1c/Draft 10, p. 149 */ 211 212 int _EXFUN(pthread_detach, (pthread_t thread)); 213 214 /* Thread Termination, p1003.1c/Draft 10, p. 150 */ 215 216 void _EXFUN(pthread_exit, (void *value_ptr)); 217 218 /* Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX */ 219 220 pthread_t _EXFUN(pthread_self, (void)); 221 222 /* Compare Thread IDs, p1003.1c/Draft 10, p. 153 */ 223 224 int _EXFUN(pthread_equal, (pthread_t t1, pthread_t t2)); 225 226 /* Dynamic Package Initialization */ 227 228 /* This is used to statically initialize a pthread_once_t. Example: 229 230 pthread_once_t once = PTHREAD_ONCE_INIT; 231 232 NOTE: This is named inconsistently -- it should be INITIALIZER. */ 233 234 #define PTHREAD_ONCE_INIT { 1, 0 } /* is initialized and not run */ 235 236 int _EXFUN(pthread_once, 237 (pthread_once_t *once_control, void (*init_routine)(void))); 238 239 /* Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 */ 240 241 int _EXFUN(pthread_key_create, 242 (pthread_key_t *key, void (*destructor)( void * ))); 243 244 /* Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 */ 245 246 int _EXFUN(pthread_setspecific, (pthread_key_t key, const void *value)); 247 void * _EXFUN(pthread_getspecific, (pthread_key_t key)); 248 249 /* Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167 */ 250 251 int _EXFUN(pthread_key_delete, (pthread_key_t key)); 252 253 /* Execution of a Thread, P1003.1c/Draft 10, p. 181 */ 254 255 #define PTHREAD_CANCEL_ENABLE 0 256 #define PTHREAD_CANCEL_DISABLE 1 257 258 #define PTHREAD_CANCEL_DEFERRED 0 259 #define PTHREAD_CANCEL_ASYNCHRONOUS 1 260 261 #define PTHREAD_CANCELED ((void *) -1) 262 263 int _EXFUN(pthread_cancel, (pthread_t thread)); 264 265 /* Setting Cancelability State, P1003.1c/Draft 10, p. 183 */ 266 267 int _EXFUN(pthread_setcancelstate, (int state, int *oldstate)); 268 int _EXFUN(pthread_setcanceltype, (int type, int *oldtype)); 269 void _EXFUN(pthread_testcancel, (void)); 270 271 /* Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 */ 272 273 void _EXFUN(pthread_cleanup_push, (void (*routine)( void * ), void *arg)); 274 void _EXFUN(pthread_cleanup_pop, (int execute)); 275 276 #if defined(_POSIX_THREAD_CPUTIME) 277 278 /* Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 */ 279 280 int _EXFUN(pthread_getcpuclockid, 281 (pthread_t thread_id, clockid_t *clock_id)); 282 283 /* CPU-time Clock Thread Creation Attribute, P1003.4b/D8, p. 59 */ 284 285 int _EXFUN(pthread_attr_setcputime, 286 (pthread_attr_t *attr, int clock_allowed)); 287 288 int _EXFUN(pthread_attr_getcputime, 289 (pthread_attr_t *attr, int *clock_allowed)); 290 291 #endif /* defined(_POSIX_THREAD_CPUTIME) */ 292 293 #endif /* defined(_POSIX_THREADS) */ 294 295 #ifdef __cplusplus 296 } 297 #endif 298 299 #endif 300 /* end of include file */ 301