]> Savannah Git Hosting - gnulib.git/commit
windows-once: Free allocated resources when done.
authorBruno Haible <bruno@clisp.org>
Thu, 30 May 2024 08:23:22 +0000 (10:23 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 31 May 2024 17:50:27 +0000 (19:50 +0200)
commitc6942fe973af622bbeb5fafc5c1cd32c82a2cb7b
tree4063fab0c4f6ab5b4ff61cca0d448b4f5d29affb
parent1c4f00661a3372634d0fa82a3f488c164e0c9b18
windows-once: Free allocated resources when done.

Based on an observation regarding Cygwin's pthread_once implementation
by Takashi Yano <takashi.yano@nifty.ne.jp> at
<https://cygwin.com/pipermail/cygwin/2024-January/255182.html> and
<https://cygwin.com/pipermail/cygwin-patches/2024q1/012600.html>

* lib/windows-once.h (glwthread_once_t): Change type of inited to LONG.
Add field 'num_threads'.
(GLWTHREAD_ONCE_INIT): Initialize it to zero.
* lib/windows-once.c (glwthread_once): Use InterlockedCompareExchange
instead of InterlockedIncrement. Increment num_threads while the thread
uses the lock. Let the last thread that uses the lock destroy it.
ChangeLog
lib/windows-once.c
lib/windows-once.h