diff options
Diffstat (limited to 'gl/windows-rwlock.c')
| -rw-r--r-- | gl/windows-rwlock.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/gl/windows-rwlock.c b/gl/windows-rwlock.c index 313f14ca..4a5fbfc2 100644 --- a/gl/windows-rwlock.c +++ b/gl/windows-rwlock.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Read-write locks (native Windows implementation). | 1 | /* Read-write locks (native Windows implementation). |
| 2 | Copyright (C) 2005-2025 Free Software Foundation, Inc. | 2 | Copyright (C) 2005-2026 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU Lesser General Public License as |
| @@ -46,9 +46,6 @@ glwthread_waitqueue_init (glwthread_waitqueue_t *wq) | |||
| 46 | static HANDLE | 46 | static HANDLE |
| 47 | glwthread_waitqueue_add (glwthread_waitqueue_t *wq) | 47 | glwthread_waitqueue_add (glwthread_waitqueue_t *wq) |
| 48 | { | 48 | { |
| 49 | HANDLE event; | ||
| 50 | unsigned int index; | ||
| 51 | |||
| 52 | if (wq->count == wq->alloc) | 49 | if (wq->count == wq->alloc) |
| 53 | { | 50 | { |
| 54 | unsigned int new_alloc = 2 * wq->alloc + 1; | 51 | unsigned int new_alloc = 2 * wq->alloc + 1; |
| @@ -64,14 +61,13 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq) | |||
| 64 | unsigned int old_count = wq->count; | 61 | unsigned int old_count = wq->count; |
| 65 | unsigned int old_alloc = wq->alloc; | 62 | unsigned int old_alloc = wq->alloc; |
| 66 | unsigned int old_offset = wq->offset; | 63 | unsigned int old_offset = wq->offset; |
| 67 | unsigned int i; | ||
| 68 | if (old_offset + old_count > old_alloc) | 64 | if (old_offset + old_count > old_alloc) |
| 69 | { | 65 | { |
| 70 | unsigned int limit = old_offset + old_count - old_alloc; | 66 | unsigned int limit = old_offset + old_count - old_alloc; |
| 71 | for (i = 0; i < limit; i++) | 67 | for (unsigned int i = 0; i < limit; i++) |
| 72 | new_array[old_alloc + i] = new_array[i]; | 68 | new_array[old_alloc + i] = new_array[i]; |
| 73 | } | 69 | } |
| 74 | for (i = 0; i < old_count; i++) | 70 | for (unsigned int i = 0; i < old_count; i++) |
| 75 | new_array[i] = new_array[old_offset + i]; | 71 | new_array[i] = new_array[old_offset + i]; |
| 76 | wq->offset = 0; | 72 | wq->offset = 0; |
| 77 | } | 73 | } |
| @@ -80,11 +76,11 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq) | |||
| 80 | } | 76 | } |
| 81 | /* Whether the created event is a manual-reset one or an auto-reset one, | 77 | /* Whether the created event is a manual-reset one or an auto-reset one, |
| 82 | does not matter, since we will wait on it only once. */ | 78 | does not matter, since we will wait on it only once. */ |
| 83 | event = CreateEvent (NULL, TRUE, FALSE, NULL); | 79 | HANDLE event = CreateEvent (NULL, TRUE, FALSE, NULL); |
| 84 | if (event == INVALID_HANDLE_VALUE) | 80 | if (event == INVALID_HANDLE_VALUE) |
| 85 | /* No way to allocate an event. */ | 81 | /* No way to allocate an event. */ |
| 86 | return INVALID_HANDLE_VALUE; | 82 | return INVALID_HANDLE_VALUE; |
| 87 | index = wq->offset + wq->count; | 83 | unsigned int index = wq->offset + wq->count; |
| 88 | if (index >= wq->alloc) | 84 | if (index >= wq->alloc) |
| 89 | index -= wq->alloc; | 85 | index -= wq->alloc; |
| 90 | wq->array[index] = event; | 86 | wq->array[index] = event; |
| @@ -107,9 +103,7 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq) | |||
| 107 | static void | 103 | static void |
| 108 | glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq) | 104 | glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq) |
| 109 | { | 105 | { |
| 110 | unsigned int i; | 106 | for (unsigned int i = 0; i < wq->count; i++) |
| 111 | |||
| 112 | for (i = 0; i < wq->count; i++) | ||
| 113 | { | 107 | { |
| 114 | unsigned int index = wq->offset + i; | 108 | unsigned int index = wq->offset + i; |
| 115 | if (index >= wq->alloc) | 109 | if (index >= wq->alloc) |
| @@ -160,10 +154,9 @@ glwthread_rwlock_rdlock (glwthread_rwlock_t *lock) | |||
| 160 | HANDLE event = glwthread_waitqueue_add (&lock->waiting_readers); | 154 | HANDLE event = glwthread_waitqueue_add (&lock->waiting_readers); |
| 161 | if (event != INVALID_HANDLE_VALUE) | 155 | if (event != INVALID_HANDLE_VALUE) |
| 162 | { | 156 | { |
| 163 | DWORD result; | ||
| 164 | LeaveCriticalSection (&lock->lock); | 157 | LeaveCriticalSection (&lock->lock); |
| 165 | /* Wait until another thread signals this event. */ | 158 | /* Wait until another thread signals this event. */ |
| 166 | result = WaitForSingleObject (event, INFINITE); | 159 | DWORD result = WaitForSingleObject (event, INFINITE); |
| 167 | if (result == WAIT_FAILED || result == WAIT_TIMEOUT) | 160 | if (result == WAIT_FAILED || result == WAIT_TIMEOUT) |
| 168 | abort (); | 161 | abort (); |
| 169 | CloseHandle (event); | 162 | CloseHandle (event); |
| @@ -217,10 +210,9 @@ glwthread_rwlock_wrlock (glwthread_rwlock_t *lock) | |||
| 217 | HANDLE event = glwthread_waitqueue_add (&lock->waiting_writers); | 210 | HANDLE event = glwthread_waitqueue_add (&lock->waiting_writers); |
| 218 | if (event != INVALID_HANDLE_VALUE) | 211 | if (event != INVALID_HANDLE_VALUE) |
| 219 | { | 212 | { |
| 220 | DWORD result; | ||
| 221 | LeaveCriticalSection (&lock->lock); | 213 | LeaveCriticalSection (&lock->lock); |
| 222 | /* Wait until another thread signals this event. */ | 214 | /* Wait until another thread signals this event. */ |
| 223 | result = WaitForSingleObject (event, INFINITE); | 215 | DWORD result = WaitForSingleObject (event, INFINITE); |
| 224 | if (result == WAIT_FAILED || result == WAIT_TIMEOUT) | 216 | if (result == WAIT_FAILED || result == WAIT_TIMEOUT) |
| 225 | abort (); | 217 | abort (); |
| 226 | CloseHandle (event); | 218 | CloseHandle (event); |
