aboutsummaryrefslogtreecommitdiff
path: root/linuxthreads/spinlock.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-06-25 19:36:00 +0000
committerUlrich Drepper <drepper@redhat.com>1998-06-25 19:36:00 +0000
commit3387a425e65b839b68bd2973f6bc5ab22315cc5d (patch)
tree375713a0b865b10b9eddd9c9877ad68cf0bdc851 /linuxthreads/spinlock.h
parentd47aac39992cb1dd705d8c584f4d3979d7ce4602 (diff)
downloadglibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.zip
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar.gz
glibc-3387a425e65b839b68bd2973f6bc5ab22315cc5d.tar.bz2
Finish user stack support. Change locking code to be safe in situations with different priorities.
1998-06-25 19:27 Ulrich Drepper <drepper@cygnus.com> * 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 <drepper@cygnus.com> * 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.
Diffstat (limited to 'linuxthreads/spinlock.h')
-rw-r--r--linuxthreads/spinlock.h53
1 files changed, 42 insertions, 11 deletions
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