1 /* 2 Copyright (c) 2011-2016 mingw-w64 project 3 4 Permission is hereby granted, free of charge, to any person obtaining a 5 copy of this software and associated documentation files (the "Software"), 6 to deal in the Software without restriction, including without limitation 7 the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 and/or sell copies of the Software, and to permit persons to whom the 9 Software is furnished to do so, subject to the following conditions: 10 11 The above copyright notice and this permission notice shall be included in 12 all copies or substantial portions of the Software. 13 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 DEALINGS IN THE SOFTWARE. 21 */ 22 23 #ifndef WIN_PTHREADS_COND_H 24 #define WIN_PTHREADS_COND_H 25 26 #include <windows.h> 27 28 #define CHECK_COND(c) { \ 29 if (!(c) || !*c || (*c == PTHREAD_COND_INITIALIZER) \ 30 || ( ((cond_t *)(*c))->valid != (unsigned int)LIFE_COND ) ) \ 31 return EINVAL; } 32 33 #define LIFE_COND 0xC0BAB1FD 34 #define DEAD_COND 0xC0DEADBF 35 36 #define STATIC_COND_INITIALIZER(x) ((pthread_cond_t)(x) == ((pthread_cond_t)PTHREAD_COND_INITIALIZER)) 37 38 typedef struct cond_t cond_t; 39 struct cond_t 40 { 41 unsigned int valid; 42 int busy; 43 LONG waiters_count_; /* Number of waiting threads. */ 44 LONG waiters_count_unblock_; /* Number of waiting threads whitch can be unblocked. */ 45 LONG waiters_count_gone_; /* Number of waiters which are gone. */ 46 CRITICAL_SECTION waiters_count_lock_; /* Serialize access to <waiters_count_>. */ 47 CRITICAL_SECTION waiters_q_lock_; /* Serialize access to sema_q. */ 48 LONG value_q; 49 CRITICAL_SECTION waiters_b_lock_; /* Serialize access to sema_b. */ 50 LONG value_b; 51 HANDLE sema_q; /* Semaphore used to queue up threads waiting for the condition to 52 become signaled. */ 53 HANDLE sema_b; /* Semaphore used to queue up threads waiting for the condition which 54 became signaled. */ 55 }; 56 57 void cond_print_set(int state, FILE *f); 58 59 void cond_print(volatile pthread_cond_t *c, char *txt); 60 61 #endif 62