From 06974b302eaf8f08382e6e786aea53f420c12222 Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 6 Jul 2001 18:16:50 +0000 Subject: Spinlocks and barriers fixed and working. Beta level. * spin.c: Revamped and working; included static initialiser. * barrier.c: Likewise. * condvar.c: Macro constant change; inline auto init routine. * mutex.c: Likewise. * rwlock.c: Likewise. * private.c: Add support for spinlock initialiser. * global.c: Likewise. * implement.h: Likewise. * pthread.h (PTHREAD_SPINLOCK_INITIALIZER): Fix typo. tests/ChangeLog: * spin3.c: Changed test and fixed. * spin4.c: Fixed. * barrier3.c: Fixed. * barrier4.c: Fixed. --- tests/spin4.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tests/spin4.c') diff --git a/tests/spin4.c b/tests/spin4.c index a435d04..5f04a27 100644 --- a/tests/spin4.c +++ b/tests/spin4.c @@ -1,19 +1,14 @@ /* * spin4.c * - * Declare a spinlock object, lock it, spin on it, + * Declare a static spinlock object, lock it, spin on it, * and then unlock it again. - * - * For this to work on a single processor machine we have - * to static initialise the spinlock. This bypasses the - * check of the number of processors done by pthread_spin_init. - * This is a non-portable side-effect of this implementation. */ #include "test.h" #include -pthread_spinlock_t lock = PTHREADS_SPINLOCK_INITIALIZER; +pthread_spinlock_t lock = PTHREAD_SPINLOCK_INITIALIZER; struct _timeb currSysTimeStart; struct _timeb currSysTimeStop; @@ -37,7 +32,16 @@ int main() { long result = 0; + int i; pthread_t t; + int CPUs; + + if (pthread_getprocessors_np(&CPUs) != 0 || CPUs == 1) + { + printf("This test is not applicable to this system.\n"); + printf("Either there is only 1 CPU or the no. could not be determined.\n"); + exit(0); + } assert(pthread_spin_lock(&lock) == 0); @@ -47,6 +51,7 @@ main() * This should relinqish the CPU to the func thread enough times * to waste approximately 2000 millisecs only if the lock really * is spinning in the func thread (assuming 10 millisec CPU quantum). + */ for (i = 0; i < 200; i++) { sched_yield(); -- cgit v1.2.3