[5e9b32b] | 1 | /* pthread.h |
---|
| 2 | * |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | #ifndef __PTHREAD_h |
---|
| 6 | #define __PTHREAD_h |
---|
| 7 | |
---|
| 8 | #include <rtems/posix/features.h> |
---|
| 9 | |
---|
| 10 | #if defined(_POSIX_THREADS) |
---|
| 11 | |
---|
| 12 | #include <sys/types.h> |
---|
| 13 | #include <time.h> |
---|
| 14 | #include <sys/sched.h> |
---|
| 15 | |
---|
| 16 | /* |
---|
| 17 | * 3.1.3 Register Fork Handlers, P1003.1c/Draft 10, P1003.1c/Draft 10, p. 27 |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | int pthread_atfork( |
---|
| 21 | void (*prepare)(void), |
---|
| 22 | void (*parent)(void), |
---|
| 23 | void (*child)(void) |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | /* |
---|
| 27 | * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | int pthread_mutexattr_init( |
---|
| 31 | pthread_mutexattr_t *attr |
---|
| 32 | ); |
---|
| 33 | |
---|
| 34 | int pthread_mutexattr_destroy( |
---|
| 35 | pthread_mutexattr_t *attr |
---|
| 36 | ); |
---|
| 37 | |
---|
| 38 | int pthread_mutexattr_getpshared( |
---|
| 39 | const pthread_mutexattr_t *attr, |
---|
| 40 | int *pshared |
---|
| 41 | ); |
---|
| 42 | |
---|
| 43 | int pthread_mutexattr_setpshared( |
---|
| 44 | pthread_mutexattr_t *attr, |
---|
| 45 | int pshared |
---|
| 46 | ); |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | int pthread_mutex_init( |
---|
| 53 | pthread_mutex_t *mutex, |
---|
| 54 | const pthread_mutexattr_t *attr |
---|
| 55 | ); |
---|
| 56 | |
---|
| 57 | int pthread_mutex_destroy( |
---|
| 58 | pthread_mutex_t *mutex |
---|
| 59 | ); |
---|
| 60 | |
---|
| 61 | /* |
---|
| 62 | * This is used to statically initialize a pthread_mutex_t. Example: |
---|
| 63 | * |
---|
| 64 | * pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) |
---|
| 68 | |
---|
| 69 | /* |
---|
| 70 | * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 |
---|
| 71 | * |
---|
| 72 | * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 |
---|
| 73 | */ |
---|
| 74 | |
---|
| 75 | int pthread_mutex_lock( |
---|
| 76 | pthread_mutex_t *mutex |
---|
| 77 | ); |
---|
| 78 | |
---|
| 79 | int pthread_mutex_trylock( |
---|
| 80 | pthread_mutex_t *mutex |
---|
| 81 | ); |
---|
| 82 | |
---|
| 83 | int pthread_mutex_unlock( |
---|
| 84 | pthread_mutex_t *mutex |
---|
| 85 | ); |
---|
| 86 | |
---|
| 87 | #if defined(_POSIX_TIMEOUTS) |
---|
| 88 | |
---|
| 89 | int pthread_mutex_timedlock( |
---|
| 90 | pthread_mutex_t *mutex, |
---|
| 91 | const struct timespec *timeout |
---|
| 92 | ); |
---|
| 93 | |
---|
| 94 | #endif /* _POSIX_TIMEOUTS */ |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | * 11.4.1 Condition Variable Initialization Attributes, |
---|
| 98 | * P1003.1c/Draft 10, p. 96 |
---|
| 99 | */ |
---|
| 100 | |
---|
| 101 | int pthread_condattr_init( |
---|
| 102 | pthread_condattr_t *attr |
---|
| 103 | ); |
---|
| 104 | |
---|
| 105 | int pthread_condattr_destroy( |
---|
| 106 | pthread_condattr_t *attr |
---|
| 107 | ); |
---|
| 108 | |
---|
| 109 | int pthread_condattr_getpshared( |
---|
| 110 | const pthread_condattr_t *attr, |
---|
| 111 | int *pshared |
---|
| 112 | ); |
---|
| 113 | |
---|
| 114 | int pthread_condattr_setpshared( |
---|
| 115 | pthread_condattr_t *attr, |
---|
| 116 | int pshared |
---|
| 117 | ); |
---|
| 118 | |
---|
| 119 | /* |
---|
| 120 | * 11.4.2 Initializing and Destroying a Condition Variable, |
---|
| 121 | * P1003.1c/Draft 10, p. 87 |
---|
| 122 | */ |
---|
| 123 | |
---|
| 124 | int pthread_cond_init( |
---|
| 125 | pthread_cond_t *cond, |
---|
| 126 | const pthread_condattr_t *attr |
---|
| 127 | ); |
---|
| 128 | |
---|
| 129 | int pthread_cond_destroy( |
---|
| 130 | pthread_cond_t *mutex |
---|
| 131 | ); |
---|
| 132 | |
---|
| 133 | /* |
---|
| 134 | * This is used to statically initialize a pthread_cond_t. Example: |
---|
| 135 | * |
---|
| 136 | * pthread_cond_t cond = PTHREAD_COND_INITIALIZER; |
---|
| 137 | */ |
---|
| 138 | |
---|
| 139 | #define PTHREAD_COND_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) |
---|
| 140 | |
---|
| 141 | /* |
---|
| 142 | * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 |
---|
| 143 | */ |
---|
| 144 | |
---|
| 145 | int pthread_cond_signal( |
---|
| 146 | pthread_cond_t *cond |
---|
| 147 | ); |
---|
| 148 | |
---|
| 149 | int pthread_cond_broadcast( |
---|
| 150 | pthread_cond_t *cond |
---|
| 151 | ); |
---|
| 152 | |
---|
| 153 | /* |
---|
| 154 | * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 |
---|
| 155 | */ |
---|
| 156 | |
---|
| 157 | int pthread_cond_wait( |
---|
| 158 | pthread_cond_t *cond, |
---|
| 159 | pthread_mutex_t *mutex |
---|
| 160 | ); |
---|
| 161 | |
---|
| 162 | int pthread_cond_timedwait( |
---|
| 163 | pthread_cond_t *cond, |
---|
| 164 | pthread_mutex_t *mutex, |
---|
| 165 | const struct timespec *abstime |
---|
| 166 | ); |
---|
| 167 | |
---|
| 168 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
---|
| 169 | |
---|
| 170 | /* |
---|
| 171 | * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 |
---|
| 172 | */ |
---|
| 173 | |
---|
| 174 | int pthread_attr_setscope( |
---|
| 175 | pthread_attr_t *attr, |
---|
| 176 | int contentionscope |
---|
| 177 | ); |
---|
| 178 | |
---|
| 179 | int pthread_attr_getscope( |
---|
| 180 | const pthread_attr_t *attr, |
---|
| 181 | int *contentionscope |
---|
| 182 | ); |
---|
| 183 | |
---|
| 184 | #define PTHREAD_INHERIT_SCHED 0 /* scheduling policy and associated */ |
---|
| 185 | /* attributes are inherited from */ |
---|
| 186 | /* the calling thread. */ |
---|
| 187 | #define PTHREAD_EXPLICIT_SCHED 0 /* set from provided attribute object */ |
---|
| 188 | |
---|
| 189 | int pthread_attr_setinheritsched( |
---|
| 190 | pthread_attr_t *attr, |
---|
| 191 | int inheritsched |
---|
| 192 | ); |
---|
| 193 | |
---|
| 194 | int pthread_attr_getinheritsched( |
---|
| 195 | const pthread_attr_t *attr, |
---|
| 196 | int *inheritsched |
---|
| 197 | ); |
---|
| 198 | |
---|
| 199 | int pthread_attr_setschedpolicy( |
---|
| 200 | pthread_attr_t *attr, |
---|
| 201 | int policy |
---|
| 202 | ); |
---|
| 203 | |
---|
| 204 | int pthread_attr_getschedpolicy( |
---|
| 205 | const pthread_attr_t *attr, |
---|
| 206 | int *policy |
---|
| 207 | ); |
---|
| 208 | |
---|
| 209 | #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */ |
---|
| 210 | |
---|
| 211 | int pthread_attr_setschedparam( |
---|
| 212 | pthread_attr_t *attr, |
---|
| 213 | const struct sched_param param |
---|
| 214 | ); |
---|
| 215 | |
---|
| 216 | int pthread_attr_getschedparam( |
---|
| 217 | const pthread_attr_t *attr, |
---|
| 218 | struct sched_param *param |
---|
| 219 | ); |
---|
| 220 | |
---|
| 221 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
---|
| 222 | |
---|
| 223 | /* |
---|
| 224 | * 13.5.2 Dynamic Thread Scheduling Parameters Access, |
---|
| 225 | * P1003.1c/Draft 10, p. 124 |
---|
| 226 | */ |
---|
| 227 | |
---|
| 228 | int pthread_getschedparam( |
---|
| 229 | pthread_t thread, |
---|
| 230 | int *policy, |
---|
| 231 | struct sched_param *param |
---|
| 232 | ); |
---|
| 233 | |
---|
| 234 | int pthread_setschedparam( |
---|
| 235 | pthread_t thread, |
---|
| 236 | int policy, |
---|
| 237 | struct sched_param *param |
---|
| 238 | ); |
---|
| 239 | |
---|
| 240 | #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */ |
---|
| 241 | |
---|
| 242 | #if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT) |
---|
| 243 | |
---|
| 244 | /* |
---|
| 245 | * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 |
---|
| 246 | */ |
---|
| 247 | |
---|
| 248 | /* |
---|
| 249 | * Values for protocol. |
---|
| 250 | */ |
---|
| 251 | |
---|
| 252 | #define PTHREAD_PRIO_NONE 0 |
---|
| 253 | #define PTHREAD_PRIO_INHERIT 1 |
---|
| 254 | #define PTHREAD_PRIO_PROTECT 2 |
---|
| 255 | |
---|
| 256 | int pthread_mutexattr_setprotocol( |
---|
| 257 | pthread_mutexattr_t *attr, |
---|
| 258 | int protocol |
---|
| 259 | ); |
---|
| 260 | |
---|
| 261 | int pthread_mutexattr_getprotocol( |
---|
| 262 | const pthread_mutexattr_t *attr, |
---|
| 263 | int *protocol |
---|
| 264 | ); |
---|
| 265 | |
---|
| 266 | int pthread_mutexattr_setprioceiling( |
---|
| 267 | pthread_mutexattr_t *attr, |
---|
| 268 | int prioceiling |
---|
| 269 | ); |
---|
| 270 | |
---|
| 271 | int pthread_mutexattr_getprioceiling( |
---|
| 272 | const pthread_mutexattr_t *attr, |
---|
| 273 | int *prioceiling |
---|
| 274 | ); |
---|
| 275 | |
---|
| 276 | #endif /* _POSIX_THREAD_PRIO_INHERIT || _POSIX_THREAD_PRIO_PROTECT */ |
---|
| 277 | |
---|
| 278 | #if defined(_POSIX_THREAD_PRIO_PROTECT) |
---|
| 279 | |
---|
| 280 | /* |
---|
| 281 | * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 |
---|
| 282 | */ |
---|
| 283 | |
---|
| 284 | int pthread_mutex_setprioceiling( |
---|
| 285 | pthread_mutex_t *mutex, |
---|
| 286 | int prioceiling, |
---|
| 287 | int *old_ceiling |
---|
| 288 | ); |
---|
| 289 | |
---|
| 290 | int pthread_mutex_getprioceiling( |
---|
| 291 | pthread_mutex_t *mutex, |
---|
| 292 | int *prioceiling |
---|
| 293 | ); |
---|
| 294 | |
---|
| 295 | #endif /* _POSIX_THREAD_PRIO_PROTECT */ |
---|
| 296 | |
---|
| 297 | /* |
---|
| 298 | * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 |
---|
| 299 | */ |
---|
| 300 | |
---|
| 301 | int pthread_attr_init( |
---|
| 302 | pthread_attr_t *attr |
---|
| 303 | ); |
---|
| 304 | |
---|
| 305 | int pthread_attr_destroy( |
---|
| 306 | pthread_attr_t *attr |
---|
| 307 | ); |
---|
| 308 | |
---|
| 309 | int pthread_attr_getstacksize( |
---|
| 310 | const pthread_attr_t *attr, |
---|
| 311 | size_t *stacksize |
---|
| 312 | ); |
---|
| 313 | |
---|
| 314 | int pthread_attr_setstacksize( |
---|
| 315 | pthread_attr_t *attr, |
---|
| 316 | size_t stacksize |
---|
| 317 | ); |
---|
| 318 | |
---|
| 319 | int pthread_attr_getstackaddr( |
---|
| 320 | const pthread_attr_t *attr, |
---|
| 321 | void **stackaddr |
---|
| 322 | ); |
---|
| 323 | |
---|
| 324 | int pthread_attr_setstackaddr( |
---|
| 325 | pthread_attr_t *attr, |
---|
| 326 | void *stackaddr |
---|
| 327 | ); |
---|
| 328 | |
---|
| 329 | int pthread_attr_getdetachstate( |
---|
| 330 | const pthread_attr_t *attr, |
---|
| 331 | int *detachstate |
---|
| 332 | ); |
---|
| 333 | |
---|
| 334 | int pthread_attr_setdetachstate( |
---|
| 335 | pthread_attr_t *attr, |
---|
| 336 | int detachstate |
---|
| 337 | ); |
---|
| 338 | |
---|
| 339 | /* |
---|
| 340 | * 16.1.2 Thread Creation, P1003.1c/Draft 10, p. 144 |
---|
| 341 | */ |
---|
| 342 | |
---|
| 343 | int pthread_create( |
---|
| 344 | pthread_t *thread, |
---|
| 345 | const pthread_attr_t *attr, |
---|
| 346 | void (*start_routine)( void * ), |
---|
| 347 | void *arg |
---|
| 348 | ); |
---|
| 349 | |
---|
| 350 | /* |
---|
| 351 | * 16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147 |
---|
| 352 | */ |
---|
| 353 | |
---|
| 354 | int pthread_join( |
---|
| 355 | pthread_t thread, |
---|
| 356 | void **value_ptr |
---|
| 357 | ); |
---|
| 358 | |
---|
| 359 | /* |
---|
| 360 | * 16.1.4 Detaching a Thread, P1003.1c/Draft 10, p. 149 |
---|
| 361 | */ |
---|
| 362 | |
---|
| 363 | int pthread_detach( |
---|
| 364 | pthread_t thread |
---|
| 365 | ); |
---|
| 366 | |
---|
| 367 | /* |
---|
| 368 | * 16.1.6 Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX |
---|
| 369 | */ |
---|
| 370 | |
---|
| 371 | pthread_t pthread_self( void ); |
---|
| 372 | |
---|
| 373 | /* |
---|
| 374 | * 16.1.7 Compare Thread IDs, p1003.1c/Draft 10, p. 153 |
---|
| 375 | */ |
---|
| 376 | |
---|
| 377 | int pthread_equal( |
---|
| 378 | pthread_t t1, |
---|
| 379 | pthread_t t2 |
---|
| 380 | ); |
---|
| 381 | |
---|
| 382 | /* |
---|
| 383 | * 16.1.8 Dynamic Package Initialization |
---|
| 384 | */ |
---|
| 385 | |
---|
| 386 | /* |
---|
| 387 | * This is used to statically initialize a pthread_once_t. Example: |
---|
| 388 | * |
---|
| 389 | * pthread_once_t once = PTHREAD_ONCE_INITIALIZER; |
---|
| 390 | */ |
---|
| 391 | |
---|
| 392 | #define PTHREAD_ONCE_INITIALIZER { TRUE, FALSE } |
---|
| 393 | |
---|
| 394 | int pthread_once( |
---|
| 395 | pthread_once_t *once_control, |
---|
| 396 | void (*init_routine)(void) |
---|
| 397 | ); |
---|
| 398 | |
---|
| 399 | /* |
---|
| 400 | * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 |
---|
| 401 | */ |
---|
| 402 | |
---|
| 403 | int pthread_key_create( |
---|
| 404 | pthread_key_t *key, |
---|
| 405 | void (*destructor)( void * ) |
---|
| 406 | ); |
---|
| 407 | |
---|
| 408 | /* |
---|
| 409 | * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 |
---|
| 410 | */ |
---|
| 411 | |
---|
| 412 | int pthread_setspecific( |
---|
| 413 | pthread_key_t key, |
---|
| 414 | const void *value |
---|
| 415 | ); |
---|
| 416 | |
---|
| 417 | void *pthread_getspecific( |
---|
| 418 | pthread_key_t key |
---|
| 419 | ); |
---|
| 420 | |
---|
| 421 | /* |
---|
| 422 | * 17.1.3 Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167 |
---|
| 423 | */ |
---|
| 424 | |
---|
| 425 | int pthread_key_delete( |
---|
| 426 | pthread_key_t key |
---|
| 427 | ); |
---|
| 428 | |
---|
| 429 | /* |
---|
| 430 | * 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181 |
---|
| 431 | */ |
---|
| 432 | |
---|
| 433 | #define PTHREAD_CANCEL_ENABLE 0 |
---|
| 434 | #define PTHREAD_CANCEL_DISABLE 1 |
---|
| 435 | |
---|
| 436 | #define PTHREAD_CANCEL_DEFERRED 0 |
---|
| 437 | #define PTHREAD_CANCEL_ASYNCHRONOUS 1 |
---|
| 438 | |
---|
| 439 | int pthread_cancel( |
---|
| 440 | pthread_t thread |
---|
| 441 | ); |
---|
| 442 | |
---|
| 443 | /* |
---|
| 444 | * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 |
---|
| 445 | */ |
---|
| 446 | |
---|
| 447 | int pthread_setcancelstate( |
---|
| 448 | int state, |
---|
| 449 | int *oldstate |
---|
| 450 | ); |
---|
| 451 | |
---|
| 452 | int pthread_setcanceltype( |
---|
| 453 | int type, |
---|
| 454 | int *oldtype |
---|
| 455 | ); |
---|
| 456 | |
---|
| 457 | void pthread_testcancel( void ); |
---|
| 458 | |
---|
| 459 | /* |
---|
| 460 | * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 |
---|
| 461 | */ |
---|
| 462 | |
---|
| 463 | void pthread_cleanup_push( |
---|
| 464 | void (*routine)( void * ), |
---|
| 465 | void *arg |
---|
| 466 | ); |
---|
| 467 | |
---|
| 468 | void pthread_cleanup_pop( |
---|
| 469 | int execute |
---|
| 470 | ); |
---|
| 471 | |
---|
| 472 | #if defined(_POSIX_THREAD_CPUTIME) |
---|
| 473 | |
---|
| 474 | /* |
---|
| 475 | * 20.1.6 Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 |
---|
| 476 | */ |
---|
| 477 | |
---|
| 478 | int pthread_getcpuclockid( |
---|
| 479 | pthread_t pid, |
---|
| 480 | clockid_t *clock_id |
---|
| 481 | ); |
---|
| 482 | |
---|
| 483 | /* |
---|
| 484 | * 20.1.7 CPU-time Clock Thread Creation Attribute, P1003.4b/D8, p. 59 |
---|
| 485 | */ |
---|
| 486 | |
---|
| 487 | int pthread_attr_setcputime( |
---|
| 488 | pthread_attr_t *attr, |
---|
| 489 | int clock_allowed |
---|
| 490 | ); |
---|
| 491 | |
---|
| 492 | int pthread_attr_getcputime( |
---|
| 493 | pthread_attr_t *attr, |
---|
| 494 | int *clock_allowed |
---|
| 495 | ); |
---|
| 496 | |
---|
| 497 | #endif /* defined(_POSIX_THREAD_CPUTIME) */ |
---|
| 498 | |
---|
| 499 | #endif /* defined(_POSIX_THREADS) */ |
---|
| 500 | #endif |
---|
| 501 | /* end of include file */ |
---|