1 /* Condition variables (native Windows implementation).
2 Copyright (C) 2008-2020 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program 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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Yoann Vandoorselaere <yoann@prelude-ids.org>, 2008.
18 Based on Bruno Haible <bruno@clisp.org> lock.h */
20 #ifndef _WINDOWS_COND_H
21 #define _WINDOWS_COND_H
23 #define WIN32_LEAN_AND_MEAN /* avoid including junk */
28 #include "windows-initguard.h"
30 #ifndef _glwthread_linked_waitqueue_link_defined
31 #define _glwthread_linked_waitqueue_link_defined
32 struct glwthread_waitqueue_link
34 struct glwthread_waitqueue_link
*wql_next
;
35 struct glwthread_waitqueue_link
*wql_prev
;
37 #endif /* _glwthread_linked_waitqueue_link_defined */
41 struct glwthread_waitqueue_link wq_list
; /* circular list of waiting threads */
43 glwthread_linked_waitqueue_t
;
47 glwthread_initguard_t guard
; /* protects the initialization */
48 CRITICAL_SECTION lock
; /* protects the remaining fields */
49 glwthread_linked_waitqueue_t waiters
; /* waiting threads */
53 #define GLWTHREAD_COND_INIT { GLWTHREAD_INITGUARD_INIT }
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
,
64 int (*mutex_lock
) (void *),
65 int (*mutex_unlock
) (void *));
66 extern int glwthread_cond_timedwait (glwthread_cond_t
*cond
,
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
);
79 #endif /* _WINDOWS_COND_H */