]> 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 22:10:44 +0000 (00:10 +0200)
commit1e48983d6446f243ae7ecaf570e8ef953de3ddc2
tree0d59927abea9125a34945d111aba05a0d00a8766
parentcf1f6e74bf5fcf6c1491f37d27abc63567354224
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