From 3387a425e65b839b68bd2973f6bc5ab22315cc5d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 25 Jun 1998 19:36:00 +0000 Subject: Finish user stack support. Change locking code to be safe in situations with different priorities. 1998-06-25 19:27 Ulrich Drepper * attr.c: Finish user stack support. Change locking code to be safe in situations with different priorities. * cancel.c: Likewise. * condvar.c: Likewise. * internals.h: Likewise. * join.c: Likewise. * manager.c: Likewise. * mutex.c: Likewise. * pthread.c: Likewise. * ptlongjmp.c: Likewise. * queue.h: Likewise. * rwlock.c: Likewise. * semaphore.c: Likewise. * semaphore.h: Likewise. * signals.c: Likewise. * spinlock.c: Likewise. * spinlock.h: Likewise. Patches by Xavier leroy. 1998-06-25 Ulrich Drepper * sysdeps/pthread/pthread.h: Make [sg]et_stacksize and [sg]et_stackaddr prototypes always available. * sysdeps/unix/sysv/linux/bits/posix_opt.h: Define _POSIX_THREAD_ATTR_STACKSIZE and _POSIX_THREAD_ATTR_STACKADDR. --- linuxthreads/spinlock.h | 53 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'linuxthreads/spinlock.h') diff --git a/linuxthreads/spinlock.h b/linuxthreads/spinlock.h index 1707d3e..d21a967 100644 --- a/linuxthreads/spinlock.h +++ b/linuxthreads/spinlock.h @@ -1,7 +1,6 @@ /* Linuxthreads - a simple clone()-based implementation of Posix */ /* threads for Linux. */ -/* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) and */ -/* Richard Henderson (rth@tamu.edu) */ +/* Copyright (C) 1998 Xavier Leroy (Xavier.Leroy@inria.fr) */ /* */ /* This program is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Library General Public License */ @@ -13,20 +12,52 @@ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU Library General Public License for more details. */ -/* Spin locks */ +/* Internal locks */ -extern void __pthread_acquire(int * spinlock); +extern void __pthread_lock(struct _pthread_fastlock * lock); +extern int __pthread_trylock(struct _pthread_fastlock * lock); +extern void __pthread_unlock(struct _pthread_fastlock * lock); -static inline void acquire(int * spinlock) +static inline void __pthread_init_lock(struct _pthread_fastlock * lock) { - if (testandset(spinlock)) __pthread_acquire(spinlock); + lock->status = 0; + lock->spinlock = 0; } -static inline void release(int * spinlock) +#define LOCK_INITIALIZER {0, 0} + +#if defined(TEST_FOR_COMPARE_AND_SWAP) + +extern int __pthread_has_cas; +extern int __pthread_compare_and_swap(long * ptr, long oldval, long newval, + int * spinlock); + +static inline int compare_and_swap(long * ptr, long oldval, long newval, + int * spinlock) +{ + if (__pthread_has_cas) + return __compare_and_swap(ptr, oldval, newval); + else + return __pthread_compare_and_swap(ptr, oldval, newval, spinlock); +} + +#elif defined(HAS_COMPARE_AND_SWAP) + +static inline int compare_and_swap(long * ptr, long oldval, long newval, + int * spinlock) { -#ifndef RELEASE - *spinlock = 0; + return __compare_and_swap(ptr, oldval, newval); +} + #else - RELEASE(spinlock); -#endif + +extern int __pthread_compare_and_swap(long * ptr, long oldval, long newval, + int * spinlock); + +static inline int compare_and_swap(long * ptr, long oldval, long newval, + int * spinlock) +{ + return __pthread_compare_and_swap(ptr, oldval, newval, spinlock); } + +#endif -- cgit v1.1