| 1 |
/* Condition variables (native Windows implementation). |
| 2 |
Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License as |
| 6 |
published by the Free Software Foundation; either version 2.1 of the |
| 7 |
License, or (at your option) any later version. |
| 8 |
|
| 9 |
This file is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
/* Written by Yoann Vandoorselaere <[email protected]>, 2008. |
| 18 |
Based on Bruno Haible <[email protected]> lock.h */ |
| 19 |
|
| 20 |
#ifndef _WINDOWS_COND_H |
| 21 |
#define _WINDOWS_COND_H |
| 22 |
|
| 23 |
#define WIN32_LEAN_AND_MEAN /* avoid including junk */ |
| 24 |
#include <windows.h> |
| 25 |
|
| 26 |
#include <time.h> |
| 27 |
|
| 28 |
#include "windows-initguard.h" |
| 29 |
|
| 30 |
#ifndef _glwthread_linked_waitqueue_link_defined |
| 31 |
#define _glwthread_linked_waitqueue_link_defined |
| 32 |
struct glwthread_waitqueue_link |
| 33 |
{ |
| 34 |
struct glwthread_waitqueue_link *wql_next; |
| 35 |
struct glwthread_waitqueue_link *wql_prev; |
| 36 |
}; |
| 37 |
#endif /* _glwthread_linked_waitqueue_link_defined */ |
| 38 |
|
| 39 |
typedef struct |
| 40 |
{ |
| 41 |
struct glwthread_waitqueue_link wq_list; /* circular list of waiting threads */ |
| 42 |
} |
| 43 |
glwthread_linked_waitqueue_t; |
| 44 |
|
| 45 |
typedef struct |
| 46 |
{ |
| 47 |
glwthread_initguard_t guard; /* protects the initialization */ |
| 48 |
CRITICAL_SECTION lock; /* protects the remaining fields */ |
| 49 |
glwthread_linked_waitqueue_t waiters; /* waiting threads */ |
| 50 |
} |
| 51 |
glwthread_cond_t; |
| 52 |
|
| 53 |
#define GLWTHREAD_COND_INIT { GLWTHREAD_INITGUARD_INIT } |
| 54 |
|
| 55 |
#ifdef __cplusplus |
| 56 |
extern "C" { |
| 57 |
#endif |
| 58 |
|
| 59 |
extern int glwthread_cond_init (glwthread_cond_t *cond); |
| 60 |
/* Here, to cope with the various types of mutexes, the mutex is a 'void *', and |
| 61 |
the caller needs to pass the corresponding *_lock and *_unlock functions. */ |
| 62 |
extern int glwthread_cond_wait (glwthread_cond_t *cond, |
| 63 |
void *mutex, |
| 64 |
int (*mutex_lock) (void *), |
| 65 |
int (*mutex_unlock) (void *)); |
| 66 |
extern int glwthread_cond_timedwait (glwthread_cond_t *cond, |
| 67 |
void *mutex, |
| 68 |
int (*mutex_lock) (void *), |
| 69 |
int (*mutex_unlock) (void *), |
| 70 |
const struct timespec *abstime); |
| 71 |
extern int glwthread_cond_signal (glwthread_cond_t *cond); |
| 72 |
extern int glwthread_cond_broadcast (glwthread_cond_t *cond); |
| 73 |
extern int glwthread_cond_destroy (glwthread_cond_t *cond); |
| 74 |
|
| 75 |
#ifdef __cplusplus |
| 76 |
} |
| 77 |
#endif |
| 78 |
|
| 79 |
#endif /* _WINDOWS_COND_H */ |