From aac54e89d7945f3f4557067b1d4a1cd8853d369f Mon Sep 17 00:00:00 2001 From: rpj Date: Sat, 2 Jul 2011 06:35:21 +0000 Subject: See the ChangeLogs --- ChangeLog | 6 ++++++ implement.h | 14 +++++++------- pthread_spin_unlock.c | 3 +-- tests/Bmakefile | 2 +- tests/ChangeLog | 11 +++++++++++ tests/GNUmakefile | 2 +- tests/Makefile | 2 +- tests/Wmakefile | 2 +- tests/rwlock3.c | 4 +++- tests/rwlock4.c | 4 +++- tests/rwlock5.c | 4 +++- tests/spin3.c | 6 +++++- 12 files changed, 43 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee35762..461973b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-07-02 Ross Johnson + + * pthread_spin_unlock.c (EPERM): Return success if unlocking a lock + that is not locked, because single CPU machines wrap a + PTHREAD_MUTEX_NORMAL mutex, which returns success in this case. + 2011-07-02 Daniel Richard G. * Makefile: Cleanups and implovements. diff --git a/implement.h b/implement.h index 5344505..c4a00d2 100644 --- a/implement.h +++ b/implement.h @@ -85,21 +85,21 @@ typedef VOID (APIENTRY *PAPCFUNC)(DWORD dwParam); #else #define INLINE #endif + #if defined(_MSC_VER) && _MSC_VER < 1300 /* * MSVC 6 does not use the "volatile" qualifier */ -#define VOLATILE +#define PTW32_INTERLOCKED_VOLATILE #else -#define VOLATILE volatile +#define PTW32_INTERLOCKED_VOLATILE volatile #endif - #define PTW32_INTERLOCKED_LONG long #define PTW32_INTERLOCKED_SIZE size_t #define PTW32_INTERLOCKED_PVOID PVOID -#define PTW32_INTERLOCKED_LONGPTR VOLATILE long* -#define PTW32_INTERLOCKED_SIZEPTR VOLATILE size_t* -#define PTW32_INTERLOCKED_PVOID_PTR VOLATILE PVOID* +#define PTW32_INTERLOCKED_LONGPTR PTW32_INTERLOCKED_VOLATILE long* +#define PTW32_INTERLOCKED_SIZEPTR PTW32_INTERLOCKED_VOLATILE size_t* +#define PTW32_INTERLOCKED_PVOID_PTR PTW32_INTERLOCKED_VOLATILE PVOID* #if defined(__MINGW64__) || defined(__MINGW32__) # include @@ -147,7 +147,7 @@ struct ptw32_thread_t_ HANDLE threadH; /* Win32 thread handle - POSIX thread is invalid if threadH == 0 */ pthread_t ptHandle; /* This thread's permanent pthread_t handle */ ptw32_thread_t * prevReuse; /* Links threads on reuse stack */ - VOLATILE PThreadState state; + volatile PThreadState state; ptw32_mcs_lock_t threadLock; /* Used for serialised access to public thread state */ ptw32_mcs_lock_t stateLock; /* Used for async-cancel safety */ HANDLE cancelEvent; diff --git a/pthread_spin_unlock.c b/pthread_spin_unlock.c index 0e8add8..3a6932a 100644 --- a/pthread_spin_unlock.c +++ b/pthread_spin_unlock.c @@ -61,9 +61,8 @@ pthread_spin_unlock (pthread_spinlock_t * lock) (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED)) { case PTW32_SPIN_LOCKED: - return 0; case PTW32_SPIN_UNLOCKED: - return EPERM; + return 0; case PTW32_SPIN_USE_MUTEX: return pthread_mutex_unlock (&(s->u.mutex)); } diff --git a/tests/Bmakefile b/tests/Bmakefile index bd8d7b7..992b240 100644 --- a/tests/Bmakefile +++ b/tests/Bmakefile @@ -326,7 +326,7 @@ robust4.pass: robust3.pass robust5.pass: robust4.pass rwlock1.pass: condvar6.pass rwlock2.pass: rwlock1.pass -rwlock3.pass: rwlock2.pass +rwlock3.pass: rwlock2.pass join2.pass rwlock4.pass: rwlock3.pass rwlock5.pass: rwlock4.pass rwlock6.pass: rwlock5.pass diff --git a/tests/ChangeLog b/tests/ChangeLog index 803b4dc..91bb8ef 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,14 @@ +2011-07-02 Ross Johnson + + * spin3.c: Unlock the unlocked spinlock now returns success. + * rwlock3.c: Join the thread to ensure it's completed. + * rwlock4.c: Likewise. + * rwlock5.c: Likewise. + * Makefile: Adjust prerequisites. + * GNUmakefile: Likewise. + * Bmakefile: Likewise. + * Wmakefile: Likewise. + 2011-07-02 Daniel Richard G. * *.[ch]: Cleanups around timeb struct, mainly centralising diff --git a/tests/GNUmakefile b/tests/GNUmakefile index e0e9de5..e773433 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -348,7 +348,7 @@ robust4.pass: robust3.pass robust5.pass: robust4.pass rwlock1.pass: condvar6.pass rwlock2.pass: rwlock1.pass -rwlock3.pass: rwlock2.pass +rwlock3.pass: rwlock2.pass join2.pass rwlock4.pass: rwlock3.pass rwlock5.pass: rwlock4.pass rwlock6.pass: rwlock5.pass diff --git a/tests/Makefile b/tests/Makefile index cb4cacb..595c5b5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -417,7 +417,7 @@ robust4.pass: robust3.pass robust5.pass: robust4.pass rwlock1.pass: condvar6.pass rwlock2.pass: rwlock1.pass -rwlock3.pass: rwlock2.pass +rwlock3.pass: rwlock2.pass join2.pass rwlock4.pass: rwlock3.pass rwlock5.pass: rwlock4.pass rwlock6.pass: rwlock5.pass diff --git a/tests/Wmakefile b/tests/Wmakefile index 0fcbd43..8d5d7a5 100644 --- a/tests/Wmakefile +++ b/tests/Wmakefile @@ -324,7 +324,7 @@ robust4.pass: robust3.pass robust5.pass: robust4.pass rwlock1.pass: condvar6.pass rwlock2.pass: rwlock1.pass -rwlock3.pass: rwlock2.pass +rwlock3.pass: rwlock2.pass join2.pass rwlock4.pass: rwlock3.pass rwlock5.pass: rwlock4.pass rwlock6.pass: rwlock5.pass diff --git a/tests/rwlock3.c b/tests/rwlock3.c index 36ccf58..d30f040 100644 --- a/tests/rwlock3.c +++ b/tests/rwlock3.c @@ -37,6 +37,8 @@ * and then unlock it again. * * Depends on API functions: + * pthread_create() + * pthread_join() * pthread_rwlock_wrlock() * pthread_rwlock_trywrlock() * pthread_rwlock_unlock() @@ -66,7 +68,7 @@ main() assert(pthread_create(&t, NULL, func, NULL) == 0); - Sleep(20); + assert(pthread_join(t, NULL) == 0); assert(pthread_rwlock_unlock(&rwlock1) == 0); diff --git a/tests/rwlock4.c b/tests/rwlock4.c index 7ba6302..a19a001 100644 --- a/tests/rwlock4.c +++ b/tests/rwlock4.c @@ -37,6 +37,8 @@ * and then unlock it again. * * Depends on API functions: + * pthread_create() + * pthread_join() * pthread_rwlock_rdlock() * pthread_rwlock_trywrlock() * pthread_rwlock_unlock() @@ -66,7 +68,7 @@ main() assert(pthread_create(&t, NULL, func, NULL) == 0); - Sleep(20); + assert(pthread_join(t, NULL) == 0); assert(pthread_rwlock_unlock(&rwlock1) == 0); diff --git a/tests/rwlock5.c b/tests/rwlock5.c index 75880cd..3b40547 100644 --- a/tests/rwlock5.c +++ b/tests/rwlock5.c @@ -37,6 +37,8 @@ * and then unlock it again. * * Depends on API functions: + * pthread_create() + * pthread_join() * pthread_rwlock_rdlock() * pthread_rwlock_tryrdlock() * pthread_rwlock_unlock() @@ -68,7 +70,7 @@ main() assert(pthread_create(&t, NULL, func, NULL) == 0); - Sleep(20); + assert(pthread_join(t, NULL) == 0); assert(pthread_rwlock_unlock(&rwlock1) == 0); diff --git a/tests/spin3.c b/tests/spin3.c index fa16b35..bbf8bfb 100644 --- a/tests/spin3.c +++ b/tests/spin3.c @@ -64,7 +64,11 @@ main() assert(pthread_spin_lock(&spin) == 0); assert(pthread_create(&t, NULL, unlocker, (void*)0) == 0); assert(pthread_join(t, NULL) == 0); - assert(pthread_spin_unlock(&spin) == EPERM); + /* + * Our spinlocks don't record the owner thread so any thread can unlock the spinlock, + * but nor is it an error for any thread to unlock a spinlock that is not locked. + */ + assert(pthread_spin_unlock(&spin) == 0); assert(pthread_spin_destroy(&spin) == 0); assert(wasHere == 2); -- cgit v1.2.3