exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / windows-timedrwlock.h
blob4520f08cd1f575ba1dfa50b4959ad438b7b21a7e
1 /* Timed read-write locks (native Windows implementation).
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2019. */
19 #ifndef _WINDOWS_TIMEDRWLOCK_H
20 #define _WINDOWS_TIMEDRWLOCK_H
22 #define WIN32_LEAN_AND_MEAN /* avoid including junk */
23 #include <windows.h>
25 #include <time.h>
27 #include "windows-initguard.h"
29 #ifndef _glwthread_linked_waitqueue_link_defined
30 #define _glwthread_linked_waitqueue_link_defined
31 struct glwthread_waitqueue_link
33 struct glwthread_waitqueue_link *wql_next;
34 struct glwthread_waitqueue_link *wql_prev;
36 #endif /* _glwthread_linked_waitqueue_link_defined */
37 typedef struct
39 struct glwthread_waitqueue_link wq_list; /* circular list of waiting threads */
40 unsigned int count; /* number of waiting threads */
42 glwthread_clinked_waitqueue_t;
44 typedef struct
46 glwthread_initguard_t guard; /* protects the initialization */
47 CRITICAL_SECTION lock; /* protects the remaining fields */
48 glwthread_clinked_waitqueue_t waiting_readers; /* waiting readers */
49 glwthread_clinked_waitqueue_t waiting_writers; /* waiting writers */
50 int runcount; /* number of readers running, or -1 when a writer runs */
52 glwthread_timedrwlock_t;
54 #define GLWTHREAD_TIMEDRWLOCK_INIT { GLWTHREAD_INITGUARD_INIT }
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
60 extern void glwthread_timedrwlock_init (glwthread_timedrwlock_t *lock);
61 extern int glwthread_timedrwlock_rdlock (glwthread_timedrwlock_t *lock);
62 extern int glwthread_timedrwlock_wrlock (glwthread_timedrwlock_t *lock);
63 extern int glwthread_timedrwlock_tryrdlock (glwthread_timedrwlock_t *lock);
64 extern int glwthread_timedrwlock_trywrlock (glwthread_timedrwlock_t *lock);
65 extern int glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock,
66 const struct timespec *abstime);
67 extern int glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock,
68 const struct timespec *abstime);
69 extern int glwthread_timedrwlock_unlock (glwthread_timedrwlock_t *lock);
70 extern int glwthread_timedrwlock_destroy (glwthread_timedrwlock_t *lock);
72 #ifdef __cplusplus
74 #endif
76 #endif /* _WINDOWS_TIMEDRWLOCK_H */