Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/ntirpc/misc/winpthreads.h
$ cat -n /usr/include/ntirpc/misc/winpthreads.h 1 /* 2 * Posix Threads library for Microsoft Windows 3 * 4 * Use at own risk, there is no implied warranty to this code. 5 * It uses undocumented features of Microsoft Windows that can change 6 * at any time in the future. 7 * 8 * (C) 2010 Lockless Inc. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 15 * 16 * * Redistributions of source code must retain the above copyright notice, 17 * this list of conditions and the following disclaimer. 18 * * Redistributions in binary form must reproduce the above copyright notice, 19 * this list of conditions and the following disclaimer in the documentation 20 * and/or other materials provided with the distribution. 21 * * Neither the name of Lockless Inc. nor the names of its contributors may be 22 * used to endorse or promote products derived from this software without 23 * specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AN ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 36 * OF THE POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * You may want to use the MingW64 winpthreads library instead. 41 * It is based on this, but adds error checking. 42 */ 43 44 /* 45 * Version 1.0.1 Released 2 Feb 2012 46 * Fixes pthread_barrier_destroy() to wait for threads to exit the barrier. 47 */ 48 49 #ifndef WIN_PTHREADS 50 #define WIN_PTHREADS 51 52 #include
53 #include
54 55 #include
56 #include
57 #include
58 59 #if !defined(__MINGW32__) /* XXX 64? */ 60 #define ETIMEDOUT 110 61 #define ENOTSUP 134 62 #endif 63 64 #define PTHREAD_CANCEL_DISABLE 0 65 #define PTHREAD_CANCEL_ENABLE 0x01 66 67 #define PTHREAD_CANCEL_DEFERRED 0 68 #define PTHREAD_CANCEL_ASYNCHRONOUS 0x02 69 70 #define PTHREAD_CREATE_JOINABLE 0 71 #define PTHREAD_CREATE_DETACHED 0x04 72 73 #define PTHREAD_EXPLICT_SCHED 0 74 #define PTHREAD_INHERIT_SCHED 0x08 75 76 #define PTHREAD_SCOPE_PROCESS 0 77 #define PTHREAD_SCOPE_SYSTEM 0x10 78 79 #define PTHREAD_DEFAULT_ATTR (PTHREAD_CANCEL_ENABLE) 80 81 #define PTHREAD_CANCELED ((void *) 0xDEADBEEF) 82 83 #define PTHREAD_ONCE_INIT 0 84 #define PTHREAD_MUTEX_INITIALIZER {(void *) -1, -1, 0, 0, 0, 0} 85 #define PTHREAD_RWLOCK_INITIALIZER {0} 86 #define PTHREAD_COND_INITIALIZER {0} 87 #define PTHREAD_BARRIER_INITIALIZER \ 88 {0, 0, PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER} 89 #define PTHREAD_SPINLOCK_INITIALIZER 0 90 91 #define PTHREAD_DESTRUCTOR_ITERATIONS 256 92 #define PTHREAD_KEYS_MAX (1<<20) 93 94 #define PTHREAD_MUTEX_NORMAL 0 95 #define PTHREAD_MUTEX_ERRORCHECK 1 96 #define PTHREAD_MUTEX_RECURSIVE 2 97 #define PTHREAD_MUTEX_DEFAULT 3 98 #define PTHREAD_MUTEX_SHARED 4 99 #define PTHREAD_MUTEX_PRIVATE 0 100 #define PTHREAD_PRIO_NONE 0 101 #define PTHREAD_PRIO_INHERIT 8 102 #define PTHREAD_PRIO_PROTECT 16 103 #define PTHREAD_PRIO_MULT 32 104 #define PTHREAD_PROCESS_SHARED 0 105 #define PTHREAD_PROCESS_PRIVATE 1 106 107 #define PTHREAD_BARRIER_SERIAL_THREAD 1 108 109 #if !defined(__MINGW32__) 110 /* Windows doesn't have this, so declare it ourselves. */ 111 struct timespec { 112 /* long long in windows is the same as long in unix for 64bit */ 113 long long tv_sec; 114 long long tv_nsec; 115 }; 116 #endif 117 118 typedef struct _pthread_cleanup _pthread_cleanup; 119 struct _pthread_cleanup { 120 void (*func) (void *); 121 void *arg; 122 _pthread_cleanup *next; 123 }; 124 125 struct _pthread_v { 126 void *ret_arg; 127 void *(*func) (void *); 128 _pthread_cleanup *clean; 129 uintptr_t h; 130 int cancelled; 131 unsigned p_state; 132 int keymax; 133 void **keyval; 134 135 jmp_buf jb; 136 }; 137 138 typedef struct _pthread_v *pthread_t; 139 140 #if defined(__MINGW32__) 141 #include
142 143 typedef struct _RTL_CONDITION_VARIABLE { 144 PVOID Ptr; 145 } CONDITION_VARIABLE, *PCONDITION_VARIABLE; 146 147 typedef struct _RTL_SRWLOCK { 148 PVOID Ptr; 149 } SRWLOCK, *PSRWLOCK; 150 151 #endif 152 153 typedef struct pthread_barrier_t pthread_barrier_t; 154 struct pthread_barrier_t { 155 int count; 156 int total; 157 CRITICAL_SECTION m; 158 CONDITION_VARIABLE cv; 159 }; 160 161 typedef struct pthread_attr_t pthread_attr_t; 162 struct pthread_attr_t { 163 unsigned p_state; 164 void *stack; 165 size_t s_size; 166 }; 167 168 typedef long pthread_once_t; 169 typedef unsigned pthread_mutexattr_t; 170 typedef SRWLOCK pthread_rwlock_t; 171 typedef CRITICAL_SECTION pthread_mutex_t; 172 typedef unsigned pthread_key_t; 173 typedef void *pthread_barrierattr_t; 174 typedef long pthread_spinlock_t; 175 typedef int pthread_condattr_t; 176 typedef CONDITION_VARIABLE pthread_cond_t; 177 typedef int pthread_rwlockattr_t; 178 179 volatile long _pthread_cancelling; 180 181 int _pthread_concur; 182 183 /* Will default to zero as needed */ 184 pthread_once_t _pthread_tls_once; 185 DWORD _pthread_tls; 186 187 /* Note initializer is zero, so this works */ 188 pthread_rwlock_t _pthread_key_lock; 189 long _pthread_key_max; 190 long _pthread_key_sch; 191 void (**_pthread_key_dest) (void *); 192 193 #define pthread_cleanup_push(F, A) \ 194 do { \ 195 const _pthread_cleanup _pthread_cup = {(F), (A), \ 196 pthread_self()->clean}; \ 197 _ReadWriteBarrier(); \ 198 pthread_self()->clean = (_pthread_cleanup *) &_pthread_cup; \ 199 _ReadWriteBarrier(); \ 200 } while (0) 201 202 #define pthread_cleanup_pop(E) \ 203 do { \ 204 _pthread_cleanup *_pthread_cup = pthread_self()->clean; \ 205 if (_pthread_cup) { \ 206 _pthread_cup->func(_pthread_cup->arg); \ 207 pthread_self()->clean = _pthread_cup->next; \ 208 } \ 209 } while (0) 210 211 static void 212 _pthread_once_cleanup(void *arg) 213 { 214 pthread_once_t *o = (pthread_once_t *) arg; 215 *o = 0; 216 } 217 218 static pthread_t pthread_self(void); 219 220 static int 221 pthread_once(pthread_once_t *o, void (*func) (void)) 222 { 223 long state = *o; 224 225 _ReadWriteBarrier(); 226 227 while (state != 1) { 228 if (!state) { 229 if (!_InterlockedCompareExchange(o, 2, 0)) { 230 /* Success */ 231 pthread_cleanup_push(_pthread_once_cleanup, o); 232 func(); 233 pthread_cleanup_pop(0); 234 235 /* Mark as done */ 236 *o = 1; 237 238 return 0; 239 } 240 } 241 242 YieldProcessor(); 243 244 _ReadWriteBarrier(); 245 246 state = *o; 247 } 248 249 /* Done */ 250 return 0; 251 } 252 253 static int 254 _pthread_once_raw(pthread_once_t *o, void (*func) (void)) 255 { 256 long state = *o; 257 258 _ReadWriteBarrier(); 259 260 while (state != 1) { 261 if (!state) { 262 if (!_InterlockedCompareExchange(o, 2, 0)) { 263 /* Success */ 264 func(); 265 266 /* Mark as done */ 267 *o = 1; 268 269 return 0; 270 } 271 } 272 273 YieldProcessor(); 274 275 _ReadWriteBarrier(); 276 277 state = *o; 278 } 279 280 /* Done */ 281 return 0; 282 } 283 284 static int 285 pthread_mutex_lock(pthread_mutex_t *m) 286 { 287 EnterCriticalSection(m); 288 return 0; 289 } 290 291 static int 292 pthread_mutex_unlock(pthread_mutex_t *m) 293 { 294 LeaveCriticalSection(m); 295 return 0; 296 } 297 298 static int 299 pthread_mutex_trylock(pthread_mutex_t *m) 300 { 301 return TryEnterCriticalSection(m) ? 0 : EBUSY; 302 } 303 304 static int 305 pthread_mutex_init(pthread_mutex_t *m, pthread_mutexattr_t *a) 306 { 307 (void)a; 308 InitializeCriticalSection(m); 309 310 return 0; 311 } 312 313 static int 314 pthread_mutex_destroy(pthread_mutex_t *m) 315 { 316 DeleteCriticalSection(m); 317 return 0; 318 } 319 320 #define pthread_mutex_getprioceiling(M, P) ENOTSUP 321 #define pthread_mutex_setprioceiling(M, P) ENOTSUP 322 323 static int pthread_equal(pthread_t t1, pthread_t t2) 324 { 325 return t1 == t2; 326 } 327 328 static void pthread_testcancel(void); 329 330 static int 331 pthread_rwlock_init(pthread_rwlock_t *l, pthread_rwlockattr_t *a) 332 { 333 (void)a; 334 InitializeSRWLock(l); 335 336 return 0; 337 } 338 339 static int 340 pthread_rwlock_destroy(pthread_rwlock_t *l) 341 { 342 (void)*l; 343 return 0; 344 } 345 346 static int 347 pthread_rwlock_rdlock(pthread_rwlock_t *l) 348 { 349 pthread_testcancel(); 350 AcquireSRWLockShared(l); 351 352 return 0; 353 } 354 355 static int 356 pthread_rwlock_wrlock(pthread_rwlock_t *l) 357 { 358 pthread_testcancel(); 359 AcquireSRWLockExclusive(l); 360 361 return 0; 362 } 363 364 static int 365 pthread_rwlock_unlock(pthread_rwlock_t *l) 366 { 367 void *state = *(void **)l; 368 369 if (state == (void *)1) { 370 /* Known to be an exclusive lock */ 371 ReleaseSRWLockExclusive(l); 372 } else { 373 /* A shared unlock will work */ 374 ReleaseSRWLockShared(l); 375 } 376 377 return 0; 378 } 379 380 static void 381 pthread_tls_init(void) 382 { 383 _pthread_tls = TlsAlloc(); 384 385 /* Cannot continue if out of indexes */ 386 if (_pthread_tls == TLS_OUT_OF_INDEXES) 387 abort(); 388 } 389 390 static void 391 _pthread_cleanup_dest(pthread_t t) 392 { 393 int i, j; 394 395 for (j = 0; j < PTHREAD_DESTRUCTOR_ITERATIONS; j++) { 396 int flag = 0; 397 398 for (i = 0; i < t->keymax; i++) { 399 void *val = t->keyval[i]; 400 401 if (val) { 402 pthread_rwlock_rdlock(&_pthread_key_lock); 403 if ((uintptr_t) _pthread_key_dest[i] > 1) { 404 /* Call destructor */ 405 t->keyval[i] = NULL; 406 _pthread_key_dest[i] (val); 407 flag = 1; 408 } 409 pthread_rwlock_unlock(&_pthread_key_lock); 410 } 411 } 412 413 /* Nothing to do? */ 414 if (!flag) 415 return; 416 } 417 } 418 419 static 420 pthread_t pthread_self(void) 421 { 422 pthread_t t; 423 424 _pthread_once_raw(&_pthread_tls_once, pthread_tls_init); 425 426 t = TlsGetValue(_pthread_tls); 427 428 /* Main thread? */ 429 if (!t) { 430 t = malloc(sizeof(struct _pthread_v)); 431 432 /* If cannot initialize main thread, then the only thing we 433 * can do is abort */ 434 if (!t) 435 abort(); 436 437 t->ret_arg = NULL; 438 t->func = NULL; 439 t->clean = NULL; 440 t->cancelled = 0; 441 t->p_state = PTHREAD_DEFAULT_ATTR; 442 t->keymax = 0; 443 t->keyval = NULL; 444 t->h = (uintptr_t) GetCurrentThread(); 445 446 /* Save for later */ 447 TlsSetValue(_pthread_tls, t); 448 449 if (setjmp(t->jb)) { 450 /* Make sure we free ourselves if we are detached */ 451 if (!t->h) 452 free(t); 453 454 /* Time to die */ 455 _endthreadex(0); 456 } 457 } 458 459 return t; 460 } 461 462 static int 463 pthread_rwlock_tryrdlock(pthread_rwlock_t *l) 464 { 465 /* Get the current state of the lock */ 466 void *state = *(void **)l; 467 468 if (!state) { 469 /* Unlocked to locked */ 470 if (!_InterlockedCompareExchangePointer 471 ((void *)l, (void *)0x11, NULL)) 472 return 0; 473 return EBUSY; 474 } 475 476 /* A single writer exists */ 477 if (state == (void *)1) 478 return EBUSY; 479 480 /* Multiple writers exist? */ 481 if ((uintptr_t) state & 14) 482 return EBUSY; 483 484 if (_InterlockedCompareExchangePointer 485 ((void *)l, (void *)((uintptr_t) state + 16), state) == state) 486 return 0; 487 488 return EBUSY; 489 } 490 491 static int 492 pthread_rwlock_trywrlock(pthread_rwlock_t *l) 493 { 494 /* Try to grab lock if it has no users */ 495 if (!_InterlockedCompareExchangePointer((void *)l, (void *)1, NULL)) 496 return 0; 497 498 return EBUSY; 499 } 500 501 static unsigned long long 502 _pthread_time_in_ms(void) 503 { 504 struct __timeb64 tb; 505 506 _ftime64(&tb); 507 508 return tb.time * 1000 + tb.millitm; 509 } 510 511 static unsigned long long 512 _pthread_time_in_ms_from_timespec(const struct timespec *ts) 513 { 514 unsigned long long t = ts->tv_sec * 1000; 515 t += ts->tv_nsec / 1000000; 516 517 return t; 518 } 519 520 static unsigned long long 521 _pthread_rel_time_in_ms(const struct timespec *ts) 522 { 523 unsigned long long t1 = _pthread_time_in_ms_from_timespec(ts); 524 unsigned long long t2 = _pthread_time_in_ms(); 525 526 /* Prevent underflow */ 527 if (t1 < t2) 528 return 0; 529 return t1 - t2; 530 } 531 532 static int 533 pthread_rwlock_timedrdlock(pthread_rwlock_t *l, 534 const struct timespec *ts) 535 { 536 unsigned long long ct = _pthread_time_in_ms(); 537 unsigned long long t = _pthread_time_in_ms_from_timespec(ts); 538 539 pthread_testcancel(); 540 541 /* Use a busy-loop */ 542 while (1) { 543 /* Try to grab lock */ 544 if (!pthread_rwlock_tryrdlock(l)) 545 return 0; 546 547 /* Get current time */ 548 ct = _pthread_time_in_ms(); 549 550 /* Have we waited long enough? */ 551 if (ct > t) 552 return ETIMEDOUT; 553 } 554 } 555 556 static int 557 pthread_rwlock_timedwrlock(pthread_rwlock_t *l, 558 const struct timespec *ts) 559 { 560 unsigned long long ct = _pthread_time_in_ms(); 561 unsigned long long t = _pthread_time_in_ms_from_timespec(ts); 562 563 pthread_testcancel(); 564 565 /* Use a busy-loop */ 566 while (1) { 567 /* Try to grab lock */ 568 if (!pthread_rwlock_trywrlock(l)) 569 return 0; 570 571 /* Get current time */ 572 ct = _pthread_time_in_ms(); 573 574 /* Have we waited long enough? */ 575 if (ct > t) 576 return ETIMEDOUT; 577 } 578 } 579 580 static int 581 pthread_get_concurrency(int *val) 582 { 583 *val = _pthread_concur; 584 return 0; 585 } 586 587 static int 588 pthread_set_concurrency(int val) 589 { 590 _pthread_concur = val; 591 return 0; 592 } 593 594 #define pthread_getschedparam(T, P, S) ENOTSUP 595 #define pthread_setschedparam(T, P, S) ENOTSUP 596 #define pthread_getcpuclockid(T, C) ENOTSUP 597 598 static int 599 pthread_exit(void *res) 600 { 601 pthread_t t = pthread_self(); 602 603 t->ret_arg = res; 604 605 _pthread_cleanup_dest(t); 606 607 longjmp(t->jb, 1); 608 } 609 610 static void 611 _pthread_invoke_cancel(void) 612 { 613 _pthread_cleanup *pcup; 614 615 _InterlockedDecrement(&_pthread_cancelling); 616 617 /* Call cancel queue */ 618 for (pcup = pthread_self()->clean; pcup; pcup = pcup->next) { 619 /* suppress block warning */ 620 pcup->func(pcup->arg); 621 } 622 623 pthread_exit(PTHREAD_CANCELED); 624 } 625 626 static void 627 pthread_testcancel(void) 628 { 629 if (_pthread_cancelling) { 630 pthread_t t = pthread_self(); 631 632 if (t->cancelled && (t->p_state & PTHREAD_CANCEL_ENABLE)) 633 _pthread_invoke_cancel(); 634 } 635 } 636 637 static int 638 pthread_cancel(pthread_t t) 639 { 640 if (t->p_state & PTHREAD_CANCEL_ASYNCHRONOUS) { 641 /* Dangerous asynchronous cancelling */ 642 CONTEXT ctxt; 643 644 /* Already done? */ 645 if (t->cancelled) 646 return ESRCH; 647 648 ctxt.ContextFlags = CONTEXT_CONTROL; 649 650 SuspendThread((HANDLE) t->h); 651 GetThreadContext((HANDLE) t->h, &ctxt); 652 #ifdef _M_X64 653 ctxt.Rip = (uintptr_t) _pthread_invoke_cancel; 654 #else 655 ctxt.Eip = (uintptr_t) _pthread_invoke_cancel; 656 #endif 657 SetThreadContext((HANDLE) t->h, &ctxt); 658 659 /* Also try deferred Cancelling */ 660 t->cancelled = 1; 661 662 /* Notify everyone to look */ 663 _InterlockedIncrement(&_pthread_cancelling); 664 665 ResumeThread((HANDLE) t->h); 666 } else { 667 /* Safe deferred Cancelling */ 668 t->cancelled = 1; 669 670 /* Notify everyone to look */ 671 _InterlockedIncrement(&_pthread_cancelling); 672 } 673 674 return 0; 675 } 676 677 static unsigned 678 _pthread_get_state(pthread_attr_t *attr, unsigned flag) 679 { 680 return attr->p_state & flag; 681 } 682 683 static int 684 _pthread_set_state(pthread_attr_t *attr, unsigned flag, 685 unsigned val) 686 { 687 if (~flag & val) 688 return EINVAL; 689 attr->p_state &= ~flag; 690 attr->p_state |= val; 691 692 return 0; 693 } 694 695 static int 696 pthread_attr_init(pthread_attr_t *attr) 697 { 698 attr->p_state = PTHREAD_DEFAULT_ATTR; 699 attr->stack = NULL; 700 attr->s_size = 0; 701 return 0; 702 } 703 704 static int 705 pthread_attr_destroy(pthread_attr_t *attr) 706 { 707 /* No need to do anything */ 708 return 0; 709 } 710 711 static int 712 pthread_attr_setdetachstate(pthread_attr_t *a, int flag) 713 { 714 return _pthread_set_state(a, PTHREAD_CREATE_DETACHED, flag); 715 } 716 717 static int 718 pthread_attr_getdetachstate(pthread_attr_t *a, int *flag) 719 { 720 *flag = _pthread_get_state(a, PTHREAD_CREATE_DETACHED); 721 return 0; 722 } 723 724 static int 725 pthread_attr_setinheritsched(pthread_attr_t *a, int flag) 726 { 727 return _pthread_set_state(a, PTHREAD_INHERIT_SCHED, flag); 728 } 729 730 static int 731 pthread_attr_getinheritsched(pthread_attr_t *a, int *flag) 732 { 733 *flag = _pthread_get_state(a, PTHREAD_INHERIT_SCHED); 734 return 0; 735 } 736 737 static int 738 pthread_attr_setscope(pthread_attr_t *a, int flag) 739 { 740 return _pthread_set_state(a, PTHREAD_SCOPE_SYSTEM, flag); 741 } 742 743 static int 744 pthread_attr_getscope(pthread_attr_t *a, int *flag) 745 { 746 *flag = _pthread_get_state(a, PTHREAD_SCOPE_SYSTEM); 747 return 0; 748 } 749 750 static int 751 pthread_attr_getstackaddr(pthread_attr_t *attr, void **stack) 752 { 753 *stack = attr->stack; 754 return 0; 755 } 756 757 static int 758 pthread_attr_setstackaddr(pthread_attr_t *attr, void *stack) 759 { 760 attr->stack = stack; 761 return 0; 762 } 763 764 static int 765 pthread_attr_getstacksize(pthread_attr_t *attr, size_t *size) 766 { 767 *size = attr->s_size; 768 return 0; 769 } 770 771 static int 772 pthread_attr_setstacksize(pthread_attr_t *attr, size_t size) 773 { 774 attr->s_size = size; 775 return 0; 776 } 777 778 #define pthread_attr_getguardsize(A, S) ENOTSUP 779 #define pthread_attr_setgaurdsize(A, S) ENOTSUP 780 #define pthread_attr_getschedparam(A, S) ENOTSUP 781 #define pthread_attr_setschedparam(A, S) ENOTSUP 782 #define pthread_attr_getschedpolicy(A, S) ENOTSUP 783 #define pthread_attr_setschedpolicy(A, S) ENOTSUP 784 785 static int 786 pthread_setcancelstate(int state, int *oldstate) 787 { 788 pthread_t t = pthread_self(); 789 790 if ((state & PTHREAD_CANCEL_ENABLE) != state) 791 return EINVAL; 792 if (oldstate) 793 *oldstate = t->p_state & PTHREAD_CANCEL_ENABLE; 794 t->p_state &= ~PTHREAD_CANCEL_ENABLE; 795 t->p_state |= state; 796 797 return 0; 798 } 799 800 static int 801 pthread_setcanceltype(int type, int *oldtype) 802 { 803 pthread_t t = pthread_self(); 804 805 if ((type & PTHREAD_CANCEL_ASYNCHRONOUS) != type) 806 return EINVAL; 807 if (oldtype) 808 *oldtype = t->p_state & PTHREAD_CANCEL_ASYNCHRONOUS; 809 t->p_state &= ~PTHREAD_CANCEL_ASYNCHRONOUS; 810 t->p_state |= type; 811 812 return 0; 813 } 814 815 static unsigned int 816 pthread_create_wrapper(void *args) 817 { 818 struct _pthread_v *tv = args; 819 int i, j; 820 821 _pthread_once_raw(&_pthread_tls_once, pthread_tls_init); 822 823 TlsSetValue(_pthread_tls, tv); 824 825 if (!setjmp(tv->jb)) { 826 /* Call function and save return value */ 827 tv->ret_arg = tv->func(tv->ret_arg); 828 829 /* Clean up destructors */ 830 _pthread_cleanup_dest(tv); 831 } 832 833 /* If we exit too early, then we can race with create */ 834 while ((HANDLE) tv->h == (HANDLE) - 1) { 835 YieldProcessor(); 836 _ReadWriteBarrier(); 837 } 838 839 /* Make sure we free ourselves if we are detached */ 840 if (!tv->h) 841 free(tv); 842 843 return 0; 844 } 845 846 static int 847 pthread_create(pthread_t *th, pthread_attr_t *attr, 848 void *(*func) (void *), void *arg) 849 { 850 struct _pthread_v *tv = malloc(sizeof(struct _pthread_v)); 851 unsigned ssize = 0; 852 853 if (!tv) 854 return 1; 855 856 *th = tv; 857 858 /* Save data in pthread_t */ 859 tv->ret_arg = arg; 860 tv->func = func; 861 tv->clean = NULL; 862 tv->cancelled = 0; 863 tv->p_state = PTHREAD_DEFAULT_ATTR; 864 tv->keymax = 0; 865 tv->keyval = NULL; 866 tv->h = (uintptr_t) -1; 867 868 if (attr) { 869 tv->p_state = attr->p_state; 870 ssize = attr->s_size; 871 } 872 873 /* Make sure tv->h has value of -1 */ 874 _ReadWriteBarrier(); 875 876 tv->h = 877 _beginthreadex(NULL, ssize, pthread_create_wrapper, tv, 0, NULL); 878 879 /* Failed */ 880 if (!tv->h) 881 return 1; 882 883 if (tv->p_state & PTHREAD_CREATE_DETACHED) { 884 CloseHandle((HANDLE) tv->h); 885 _ReadWriteBarrier(); 886 tv->h = 0; 887 } 888 889 return 0; 890 } 891 892 static int 893 pthread_join(pthread_t t, void **res) 894 { 895 struct _pthread_v *tv = t; 896 897 pthread_testcancel(); 898 899 WaitForSingleObject((HANDLE) tv->h, INFINITE); 900 CloseHandle((HANDLE) tv->h); 901 902 /* Obtain return value */ 903 if (res) 904 *res = tv->ret_arg; 905 906 free(tv); 907 908 return 0; 909 } 910 911 static int 912 pthread_detach(pthread_t t) 913 { 914 struct _pthread_v *tv = t; 915 916 /* 917 * This can't race with thread exit because 918 * our call would be undefined if called on a dead thread. 919 */ 920 921 CloseHandle((HANDLE) tv->h); 922 _ReadWriteBarrier(); 923 tv->h = 0; 924 925 return 0; 926 } 927 928 static int 929 pthread_mutexattr_init(pthread_mutexattr_t *a) 930 { 931 *a = 0; 932 return 0; 933 } 934 935 static int 936 pthread_mutexattr_destroy(pthread_mutexattr_t *a) 937 { 938 (void)a; 939 return 0; 940 } 941 942 static int 943 pthread_mutexattr_gettype(pthread_mutexattr_t *a, int *type) 944 { 945 *type = *a & 3; 946 947 return 0; 948 } 949 950 static int 951 pthread_mutexattr_settype(pthread_mutexattr_t *a, int type) 952 { 953 if ((unsigned)type > 3) 954 return EINVAL; 955 *a &= ~3; 956 *a |= type; 957 958 return 0; 959 } 960 961 static int 962 pthread_mutexattr_getpshared(pthread_mutexattr_t *a, int *type) 963 { 964 *type = *a & 4; 965 966 return 0; 967 } 968 969 static int 970 pthread_mutexattr_setpshared(pthread_mutexattr_t *a, int type) 971 { 972 if ((type & 4) != type) 973 return EINVAL; 974 975 *a &= ~4; 976 *a |= type; 977 978 return 0; 979 } 980 981 static int 982 pthread_mutexattr_getprotocol(pthread_mutexattr_t *a, int *type) 983 { 984 *type = *a & (8 + 16); 985 986 return 0; 987 } 988 989 static int 990 pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int type) 991 { 992 if ((type & (8 + 16)) != 8 + 16) 993 return EINVAL; 994 995 *a &= ~(8 + 16); 996 *a |= type; 997 998 return 0; 999 } 1000 1001 static int 1002 pthread_mutexattr_getprioceiling(pthread_mutexattr_t *a, int *prio) 1003 { 1004 *prio = *a / PTHREAD_PRIO_MULT; 1005 return 0; 1006 } 1007 1008 static int 1009 pthread_mutexattr_setprioceiling(pthread_mutexattr_t *a, int prio) 1010 { 1011 *a &= (PTHREAD_PRIO_MULT - 1); 1012 *a += prio * PTHREAD_PRIO_MULT; 1013 1014 return 0; 1015 } 1016 1017 static int 1018 pthread_mutex_timedlock(pthread_mutex_t *m, struct timespec *ts) 1019 { 1020 unsigned long long t, ct; 1021 1022 struct _pthread_crit_t { 1023 void *debug; 1024 LONG count; 1025 LONG r_count; 1026 HANDLE owner; 1027 HANDLE sem; 1028 ULONG_PTR spin; 1029 }; 1030 1031 /* Try to lock it without waiting */ 1032 if (!pthread_mutex_trylock(m)) 1033 return 0; 1034 1035 ct = _pthread_time_in_ms(); 1036 t = _pthread_time_in_ms_from_timespec(ts); 1037 1038 while (1) { 1039 /* Have we waited long enough? */ 1040 if (ct > t) 1041 return ETIMEDOUT; 1042 1043 /* Wait on semaphore within critical section */ 1044 WaitForSingleObject(((struct _pthread_crit_t *)m)->sem, t - ct); 1045 1046 /* Try to grab lock */ 1047 if (!pthread_mutex_trylock(m)) 1048 return 0; 1049 1050 /* Get current time */ 1051 ct = _pthread_time_in_ms(); 1052 } 1053 } 1054 1055 #define _PTHREAD_BARRIER_FLAG (1<<30) 1056 1057 static int 1058 pthread_barrier_destroy(pthread_barrier_t *b) 1059 { 1060 EnterCriticalSection(&b->m); 1061 1062 while (b->total > _PTHREAD_BARRIER_FLAG) { 1063 /* Wait until everyone exits the barrier */ 1064 SleepConditionVariableCS(&b->cv, &b->m, INFINITE); 1065 } 1066 1067 LeaveCriticalSection(&b->m); 1068 1069 DeleteCriticalSection(&b->m); 1070 1071 return 0; 1072 } 1073 1074 static int 1075 pthread_barrier_init(pthread_barrier_t *b, void *attr, int count) 1076 { 1077 /* Ignore attr */ 1078 (void)attr; 1079 1080 b->count = count; 1081 b->total = 0; 1082 1083 InitializeCriticalSection(&b->m); 1084 InitializeConditionVariable(&b->cv); 1085 1086 return 0; 1087 } 1088 1089 static int 1090 pthread_barrier_wait(pthread_barrier_t *b) 1091 { 1092 EnterCriticalSection(&b->m); 1093 1094 while (b->total > _PTHREAD_BARRIER_FLAG) { 1095 /* Wait until everyone exits the barrier */ 1096 SleepConditionVariableCS(&b->cv, &b->m, INFINITE); 1097 } 1098 1099 /* Are we the first to enter? */ 1100 if (b->total == _PTHREAD_BARRIER_FLAG) 1101 b->total = 0; 1102 1103 b->total++; 1104 1105 if (b->total == b->count) { 1106 b->total += _PTHREAD_BARRIER_FLAG - 1; 1107 WakeAllConditionVariable(&b->cv); 1108 1109 LeaveCriticalSection(&b->m); 1110 1111 return 1; 1112 } else { 1113 while (b->total < _PTHREAD_BARRIER_FLAG) { 1114 /* Wait until enough threads enter the barrier */ 1115 SleepConditionVariableCS(&b->cv, &b->m, INFINITE); 1116 } 1117 1118 b->total--; 1119 1120 /* Get entering threads to wake up */ 1121 if (b->total == _PTHREAD_BARRIER_FLAG) 1122 WakeAllConditionVariable(&b->cv); 1123 1124 LeaveCriticalSection(&b->m); 1125 1126 return 0; 1127 } 1128 } 1129 1130 static int 1131 pthread_barrierattr_init(void **attr) 1132 { 1133 *attr = NULL; 1134 return 0; 1135 } 1136 1137 static int 1138 pthread_barrierattr_destroy(void **attr) 1139 { 1140 /* Ignore attr */ 1141 (void)attr; 1142 1143 return 0; 1144 } 1145 1146 static int 1147 pthread_barrierattr_setpshared(void **attr, int s) 1148 { 1149 *attr = (void *)(uintptr_t) s; 1150 return 0; 1151 } 1152 1153 static int 1154 pthread_barrierattr_getpshared(void **attr, int *s) 1155 { 1156 *s = (int)(size_t) *attr; 1157 1158 return 0; 1159 } 1160 1161 static int 1162 pthread_key_create(pthread_key_t *key, void (*dest) (void *)) 1163 { 1164 int i; 1165 long nmax; 1166 void (**d) (void *); 1167 1168 if (!key) 1169 return EINVAL; 1170 1171 pthread_rwlock_wrlock(&_pthread_key_lock); 1172 1173 for (i = _pthread_key_sch; i < _pthread_key_max; i++) { 1174 if (!_pthread_key_dest[i]) { 1175 *key = i; 1176 if (dest) 1177 _pthread_key_dest[i] = dest; 1178 else 1179 _pthread_key_dest[i] = (void (*)(void *))1; 1180 pthread_rwlock_unlock(&_pthread_key_lock); 1181 1182 return 0; 1183 } 1184 } 1185 1186 for (i = 0; i < _pthread_key_sch; i++) { 1187 if (!_pthread_key_dest[i]) { 1188 *key = i; 1189 if (dest) 1190 _pthread_key_dest[i] = dest; 1191 else 1192 _pthread_key_dest[i] = (void (*)(void *))1; 1193 pthread_rwlock_unlock(&_pthread_key_lock); 1194 1195 return 0; 1196 } 1197 } 1198 1199 if (!_pthread_key_max) 1200 _pthread_key_max = 1; 1201 if (_pthread_key_max == PTHREAD_KEYS_MAX) { 1202 pthread_rwlock_unlock(&_pthread_key_lock); 1203 return ENOMEM; 1204 } 1205 1206 nmax = _pthread_key_max * 2; 1207 if (nmax > PTHREAD_KEYS_MAX) 1208 nmax = PTHREAD_KEYS_MAX; 1209 1210 /* No spare room anywhere */ 1211 d = realloc(_pthread_key_dest, nmax * sizeof(*d)); 1212 if (!d) { 1213 pthread_rwlock_unlock(&_pthread_key_lock); 1214 return ENOMEM; 1215 } 1216 1217 /* Clear new region */ 1218 memset((void *)&d[_pthread_key_max], 0, 1219 (nmax - _pthread_key_max) * sizeof(void *)); 1220 1221 /* Use new region */ 1222 _pthread_key_dest = d; 1223 _pthread_key_sch = _pthread_key_max + 1; 1224 *key = _pthread_key_max; 1225 _pthread_key_max = nmax; 1226 1227 if (dest) 1228 _pthread_key_dest[*key] = dest; 1229 else 1230 _pthread_key_dest[*key] = (void (*)(void *))1; 1231 pthread_rwlock_unlock(&_pthread_key_lock); 1232 1233 return 0; 1234 } 1235 1236 static int 1237 pthread_key_delete(pthread_key_t key) 1238 { 1239 if (key > _pthread_key_max) 1240 return EINVAL; 1241 if (!_pthread_key_dest) 1242 return EINVAL; 1243 1244 pthread_rwlock_wrlock(&_pthread_key_lock); 1245 _pthread_key_dest[key] = NULL; 1246 1247 /* Start next search from our location */ 1248 if (_pthread_key_sch > key) 1249 _pthread_key_sch = key; 1250 1251 pthread_rwlock_unlock(&_pthread_key_lock); 1252 1253 return 0; 1254 } 1255 1256 static void * 1257 pthread_getspecific(pthread_key_t key) 1258 { 1259 pthread_t t = pthread_self(); 1260 1261 if (key >= t->keymax) 1262 return NULL; 1263 1264 return t->keyval[key]; 1265 1266 } 1267 1268 static int 1269 pthread_setspecific(pthread_key_t key, const void *value) 1270 { 1271 pthread_t t = pthread_self(); 1272 1273 if (key > t->keymax) { 1274 int keymax = (key + 1) * 2; 1275 void **kv = realloc(t->keyval, keymax * sizeof(void *)); 1276 1277 if (!kv) 1278 return ENOMEM; 1279 1280 /* Clear new region */ 1281 memset(&kv[t->keymax], 0, 1282 (keymax - t->keymax) * sizeof(void *)); 1283 1284 t->keyval = kv; 1285 t->keymax = keymax; 1286 } 1287 1288 t->keyval[key] = (void *)value; 1289 1290 return 0; 1291 } 1292 1293 static int 1294 pthread_spin_init(pthread_spinlock_t *l, int pshared) 1295 { 1296 (void)pshared; 1297 1298 *l = 0; 1299 return 0; 1300 } 1301 1302 static int 1303 pthread_spin_destroy(pthread_spinlock_t *l) 1304 { 1305 (void)l; 1306 return 0; 1307 } 1308 1309 /* No-fair spinlock due to lack of knowledge of thread number */ 1310 static int 1311 pthread_spin_lock(pthread_spinlock_t *l) 1312 { 1313 while (_InterlockedExchange(l, EBUSY)) { 1314 /* Don't lock the bus whilst waiting */ 1315 while (*l) { 1316 YieldProcessor(); 1317 1318 /* Compiler barrier. Prevent caching of *l */ 1319 _ReadWriteBarrier(); 1320 } 1321 } 1322 1323 return 0; 1324 } 1325 1326 static int 1327 pthread_spin_trylock(pthread_spinlock_t *l) 1328 { 1329 return _InterlockedExchange(l, EBUSY); 1330 } 1331 1332 static int 1333 pthread_spin_unlock(pthread_spinlock_t *l) 1334 { 1335 /* Compiler barrier. The store below acts with release symmantics */ 1336 _ReadWriteBarrier(); 1337 1338 *l = 0; 1339 1340 return 0; 1341 } 1342 1343 static int 1344 pthread_cond_init(pthread_cond_t *c, pthread_condattr_t *a) 1345 { 1346 (void)a; 1347 1348 InitializeConditionVariable(c); 1349 return 0; 1350 } 1351 1352 static int 1353 pthread_cond_signal(pthread_cond_t *c) 1354 { 1355 WakeConditionVariable(c); 1356 return 0; 1357 } 1358 1359 static int 1360 pthread_cond_broadcast(pthread_cond_t *c) 1361 { 1362 WakeAllConditionVariable(c); 1363 return 0; 1364 } 1365 1366 static int 1367 pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m) 1368 { 1369 pthread_testcancel(); 1370 SleepConditionVariableCS(c, m, INFINITE); 1371 return 0; 1372 } 1373 1374 static int 1375 pthread_cond_destroy(pthread_cond_t *c) 1376 { 1377 (void)c; 1378 return 0; 1379 } 1380 1381 static int 1382 pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, 1383 struct timespec *t) 1384 { 1385 unsigned long long tm = _pthread_rel_time_in_ms(t); 1386 1387 pthread_testcancel(); 1388 1389 if (!SleepConditionVariableCS(c, m, tm)) 1390 return ETIMEDOUT; 1391 1392 /* We can have a spurious wakeup after the timeout */ 1393 if (!_pthread_rel_time_in_ms(t)) 1394 return ETIMEDOUT; 1395 1396 return 0; 1397 } 1398 1399 static int 1400 pthread_condattr_destroy(pthread_condattr_t *a) 1401 { 1402 (void)a; 1403 return 0; 1404 } 1405 1406 #define pthread_condattr_getclock(A, C) ENOTSUP 1407 #define pthread_condattr_setclock(A, C) ENOTSUP 1408 1409 static int 1410 pthread_condattr_init(pthread_condattr_t *a) 1411 { 1412 *a = 0; 1413 return 0; 1414 } 1415 1416 static int 1417 pthread_condattr_getpshared(pthread_condattr_t *a, int *s) 1418 { 1419 *s = *a; 1420 return 0; 1421 } 1422 1423 static int 1424 pthread_condattr_setpshared(pthread_condattr_t *a, int s) 1425 { 1426 *a = s; 1427 return 0; 1428 } 1429 1430 static int 1431 pthread_rwlockattr_destroy(pthread_rwlockattr_t *a) 1432 { 1433 (void)a; 1434 return 0; 1435 } 1436 1437 static int 1438 pthread_rwlockattr_init(pthread_rwlockattr_t *a) 1439 { 1440 *a = 0; 1441 } 1442 1443 static int 1444 pthread_rwlockattr_getpshared(pthread_rwlockattr_t *a, int *s) 1445 { 1446 *s = *a; 1447 return 0; 1448 } 1449 1450 static int 1451 pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int s) 1452 { 1453 *a = s; 1454 return 0; 1455 } 1456 1457 /* No fork() in windows - so ignore this */ 1458 #define pthread_atfork(F1, F2, F3) 0 1459 1460 /* Windows has rudimentary signals support */ 1461 #define pthread_kill(T, S) 0 1462 #define pthread_sigmask(H, S1, S2) 0 1463 1464 /* Wrap cancellation points -- seems incompatible with decls in stdio.h */ 1465 #define accept(...) (pthread_testcancel(), accept(__VA_ARGS__)) 1466 #define aio_suspend(...) (pthread_testcancel(), aio_suspend(__VA_ARGS__)) 1467 #define clock_nanosleep(...) \ 1468 (pthread_testcancel(), clock_nanosleep(__VA_ARGS__)) 1469 #define close(...) (pthread_testcancel(), close(__VA_ARGS__)) 1470 #define connect(...) (pthread_testcancel(), connect(__VA_ARGS__)) 1471 #define creat(...) (pthread_testcancel(), creat(__VA_ARGS__)) 1472 #define fcntl(...) (pthread_testcancel(), fcntl(__VA_ARGS__)) 1473 #define fdatasync(...) (pthread_testcancel(), fdatasync(__VA_ARGS__)) 1474 #define fsync(...) (pthread_testcancel(), fsync(__VA_ARGS__)) 1475 #define getmsg(...) (pthread_testcancel(), getmsg(__VA_ARGS__)) 1476 #define getpmsg(...) (pthread_testcancel(), getpmsg(__VA_ARGS__)) 1477 #define lockf(...) (pthread_testcancel(), lockf(__VA_ARGS__)) 1478 #define mg_receive(...) (pthread_testcancel(), mg_receive(__VA_ARGS__)) 1479 #define mg_send(...) (pthread_testcancel(), mg_send(__VA_ARGS__)) 1480 #define mg_timedreceive(...) \ 1481 (pthread_testcancel(), mg_timedreceive(__VA_ARGS__)) 1482 #define mg_timessend(...) (pthread_testcancel(), mg_timedsend(__VA_ARGS__)) 1483 #define msgrcv(...) (pthread_testcancel(), msgrecv(__VA_ARGS__)) 1484 #define msgsnd(...) (pthread_testcancel(), msgsnd(__VA_ARGS__)) 1485 #define msync(...) (pthread_testcancel(), msync(__VA_ARGS__)) 1486 #define nanosleep(...) (pthread_testcancel(), nanosleep(__VA_ARGS__)) 1487 #define open(...) (pthread_testcancel(), open(__VA_ARGS__)) 1488 #define pause(...) (pthread_testcancel(), pause(__VA_ARGS__)) 1489 #define poll(...) (pthread_testcancel(), poll(__VA_ARGS__)) 1490 #define pread(...) (pthread_testcancel(), pread(__VA_ARGS__)) 1491 #define pselect(...) (pthread_testcancel(), pselect(__VA_ARGS__)) 1492 #define putmsg(...) (pthread_testcancel(), putmsg(__VA_ARGS__)) 1493 #define putpmsg(...) (pthread_testcancel(), putpmsg(__VA_ARGS__)) 1494 #define pwrite(...) (pthread_testcancel(), pwrite(__VA_ARGS__)) 1495 #define read(...) (pthread_testcancel(), read(__VA_ARGS__)) 1496 #define readv(...) (pthread_testcancel(), readv(__VA_ARGS__)) 1497 #define recv(...) (pthread_testcancel(), recv(__VA_ARGS__)) 1498 #define recvfrom(...) (pthread_testcancel(), recvfrom(__VA_ARGS__)) 1499 #define recvmsg(...) (pthread_testcancel(), recvmsg(__VA_ARGS__)) 1500 #define select(...) (pthread_testcancel(), select(__VA_ARGS__)) 1501 #define sem_timedwait(...) (pthread_testcancel(), sem_timedwait(__VA_ARGS__)) 1502 #define sem_wait(...) (pthread_testcancel(), sem_wait(__VA_ARGS__)) 1503 #define send(...) (pthread_testcancel(), send(__VA_ARGS__)) 1504 #define sendmsg(...) (pthread_testcancel(), sendmsg(__VA_ARGS__)) 1505 #define sendto(...) (pthread_testcancel(), sendto(__VA_ARGS__)) 1506 #define sigpause(...) (pthread_testcancel(), sigpause(__VA_ARGS__)) 1507 #define sigsuspend(...) (pthread_testcancel(), sigsuspend(__VA_ARGS__)) 1508 #define sigwait(...) (pthread_testcancel(), sigwait(__VA_ARGS__)) 1509 #define sigwaitinfo(...) (pthread_testcancel(), sigwaitinfo(__VA_ARGS__)) 1510 #define sleep(...) (pthread_testcancel(), sleep(__VA_ARGS__)) 1511 /* #define Sleep(...) (pthread_testcancel(), Sleep(__VA_ARGS__)) */ 1512 #define system(...) (pthread_testcancel(), system(__VA_ARGS__)) 1513 1514 #define access(...) (pthread_testcancel(), access(__VA_ARGS__)) 1515 #define asctime(...) (pthread_testcancel(), asctime(__VA_ARGS__)) 1516 #define asctime_r(...) (pthread_testcancel(), asctime_r(__VA_ARGS__)) 1517 #define catclose(...) (pthread_testcancel(), catclose(__VA_ARGS__)) 1518 #define catgets(...) (pthread_testcancel(), catgets(__VA_ARGS__)) 1519 #define catopen(...) (pthread_testcancel(), catopen(__VA_ARGS__)) 1520 #define closedir(...) (pthread_testcancel(), closedir(__VA_ARGS__)) 1521 #define closelog(...) (pthread_testcancel(), closelog(__VA_ARGS__)) 1522 #define ctermid(...) (pthread_testcancel(), ctermid(__VA_ARGS__)) 1523 #define ctime(...) (pthread_testcancel(), ctime(__VA_ARGS__)) 1524 #define ctime_r(...) (pthread_testcancel(), ctime_r(__VA_ARGS__)) 1525 #define dbm_close(...) (pthread_testcancel(), dbm_close(__VA_ARGS__)) 1526 #define dbm_delete(...) (pthread_testcancel(), dbm_delete(__VA_ARGS__)) 1527 #define dbm_fetch(...) (pthread_testcancel(), dbm_fetch(__VA_ARGS__)) 1528 #define dbm_nextkey(...) (pthread_testcancel(), dbm_nextkey(__VA_ARGS__)) 1529 #define dbm_open(...) (pthread_testcancel(), dbm_open(__VA_ARGS__)) 1530 #define dbm_store(...) (pthread_testcancel(), dbm_store(__VA_ARGS__)) 1531 #define dlclose(...) (pthread_testcancel(), dlclose(__VA_ARGS__)) 1532 #define dlopen(...) (pthread_testcancel(), dlopen(__VA_ARGS__)) 1533 #define endgrent(...) (pthread_testcancel(), endgrent(__VA_ARGS__)) 1534 #define endhostent(...) (pthread_testcancel(), endhostent(__VA_ARGS__)) 1535 #define endnetent(...) (pthread_testcancel(), endnetent(__VA_ARGS__)) 1536 #define endprotoent(...) (pthread_testcancel(), endprotoend(__VA_ARGS__)) 1537 #define endpwent(...) (pthread_testcancel(), endpwent(__VA_ARGS__)) 1538 #define endservent(...) (pthread_testcancel(), endservent(__VA_ARGS__)) 1539 #define endutxent(...) (pthread_testcancel(), endutxent(__VA_ARGS__)) 1540 #define fclose(...) (pthread_testcancel(), fclose(__VA_ARGS__)) 1541 #define fflush(...) (pthread_testcancel(), fflush(__VA_ARGS__)) 1542 #define fgetc(...) (pthread_testcancel(), fgetc(__VA_ARGS__)) 1543 #define fgetpos(...) (pthread_testcancel(), fgetpos(__VA_ARGS__)) 1544 #define fgets(...) (pthread_testcancel(), fgets(__VA_ARGS__)) 1545 #define fgetwc(...) (pthread_testcancel(), fgetwc(__VA_ARGS__)) 1546 #define fgetws(...) (pthread_testcancel(), fgetws(__VA_ARGS__)) 1547 #define fmtmsg(...) (pthread_testcancel(), fmtmsg(__VA_ARGS__)) 1548 #define fopen(...) (pthread_testcancel(), fopen(__VA_ARGS__)) 1549 #define fpathconf(...) (pthread_testcancel(), fpathconf(__VA_ARGS__)) 1550 #define fprintf(...) (pthread_testcancel(), fprintf(__VA_ARGS__)) 1551 #define fputc(...) (pthread_testcancel(), fputc(__VA_ARGS__)) 1552 #define fputs(...) (pthread_testcancel(), fputs(__VA_ARGS__)) 1553 #define fputwc(...) (pthread_testcancel(), fputwc(__VA_ARGS__)) 1554 #define fputws(...) (pthread_testcancel(), fputws(__VA_ARGS__)) 1555 #define fread(...) (pthread_testcancel(), fread(__VA_ARGS__)) 1556 #define freopen(...) (pthread_testcancel(), freopen(__VA_ARGS__)) 1557 #define fscanf(...) (pthread_testcancel(), fscanf(__VA_ARGS__)) 1558 #define fseek(...) (pthread_testcancel(), fseek(__VA_ARGS__)) 1559 #define fseeko(...) (pthread_testcancel(), fseeko(__VA_ARGS__)) 1560 #define fsetpos(...) (pthread_testcancel(), fsetpos(__VA_ARGS__)) 1561 #define fstat(...) (pthread_testcancel(), fstat(__VA_ARGS__)) 1562 #define ftell(...) (pthread_testcancel(), ftell(__VA_ARGS__)) 1563 #define ftello(...) (pthread_testcancel(), ftello(__VA_ARGS__)) 1564 #define ftw(...) (pthread_testcancel(), ftw(__VA_ARGS__)) 1565 #define fwprintf(...) (pthread_testcancel(), fwprintf(__VA_ARGS__)) 1566 #define fwrite(...) (pthread_testcancel(), fwrite(__VA_ARGS__)) 1567 #define fwscanf(...) (pthread_testcancel(), fwscanf(__VA_ARGS__)) 1568 #define getaddrinfo(...) (pthread_testcancel(), getaddrinfo(__VA_ARGS__)) 1569 #define getc(...) (pthread_testcancel(), getc(__VA_ARGS__)) 1570 #define getc_unlocked(...) (pthread_testcancel(), getc_unlocked(__VA_ARGS__)) 1571 #define getchar(...) (pthread_testcancel(), getchar(__VA_ARGS__)) 1572 #define getchar_unlocked(...) \ 1573 (pthread_testcancel(), getchar_unlocked(__VA_ARGS__)) 1574 #define getcwd(...) (pthread_testcancel(), getcwd(__VA_ARGS__)) 1575 #define getdate(...) (pthread_testcancel(), getdate(__VA_ARGS__)) 1576 #define getgrent(...) (pthread_testcancel(), getgrent(__VA_ARGS__)) 1577 #define getgrgid(...) (pthread_testcancel(), getgrgid(__VA_ARGS__)) 1578 #define getgrgid_r(...) (pthread_testcancel(), getgrgid_r(__VA_ARGS__)) 1579 #define gergrnam(...) (pthread_testcancel(), getgrnam(__VA_ARGS__)) 1580 #define getgrnam_r(...) (pthread_testcancel(), getgrnam_r(__VA_ARGS__)) 1581 #define gethostbyaddr(...) (pthread_testcancel(), gethostbyaddr(__VA_ARGS__)) 1582 #define gethostbyname(...) (pthread_testcancel(), gethostbyname(__VA_ARGS__)) 1583 #define gethostent(...) (pthread_testcancel(), gethostent(__VA_ARGS__)) 1584 #define gethostid(...) (pthread_testcancel(), gethostid(__VA_ARGS__)) 1585 #define gethostname(...) (pthread_testcancel(), gethostname(__VA_ARGS__)) 1586 #define getlogin(...) (pthread_testcancel(), getlogin(__VA_ARGS__)) 1587 #define getlogin_r(...) (pthread_testcancel(), getlogin_r(__VA_ARGS__)) 1588 #define getnameinfo(...) (pthread_testcancel(), getnameinfo(__VA_ARGS__)) 1589 #define getnetbyaddr(...) (pthread_testcancel(), getnetbyaddr(__VA_ARGS__)) 1590 #define getnetbyname(...) (pthread_testcancel(), getnetbyname(__VA_ARGS__)) 1591 #define getnetent(...) (pthread_testcancel(), getnetent(__VA_ARGS__)) 1592 #define getopt(...) (pthread_testcancel(), getopt(__VA_ARGS__)) 1593 #define getprotobyname(...) (pthread_testcancel(), getprotobyname(__VA_ARGS__)) 1594 #define getprotobynumber(...) \ 1595 (pthread_testcancel(), getprotobynumber(__VA_ARGS__)) 1596 #define getprotoent(...) (pthread_testcancel(), getprotoent(__VA_ARGS__)) 1597 #define getpwent(...) (pthread_testcancel(), getpwent(__VA_ARGS__)) 1598 #define getpwnam(...) (pthread_testcancel(), getpwnam(__VA_ARGS__)) 1599 #define getpwnam_r(...) (pthread_testcancel(), getpwnam_r(__VA_ARGS__)) 1600 #define getpwuid(...) (pthread_testcancel(), getpwuid(__VA_ARGS__)) 1601 #define getpwuid_r(...) (pthread_testcancel(), getpwuid_r(__VA_ARGS__)) 1602 #define gets(...) (pthread_testcancel(), gets(__VA_ARGS__)) 1603 #define getservbyname(...) (pthread_testcancel(), getservbyname(__VA_ARGS__)) 1604 #define getservbyport(...) (pthread_testcancel(), getservbyport(__VA_ARGS__)) 1605 #define getservent(...) (pthread_testcancel(), getservent(__VA_ARGS__)) 1606 #define getutxent(...) (pthread_testcancel(), getutxent(__VA_ARGS__)) 1607 #define getutxid(...) (pthread_testcancel(), getutxid(__VA_ARGS__)) 1608 #define getutxline(...) (pthread_testcancel(), getutxline(__VA_ARGS__)) 1609 #undef getwc 1610 #define getwc(...) (pthread_testcancel(), getwc(__VA_ARGS__)) 1611 #undef getwchar 1612 #define getwchar(...) (pthread_testcancel(), getwchar(__VA_ARGS__)) 1613 #define getwd(...) (pthread_testcancel(), getwd(__VA_ARGS__)) 1614 #define glob(...) (pthread_testcancel(), glob(__VA_ARGS__)) 1615 #define iconv_close(...) (pthread_testcancel(), iconv_close(__VA_ARGS__)) 1616 #define iconv_open(...) (pthread_testcancel(), iconv_open(__VA_ARGS__)) 1617 #define ioctl(...) (pthread_testcancel(), ioctl(__VA_ARGS__)) 1618 #define link(...) (pthread_testcancel(), link(__VA_ARGS__)) 1619 #define localtime(...) (pthread_testcancel(), localtime(__VA_ARGS__)) 1620 #define localtime_r(...) (pthread_testcancel(), localtime_r(__VA_ARGS__)) 1621 #define lseek(...) (pthread_testcancel(), lseek(__VA_ARGS__)) 1622 #define lstat(...) (pthread_testcancel(), lstat(__VA_ARGS__)) 1623 #define mkstemp(...) (pthread_testcancel(), mkstemp(__VA_ARGS__)) 1624 #define nftw(...) (pthread_testcancel(), nftw(__VA_ARGS__)) 1625 #define opendir(...) (pthread_testcancel(), opendir(__VA_ARGS__)) 1626 #define openlog(...) (pthread_testcancel(), openlog(__VA_ARGS__)) 1627 #define pathconf(...) (pthread_testcancel(), pathconf(__VA_ARGS__)) 1628 #define pclose(...) (pthread_testcancel(), pclose(__VA_ARGS__)) 1629 #define perror(...) (pthread_testcancel(), perror(__VA_ARGS__)) 1630 #define popen(...) (pthread_testcancel(), popen(__VA_ARGS__)) 1631 #define posix_fadvise(...) (pthread_testcancel(), posix_fadvise(__VA_ARGS__)) 1632 #define posix_fallocate(...) \ 1633 (pthread_testcancel(), posix_fallocate(__VA_ARGS__)) 1634 #define posix_madvise(...) (pthread_testcancel(), posix_madvise(__VA_ARGS__)) 1635 #define posix_openpt(...) (pthread_testcancel(), posix_openpt(__VA_ARGS__)) 1636 #define posix_spawn(...) (pthread_testcancel(), posix_spawn(__VA_ARGS__)) 1637 #define posix_spawnp(...) (pthread_testcancel(), posix_spawnp(__VA_ARGS__)) 1638 #define posix_trace_clear(...) \ 1639 (pthread_testcancel(), posix_trace_clear(__VA_ARGS__)) 1640 #define posix_trace_close(...) \ 1641 (pthread_testcancel(), posix_trace_close(__VA_ARGS__)) 1642 #define posix_trace_create(...) \ 1643 (pthread_testcancel(), posix_trace_create(__VA_ARGS__)) 1644 #define posix_trace_create_withlog(...) \ 1645 (pthread_testcancel(), posix_trace_create_withlog(__VA_ARGS__)) 1646 #define posix_trace_eventtypelist_getne(...) \ 1647 (pthread_testcancel(), posix_trace_eventtypelist_getne(__VA_ARGS__)) 1648 #define posix_trace_eventtypelist_rewin(...) \ 1649 (pthread_testcancel(), posix_trace_eventtypelist_rewin(__VA_ARGS__)) 1650 #define posix_trace_flush(...) \ 1651 (pthread_testcancel(), posix_trace_flush(__VA_ARGS__)) 1652 #define posix_trace_get_attr(...) \ 1653 (pthread_testcancel(), posix_trace_get_attr(__VA_ARGS__)) 1654 #define posix_trace_get_filter(...) \ 1655 (pthread_testcancel(), posix_trace_get_filter(__VA_ARGS__)) 1656 #define posix_trace_get_status(...) \ 1657 (pthread_testcancel(), posix_trace_get_status(__VA_ARGS__)) 1658 #define posix_trace_getnext_event(...) \ 1659 (pthread_testcancel(), posix_trace_getnext_event(__VA_ARGS__)) 1660 #define posix_trace_open(...) \ 1661 (pthread_testcancel(), posix_trace_open(__VA_ARGS__)) 1662 #define posix_trace_rewind(...) \ 1663 (pthread_testcancel(), posix_trace_rewind(__VA_ARGS__)) 1664 #define posix_trace_setfilter(...) \ 1665 (pthread_testcancel(), posix_trace_setfilter(__VA_ARGS__)) 1666 #define posix_trace_shutdown(...) \ 1667 (pthread_testcancel(), posix_trace_shutdown(__VA_ARGS__)) 1668 #define posix_trace_timedgetnext_event(...) \ 1669 (pthread_testcancel(), posix_trace_timedgetnext_event(__VA_ARGS__)) 1670 #define posix_typed_mem_open(...) \ 1671 (pthread_testcancel(), posix_typed_mem_open(__VA_ARGS__)) 1672 #define printf(...) (pthread_testcancel(), printf(__VA_ARGS__)) 1673 #define putc(...) (pthread_testcancel(), putc(__VA_ARGS__)) 1674 #define putc_unlocked(...) (pthread_testcancel(), putc_unlocked(__VA_ARGS__)) 1675 #define putchar(...) (pthread_testcancel(), putchar(__VA_ARGS__)) 1676 #define putchar_unlocked(...) \ 1677 (pthread_testcancel(), putchar_unlocked(__VA_ARGS__)) 1678 #define puts(...) (pthread_testcancel(), puts(__VA_ARGS__)) 1679 #define pututxline(...) (pthread_testcancel(), pututxline(__VA_ARGS__)) 1680 #undef putwc 1681 #define putwc(...) (pthread_testcancel(), putwc(__VA_ARGS__)) 1682 #undef putwchar 1683 #define putwchar(...) (pthread_testcancel(), putwchar(__VA_ARGS__)) 1684 #define readdir(...) (pthread_testcancel(), readdir(__VA_ARSG__)) 1685 #define readdir_r(...) (pthread_testcancel(), readdir_r(__VA_ARGS__)) 1686 #define remove(...) (pthread_testcancel(), remove(__VA_ARGS__)) 1687 #define rename(...) (pthread_testcancel(), rename(__VA_ARGS__)) 1688 #define rewind(...) (pthread_testcancel(), rewind(__VA_ARGS__)) 1689 #define rewinddir(...) (pthread_testcancel(), rewinddir(__VA_ARGS__)) 1690 #define scanf(...) (pthread_testcancel(), scanf(__VA_ARGS__)) 1691 #define seekdir(...) (pthread_testcancel(), seekdir(__VA_ARGS__)) 1692 #define semop(...) (pthread_testcancel(), semop(__VA_ARGS__)) 1693 #define setgrent(...) (pthread_testcancel(), setgrent(__VA_ARGS__)) 1694 #define sethostent(...) (pthread_testcancel(), sethostemt(__VA_ARGS__)) 1695 #define setnetent(...) (pthread_testcancel(), setnetent(__VA_ARGS__)) 1696 #define setprotoent(...) (pthread_testcancel(), setprotoent(__VA_ARGS__)) 1697 #define setpwent(...) (pthread_testcancel(), setpwent(__VA_ARGS__)) 1698 #define setservent(...) (pthread_testcancel(), setservent(__VA_ARGS__)) 1699 #define setutxent(...) (pthread_testcancel(), setutxent(__VA_ARGS__)) 1700 #define stat(...) (pthread_testcancel(), stat(__VA_ARGS__)) 1701 #define strerror(...) (pthread_testcancel(), strerror(__VA_ARGS__)) 1702 #define strerror_r(...) (pthread_testcancel(), strerror_r(__VA_ARGS__)) 1703 #define strftime(...) (pthread_testcancel(), strftime(__VA_ARGS__)) 1704 #define symlink(...) (pthread_testcancel(), symlink(__VA_ARGS__)) 1705 #define sync(...) (pthread_testcancel(), sync(__VA_ARGS__)) 1706 #define syslog(...) (pthread_testcancel(), syslog(__VA_ARGS__)) 1707 #define tmpfile(...) (pthread_testcancel(), tmpfile(__VA_ARGS__)) 1708 #define tmpnam(...) (pthread_testcancel(), tmpnam(__VA_ARGS__)) 1709 #define ttyname(...) (pthread_testcancel(), ttyname(__VA_ARGS__)) 1710 #define ttyname_r(...) (pthread_testcancel(), ttyname_r(__VA_ARGS__)) 1711 #define tzset(...) (pthread_testcancel(), tzset(__VA_ARGS__)) 1712 #define ungetc(...) (pthread_testcancel(), ungetc(__VA_ARGS__)) 1713 #define ungetwc(...) (pthread_testcancel(), ungetwc(__VA_ARGS__)) 1714 #define unlink(...) (pthread_testcancel(), unlink(__VA_ARGS__)) 1715 #define vfprintf(...) (pthread_testcancel(), vfprintf(__VA_ARGS__)) 1716 #define vfwprintf(...) (pthread_testcancel(), vfwprintf(__VA_ARGS__)) 1717 #define vprintf(...) (pthread_testcancel(), vprintf(__VA_ARGS__)) 1718 #define vwprintf(...) (pthread_testcancel(), vwprintf(__VA_ARGS__)) 1719 #define wcsftime(...) (pthread_testcancel(), wcsftime(__VA_ARGS__)) 1720 #define wordexp(...) (pthread_testcancel(), wordexp(__VA_ARGS__)) 1721 #define wprintf(...) (pthread_testcancel(), wprintf(__VA_ARGS__)) 1722 #define wscanf(...) (pthread_testcancel(), wscanf(__VA_ARGS__)) 1723 1724 #endif /* WIN_PTHREADS */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™