Debian Codegraph @

gnulib-tests/windows-timedrwlock.h

raw
1 /* Timed read-write locks (native Windows implementation).
2 Copyright (C) 2019-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 Bruno Haible <[email protected]>, 2019. */
18
19 #ifndef _WINDOWS_TIMEDRWLOCK_H
20 #define _WINDOWS_TIMEDRWLOCK_H
21
22 #define WIN32_LEAN_AND_MEAN /* avoid including junk */
23 #include <windows.h>
24
25 #include <time.h>
26
27 #include "windows-initguard.h"
28
29 #ifndef _glwthread_linked_waitqueue_link_defined
30 #define _glwthread_linked_waitqueue_link_defined
31 struct glwthread_waitqueue_link
32 {
33 struct glwthread_waitqueue_link *wql_next;
34 struct glwthread_waitqueue_link *wql_prev;
35 };
36 #endif /* _glwthread_linked_waitqueue_link_defined */
37 typedef struct
38 {
39 struct glwthread_waitqueue_link wq_list; /* circular list of waiting threads */
40 unsigned int count; /* number of waiting threads */
41 }
42 glwthread_clinked_waitqueue_t;
43
44 typedef struct
45 {
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 */
51 }
52 glwthread_timedrwlock_t;
53
54 #define GLWTHREAD_TIMEDRWLOCK_INIT { GLWTHREAD_INITGUARD_INIT }
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59
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);
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif /* _WINDOWS_TIMEDRWLOCK_H */