summaryrefslogtreecommitdiff
path: root/tests/windows-cond.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2026-03-08 17:28:33 +0100
committerJörg Frings-Fürst <debian@jff.email>2026-03-08 17:28:33 +0100
commit5f59a34ab747dde8ede7357f3431bf06bd6002fe (patch)
tree056a4477fd870d454d5be5868cddab829a47f4d2 /tests/windows-cond.c
parent27dae84ed92f1ef0300263091972338d12e78348 (diff)
New upstream version 1.4.2upstream/1.4.2upstream
Diffstat (limited to 'tests/windows-cond.c')
-rw-r--r--tests/windows-cond.c62
1 files changed, 25 insertions, 37 deletions
diff --git a/tests/windows-cond.c b/tests/windows-cond.c
index c6c6088d..4f848a9a 100644
--- a/tests/windows-cond.c
+++ b/tests/windows-cond.c
@@ -1,5 +1,5 @@
/* Condition variables (native Windows implementation).
- Copyright (C) 2008-2025 Free Software Foundation, Inc.
+ Copyright (C) 2008-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. */
@@ -113,12 +110,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;
@@ -134,18 +129,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;
@@ -206,11 +197,9 @@ glwthread_cond_wait (glwthread_cond_t *cond,
else
{
HANDLE event = elt->event;
- int err;
- DWORD result;
/* Now release the mutex and let any other thread take it. */
- err = mutex_unlock (mutex);
+ int err = mutex_unlock (mutex);
if (err != 0)
{
EnterCriticalSection (&cond->lock);
@@ -229,7 +218,7 @@ glwthread_cond_wait (glwthread_cond_t *cond,
This is fulfilled here, because the thread signalling is done
through SetEvent, not PulseEvent. */
/* 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);
@@ -265,7 +254,6 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
{
struct timeval currtime;
-
gettimeofday (&currtime, NULL);
if (currtime.tv_sec > abstime->tv_sec
|| (currtime.tv_sec == abstime->tv_sec
@@ -285,21 +273,20 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
else
{
HANDLE event = elt->event;
- int err;
- DWORD timeout;
- DWORD result;
/* Now release the mutex and let any other thread take it. */
- err = mutex_unlock (mutex);
- if (err != 0)
- {
- EnterCriticalSection (&cond->lock);
- glwthread_waitqueue_remove (&cond->waiters, elt);
- LeaveCriticalSection (&cond->lock);
- CloseHandle (event);
- free (elt);
- return err;
- }
+ {
+ int err = mutex_unlock (mutex);
+ if (err != 0)
+ {
+ EnterCriticalSection (&cond->lock);
+ glwthread_waitqueue_remove (&cond->waiters, elt);
+ LeaveCriticalSection (&cond->lock);
+ CloseHandle (event);
+ free (elt);
+ return err;
+ }
+ }
/* POSIX says:
"If another thread is able to acquire the mutex after the
about-to-block thread has released it, then a subsequent call to
@@ -311,6 +298,7 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
/* Wait until another thread signals this event or until the abstime
passes. */
gettimeofday (&currtime, NULL);
+ DWORD timeout;
if (currtime.tv_sec > abstime->tv_sec)
timeout = 0;
else
@@ -338,7 +326,7 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
}
}
}
- result = WaitForSingleObject (event, timeout);
+ DWORD result = WaitForSingleObject (event, timeout);
if (result == WAIT_FAILED)
abort ();
if (result == WAIT_TIMEOUT)
@@ -371,7 +359,7 @@ glwthread_cond_timedwait (glwthread_cond_t *cond,
free (elt);
/* Take the mutex again. It does not matter whether this is done
before or after the bookkeeping for WAIT_TIMEOUT. */
- err = mutex_lock (mutex);
+ int err = mutex_lock (mutex);
return (err ? err :
result == WAIT_OBJECT_0 ? 0 :
result == WAIT_TIMEOUT ? ETIMEDOUT :