diff options
| author | Jörg Frings-Fürst <debian@jff.email> | 2026-03-10 13:24:07 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff.email> | 2026-03-10 13:24:07 +0100 |
| commit | cfd1f17f1a85d95ea12bca8dae42add7dad1ad11 (patch) | |
| tree | 8016486f8ee7157213f2d09ff2491bfa9c94638a /tests/windows-timedrwlock.c | |
| parent | 14e4d584d0121031ec40e6c35869745f1747ff29 (diff) | |
| parent | 1403307d6e2fb4e7b5d97a35f40d1e95134561ab (diff) | |
Merge branch 'release/debian/1.4.2-1'HEADdebian/1.4.2-1master
Diffstat (limited to 'tests/windows-timedrwlock.c')
| -rw-r--r-- | tests/windows-timedrwlock.c | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/tests/windows-timedrwlock.c b/tests/windows-timedrwlock.c index e818407c..2297f637 100644 --- a/tests/windows-timedrwlock.c +++ b/tests/windows-timedrwlock.c @@ -1,5 +1,5 @@ /* Timed read-write locks (native Windows implementation). - Copyright (C) 2005-2024 Free Software Foundation, Inc. + Copyright (C) 2005-2026 Free Software Foundation, Inc. This file is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -54,13 +54,10 @@ glwthread_waitqueue_init (glwthread_waitqueue_t *wq) static struct glwthread_waitqueue_element * glwthread_waitqueue_add (glwthread_waitqueue_t *wq) { - struct glwthread_waitqueue_element *elt; - HANDLE event; - /* Allocate the memory for the waitqueue element on the heap, not on the thread's stack. If the thread exits unexpectedly, we prefer to leak some memory rather than to access unavailable memory and crash. */ - elt = + struct glwthread_waitqueue_element *elt = (struct glwthread_waitqueue_element *) malloc (sizeof (struct glwthread_waitqueue_element)); if (elt == NULL) @@ -69,7 +66,7 @@ glwthread_waitqueue_add (glwthread_waitqueue_t *wq) /* Whether the created event is a manual-reset one or an auto-reset one, does not matter, since we will wait on it only once. */ - event = CreateEvent (NULL, TRUE, FALSE, NULL); + HANDLE event = CreateEvent (NULL, TRUE, FALSE, NULL); if (event == INVALID_HANDLE_VALUE) { /* No way to allocate an event. */ @@ -115,12 +112,10 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq) { struct glwthread_waitqueue_element *elt = (struct glwthread_waitqueue_element *) wq->wq_list.wql_next; - struct glwthread_waitqueue_link *prev; - struct glwthread_waitqueue_link *next; /* Remove elt from the circular list. */ - prev = &wq->wq_list; /* = elt->link.wql_prev; */ - next = elt->link.wql_next; + struct glwthread_waitqueue_link *prev = &wq->wq_list; /* = elt->link.wql_prev; */ + struct glwthread_waitqueue_link *next = elt->link.wql_next; prev->wql_next = next; next->wql_prev = prev; elt->link.wql_next = NULL; @@ -137,18 +132,14 @@ glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq) static void glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq) { - struct glwthread_waitqueue_link *l; - - for (l = wq->wq_list.wql_next; l != &wq->wq_list; ) + for (struct glwthread_waitqueue_link *l = wq->wq_list.wql_next; l != &wq->wq_list; ) { struct glwthread_waitqueue_element *elt = (struct glwthread_waitqueue_element *) l; - struct glwthread_waitqueue_link *prev; - struct glwthread_waitqueue_link *next; /* Remove elt from the circular list. */ - prev = &wq->wq_list; /* = elt->link.wql_prev; */ - next = elt->link.wql_next; + struct glwthread_waitqueue_link *prev = &wq->wq_list; /* = elt->link.wql_prev; */ + struct glwthread_waitqueue_link *next = elt->link.wql_next; prev->wql_next = next; next->wql_prev = prev; elt->link.wql_next = NULL; @@ -209,10 +200,9 @@ glwthread_timedrwlock_rdlock (glwthread_timedrwlock_t *lock) if (elt != NULL) { HANDLE event = elt->event; - DWORD result; LeaveCriticalSection (&lock->lock); /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); + DWORD result = WaitForSingleObject (event, INFINITE); if (result == WAIT_FAILED || result == WAIT_TIMEOUT) abort (); CloseHandle (event); @@ -269,10 +259,9 @@ glwthread_timedrwlock_wrlock (glwthread_timedrwlock_t *lock) if (elt != NULL) { HANDLE event = elt->event; - DWORD result; LeaveCriticalSection (&lock->lock); /* Wait until another thread signals this event. */ - result = WaitForSingleObject (event, INFINITE); + DWORD result = WaitForSingleObject (event, INFINITE); if (result == WAIT_FAILED || result == WAIT_TIMEOUT) abort (); CloseHandle (event); @@ -402,17 +391,15 @@ glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock, if (elt != NULL) { HANDLE event = elt->event; - struct timeval currtime; - DWORD timeout; - DWORD result; - int retval; LeaveCriticalSection (&lock->lock); + struct timeval currtime; gettimeofday (&currtime, NULL); /* Wait until another thread signals this event or until the abstime passes. */ + DWORD timeout; if (currtime.tv_sec > abstime->tv_sec) timeout = 0; else @@ -444,7 +431,7 @@ glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock, { /* WaitForSingleObject <https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject> */ - result = WaitForSingleObject (event, timeout); + DWORD result = WaitForSingleObject (event, timeout); if (result == WAIT_FAILED) abort (); if (result != WAIT_TIMEOUT) @@ -461,6 +448,7 @@ glwthread_timedrwlock_timedrdlock (glwthread_timedrwlock_t *lock, } EnterCriticalSection (&lock->lock); /* Remove ourselves from the waiting_readers. */ + int retval; if (glwthread_waitqueue_remove (&lock->waiting_readers, elt)) retval = ETIMEDOUT; else @@ -522,17 +510,15 @@ glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock, if (elt != NULL) { HANDLE event = elt->event; - struct timeval currtime; - DWORD timeout; - DWORD result; - int retval; LeaveCriticalSection (&lock->lock); + struct timeval currtime; gettimeofday (&currtime, NULL); /* Wait until another thread signals this event or until the abstime passes. */ + DWORD timeout; if (currtime.tv_sec > abstime->tv_sec) timeout = 0; else @@ -564,7 +550,7 @@ glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock, { /* WaitForSingleObject <https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-waitforsingleobject> */ - result = WaitForSingleObject (event, timeout); + DWORD result = WaitForSingleObject (event, timeout); if (result == WAIT_FAILED) abort (); if (result != WAIT_TIMEOUT) @@ -581,6 +567,7 @@ glwthread_timedrwlock_timedwrlock (glwthread_timedrwlock_t *lock, } EnterCriticalSection (&lock->lock); /* Remove ourselves from the waiting_writers. */ + int retval; if (glwthread_waitqueue_remove (&lock->waiting_writers, elt)) retval = ETIMEDOUT; else |
