|
From: | Bruno Haible |
Subject: | windows-mutex, windows-timedmutex: Follow pthread_mutex_trylock spec |
Date: | Tue, 06 Aug 2024 15:37:45 +0200 |
pthread_mutex_trylock is required to fail with EBUSY if the mutex is a non-recursive one and it is already locked by the current thread. Similarly for mtx_trylock. On native Windows, I observe that the Gnulib implementation does not follow this spec, because - It uses the windows-mutex and windows-timedmutex modules. - This code uses the TryEnterCriticalSection function. - This function succeeds if the current thread already holds the lock, because a Windows CRITICAL_SECTION is semantically a recursive lock. These patches fixes it, and add unit tests to verify the behaviour. 2024-08-06 Bruno Haible <bruno@clisp.org> windows-timedrecmutex: Add tests. * tests/test-windows-timedrecmutex-type.c: New file. * modules/windows-timedrecmutex-tests: New file. windows-recmutex: Add tests. * tests/test-windows-recmutex-type.c: New file. * modules/windows-recmutex-tests: New file. windows-timedmutex: Add tests. * tests/test-windows-timedmutex-type.c: New file. * modules/windows-timedmutex-tests: New file. windows-mutex: Add tests. * tests/test-windows-mutex-type.c: New file. * modules/windows-mutex-tests: New file. 2024-08-06 Bruno Haible <bruno@clisp.org> windows-mutex, windows-timedmutex: Follow pthread_mutex_trylock spec. * lib/windows-mutex.h (glwthread_mutex_t): Add 'owner' field. * lib/windows-mutex.c: Include <stdlib.h>. (glwthread_mutex_lock): Set the 'owner' field after entering the critical section. (glwthread_mutex_trylock): Detect whether the lock was previously locked by this thread. Set the 'owner' field after entering the critical section. (glwthread_mutex_unlock): Clear the 'owner' field before leaving the critical section. * lib/windows-timedmutex.h (glwthread_timedmutex_t): Add 'owner' field. * lib/windows-timedmutex.c: (glwthread_timedmutex_lock): Set the 'owner' field after entering the critical section. (glwthread_timedmutex_trylock): Detect whether the lock was previously locked by this thread. Set the 'owner' field after entering the critical section. (glwthread_timedmutex_unlock): Clear the 'owner' field before leaving the critical section.
0001-windows-mutex-windows-timedmutex-Follow-pthread_mute.patch
Description: Text Data
0002-windows-mutex-Add-tests.patch
Description: Text Data
0003-windows-timedmutex-Add-tests.patch
Description: Text Data
0004-windows-recmutex-Add-tests.patch
Description: Text Data
0005-windows-timedrecmutex-Add-tests.patch
Description: Text Data
[Prev in Thread] | Current Thread | [Next in Thread] |