winpthreads: tests: update pthread_mutex/mutex7*.c Signed-off-by: Kirill Makurin <maiddaisuki@outlook.com> Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7.c b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7.c index 1b4f444..a11ee5b 100644 --- a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7.c +++ b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7.c
@@ -1,14 +1,10 @@ /* - * mutex7.c - * - * - * -------------------------------------------------------------------------- - * * Pthreads-win32 - POSIX Threads Library for Win32 * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999,2005 Pthreads-win32 contributors + * Copyright(C) 2026 mingw-w64 project * - * Contact Email: rpj@callisto.canberra.edu.au + * Contact Email: mingw-w64-public@lists.sourceforge.net * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source @@ -30,33 +26,35 @@ * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Test the default (type not set) mutex type. - * Should be the same as PTHREAD_MUTEX_NORMAL. - * Thread locks then trylocks mutex (attempted recursive lock). - * The thread should lock first time and EBUSY second time. - * - * Depends on API functions: - * pthread_mutex_lock() - * pthread_mutex_trylock() - * pthread_mutex_unlock() */ #include "test.h" -static int lockCount = 0; +/** + * Test Summary: + * + * Main thread M creates default-type mutex L. + * + * Thread A locks L. + * + * Thread A attempts to lock L again; the call to `pthread_mutex_trylock` must + * fail with EBUSY. + * + * Thread A unlocks L. + * + * Thread A attempts to unlock L again; the call to `pthread_mutex_unlock` must + * succeed (see comment below). + * + * Thread M destroys L. + */ -static pthread_mutex_t mutex; - -void * locker(void * arg) +static void *ThreadA(void *arg) { - assert(pthread_mutex_lock(&mutex) == 0); - lockCount++; - assert(pthread_mutex_trylock(&mutex) == EBUSY); - lockCount++; - assert(pthread_mutex_unlock(&mutex) == 0); + pthread_mutex_t *mutex = arg; + + assert(pthread_mutex_lock(mutex) == 0); + assert(pthread_mutex_trylock(mutex) == EBUSY); + assert(pthread_mutex_unlock(mutex) == 0); /** * POSIX states that calling `pthread_mutex_unlock` on NORMAL mutex that is * not owned by the calling thread is undefined behavior. @@ -64,22 +62,22 @@ * Our implementation for NORMAL mutexes does not check ownership at all, * so call to `pthread_mutex_unlock` on a valid NORMAL mutex always succeeds. */ - assert(pthread_mutex_unlock(&mutex) == 0); + assert(pthread_mutex_unlock(mutex) == 0); - return 0; + return arg; } int main(void) { - pthread_t t; + pthread_mutex_t mutex; + pthread_t thread; + void *result; assert(pthread_mutex_init(&mutex, NULL) == 0); - assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(1000); - assert(lockCount == 2); + assert(pthread_create(&thread, NULL, ThreadA, &mutex) == 0); + assert(pthread_join (thread, &result) == 0); + assert(result == &mutex); + assert(pthread_mutex_destroy(&mutex) == 0); - exit(0); - - /* Never reached */ return 0; }
diff --git a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7e.c b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7e.c index 0068150..a12df32 100644 --- a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7e.c +++ b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7e.c
@@ -1,14 +1,10 @@ /* - * mutex7e.c - * - * - * -------------------------------------------------------------------------- - * * Pthreads-win32 - POSIX Threads Library for Win32 * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999,2005 Pthreads-win32 contributors + * Copyright(C) 2026 mingw-w64 project * - * Contact Email: rpj@callisto.canberra.edu.au + * Contact Email: mingw-w64-public@lists.sourceforge.net * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source @@ -30,69 +26,58 @@ * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Tests PTHREAD_MUTEX_ERRORCHECK mutex type. - * Thread locks and then trylocks mutex (attempted recursive lock). - * Trylock should fail with an EBUSY error. - * The second unlock attempt should fail with an EPERM error. - * - * Depends on API functions: - * pthread_create() - * pthread_join() - * pthread_mutexattr_init() - * pthread_mutexattr_destroy() - * pthread_mutexattr_settype() - * pthread_mutexattr_gettype() - * pthread_mutex_init() - * pthread_mutex_destroy() - * pthread_mutex_lock() - * pthread_mutex_unlock() */ #include "test.h" -static int lockCount = 0; +/** + * Test Summary: + * + * Main thread M creates mutex L with type `PTHREAD_MUTEX_ERRORCHECK`. + * + * Thread A locks L. + * + * Thread A attempts to lock L again; the call to `pthread_mutex_trylock` must + * fail with EBUSY. + * + * Thread A unlocks L. + * + * Thread A attempts to unlock L again; the call to `pthread_mutex_unlock` must + * fail with EPERM. + * + * Thread M destroys L. + */ -static pthread_mutex_t mutex; -static pthread_mutexattr_t mxAttr; - -void *locker(void *arg) +static void *ThreadA(void *arg) { - assert(pthread_mutex_lock(&mutex) == 0); - lockCount++; - assert(pthread_mutex_trylock(&mutex) == EBUSY); - lockCount++; - assert(pthread_mutex_unlock(&mutex) == 0); - assert(pthread_mutex_unlock(&mutex) == EPERM); + pthread_mutex_t *mutex = arg; - return (void *) 555; + assert(pthread_mutex_lock(mutex) == 0); + assert(pthread_mutex_trylock(mutex) == EBUSY); + assert(pthread_mutex_unlock(mutex) == 0); + assert(pthread_mutex_unlock(mutex) == EPERM); + + return arg; } int main(void) { - pthread_t t; - intptr_t result = 0; - int mxType = -1; + pthread_mutexattr_t mutexAttr; + pthread_mutex_t mutex; + pthread_t thread; + int mutexType; + void *result; - assert(pthread_mutexattr_init(&mxAttr) == 0); - assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0); - assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); - assert(mxType == PTHREAD_MUTEX_ERRORCHECK); - - assert(pthread_mutex_init(&mutex, &mxAttr) == 0); - - assert(pthread_create(&t, NULL, locker, NULL) == 0); - assert(pthread_join(t, (void **) &result) == 0); - assert(result == 555); - assert(lockCount == 2); - + assert(pthread_mutexattr_init(&mutexAttr) == 0); + assert(pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK) == 0); + assert(pthread_mutexattr_gettype(&mutexAttr, &mutexType) == 0); + assert(mutexType == PTHREAD_MUTEX_ERRORCHECK); + assert(pthread_mutex_init(&mutex, &mutexAttr) == 0); + assert(pthread_create(&thread, NULL, ThreadA, &mutex) == 0); + assert(pthread_join(thread, &result) == 0); + assert(result == &mutex); assert(pthread_mutex_destroy(&mutex) == 0); - assert(pthread_mutexattr_destroy(&mxAttr) == 0); + assert(pthread_mutexattr_destroy(&mutexAttr) == 0); - exit(0); - - /* Never reached */ return 0; }
diff --git a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7n.c b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7n.c index d581a13..1abcc8c 100644 --- a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7n.c +++ b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7n.c
@@ -1,14 +1,10 @@ /* - * mutex7n.c - * - * - * -------------------------------------------------------------------------- - * * Pthreads-win32 - POSIX Threads Library for Win32 * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999,2005 Pthreads-win32 contributors + * Copyright(C) 2026 mingw-w64 project * - * Contact Email: rpj@callisto.canberra.edu.au + * Contact Email: mingw-w64-public@lists.sourceforge.net * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source @@ -30,37 +26,35 @@ * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Tests PTHREAD_MUTEX_NORMAL mutex type. - * Thread locks then trylocks mutex (attempted recursive lock). - * The thread should lock first time and EBUSY second time. - * - * Depends on API functions: - * pthread_create() - * pthread_mutexattr_init() - * pthread_mutexattr_settype() - * pthread_mutexattr_gettype() - * pthread_mutex_init() - * pthread_mutex_lock() - * pthread_mutex_unlock() */ #include "test.h" -static int lockCount = 0; +/** + * Test Summary: + * + * Main thread M creates mutex L with type `PTHREAD_MUTEX_NORMAL`. + * + * Thread A locks L. + * + * Thread A attempts to lock L again; the call to `pthread_mutex_trylock` must + * fail with EBUSY. + * + * Thread A unlocks L. + * + * Thread A attempts to unlock L again; the call to `pthread_mutex_unlock` must + * succeed (see comment below). + * + * Thread M destroys L. + */ -static pthread_mutex_t mutex; -static pthread_mutexattr_t mxAttr; - -void *locker(void *arg) +static void *ThreadA(void *arg) { - assert(pthread_mutex_lock(&mutex) == 0); - lockCount++; - assert(pthread_mutex_trylock(&mutex) == EBUSY); - lockCount++; - assert(pthread_mutex_unlock(&mutex) == 0); + pthread_mutex_t *mutex = arg; + + assert(pthread_mutex_lock(mutex) == 0); + assert(pthread_mutex_trylock(mutex) == EBUSY); + assert(pthread_mutex_unlock(mutex) == 0); /** * POSIX states that calling `pthread_mutex_unlock` on NORMAL mutex that is * not owned by the calling thread is undefined behavior. @@ -68,29 +62,29 @@ * Our implementation for NORMAL mutexes does not check ownership at all, * so call to `pthread_mutex_unlock` on a valid NORMAL mutex always succeeds. */ - assert(pthread_mutex_unlock(&mutex) == 0); + assert(pthread_mutex_unlock(mutex) == 0); - return (void *) 555; + return arg; } int main(void) { - pthread_t t; - int mxType = -1; + pthread_mutexattr_t mutexAttr; + pthread_mutex_t mutex; + pthread_t thread; + int mutexType; + void *result; - assert(pthread_mutexattr_init(&mxAttr) == 0); - assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0); - assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); - assert(mxType == PTHREAD_MUTEX_NORMAL); + assert(pthread_mutexattr_init(&mutexAttr) == 0); + assert(pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_NORMAL) == 0); + assert(pthread_mutexattr_gettype(&mutexAttr, &mutexType) == 0); + assert(mutexType == PTHREAD_MUTEX_NORMAL); + assert(pthread_mutex_init(&mutex, &mutexAttr) == 0); + assert(pthread_create(&thread, NULL, ThreadA, &mutex) == 0); + assert(pthread_join(thread, &result) == 0); + assert(result == &mutex); + assert(pthread_mutex_destroy(&mutex) == 0); + assert(pthread_mutexattr_destroy(&mutexAttr) == 0); - assert(pthread_mutex_init(&mutex, &mxAttr) == 0); - - assert(pthread_create(&t, NULL, locker, NULL) == 0); - Sleep(1000); - assert(lockCount == 2); - - exit(0); - - /* Never reached */ return 0; }
diff --git a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7r.c b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7r.c index 2de774d..2c0c02b 100644 --- a/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7r.c +++ b/mingw-w64-libraries/winpthreads/tests/pthread_mutex/mutex7r.c
@@ -1,14 +1,10 @@ /* - * mutex7r.c - * - * - * -------------------------------------------------------------------------- - * * Pthreads-win32 - POSIX Threads Library for Win32 * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999,2005 Pthreads-win32 contributors + * Copyright(C) 2026 mingw-w64 project * - * Contact Email: rpj@callisto.canberra.edu.au + * Contact Email: mingw-w64-public@lists.sourceforge.net * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source @@ -30,68 +26,58 @@ * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * -------------------------------------------------------------------------- - * - * Tests PTHREAD_MUTEX_RECURSIVE mutex type. - * Thread locks mutex then trylocks mutex (recursive lock twice). - * Both locks and unlocks should succeed. - * - * Depends on API functions: - * pthread_create() - * pthread_join() - * pthread_mutexattr_init() - * pthread_mutexattr_destroy() - * pthread_mutexattr_settype() - * pthread_mutexattr_gettype() - * pthread_mutex_init() - * pthread_mutex_destroy() - * pthread_mutex_lock() - * pthread_mutex_unlock() */ #include "test.h" -static int lockCount = 0; +/** + * Test Summary: + * + * Main thread M creates mutex L with type `PTHREAD_MUTEX_RECURSIVE`. + * + * Thread A locks L. + * + * Thread A attempts to lock L again; the call to `pthread_mutex_trylock` must + * succeed. + * + * Thread A unlocks L. + * + * Thread A attempts to unlock L again; the call to `pthread_mutex_unlock` must + * succeed. + * + * Thread M destroys L. + */ -static pthread_mutex_t mutex; -static pthread_mutexattr_t mxAttr; - -void *locker(void *arg) +static void *ThreadA(void *arg) { - assert(pthread_mutex_lock(&mutex) == 0); - lockCount++; - assert(pthread_mutex_trylock(&mutex) == 0); - lockCount++; - assert(pthread_mutex_unlock(&mutex) == 0); - assert(pthread_mutex_unlock(&mutex) == 0); + pthread_mutex_t *mutex = arg; - return (void *) 555; + assert(pthread_mutex_lock(mutex) == 0); + assert(pthread_mutex_trylock(mutex) == 0); + assert(pthread_mutex_unlock(mutex) == 0); + assert(pthread_mutex_unlock(mutex) == 0); + + return arg; } int main(void) { - pthread_t t; - intptr_t result = 0; - int mxType = -1; + pthread_mutexattr_t mutexAttr; + pthread_mutex_t mutex; + pthread_t thread; + int mutexType; + void *result; - assert(pthread_mutexattr_init(&mxAttr) == 0); - assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0); - assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0); - assert(mxType == PTHREAD_MUTEX_RECURSIVE); - - assert(pthread_mutex_init(&mutex, &mxAttr) == 0); - - assert(pthread_create(&t, NULL, locker, NULL) == 0); - assert(pthread_join(t, (void **) &result) == 0); - assert(result == 555); - assert(lockCount == 2); - + assert(pthread_mutexattr_init(&mutexAttr) == 0); + assert(pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE) == 0); + assert(pthread_mutexattr_gettype(&mutexAttr, &mutexType) == 0); + assert(mutexType == PTHREAD_MUTEX_RECURSIVE); + assert(pthread_mutex_init(&mutex, &mutexAttr) == 0); + assert(pthread_create(&thread, NULL, ThreadA, &mutex) == 0); + assert(pthread_join(thread, &result) == 0); + assert(result == &mutex); assert(pthread_mutex_destroy(&mutex) == 0); - assert(pthread_mutexattr_destroy(&mxAttr) == 0); + assert(pthread_mutexattr_destroy(&mutexAttr) == 0); - exit(0); - - /* Never reached */ return 0; }