summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2008-03-22 17:59:12 +0000
committerad <ad@NetBSD.org>2008-03-22 17:59:12 +0000
commitecdd2c2965f7ecca0ae441c5bcc92bcaf18281c1 (patch)
tree6ca9e79b7964a6427d8bf58ddbdbed21c3d0a275 /lib/libpthread
parent521414740702ea8a79c6e643c78d58f1f5bc3290 (diff)
Cheat and add inlines for _atomic_cas_ptr() to work around gcc emitting
unneeded PIC stuff in mutex_lock() and mutex_unlock(), when a thread register is used.
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/arch/i386/pthread_md.h30
-rw-r--r--lib/libpthread/arch/x86_64/pthread_md.h28
2 files changed, 55 insertions, 3 deletions
diff --git a/lib/libpthread/arch/i386/pthread_md.h b/lib/libpthread/arch/i386/pthread_md.h
index 6128b557c18..4929247e4d7 100644
--- a/lib/libpthread/arch/i386/pthread_md.h
+++ b/lib/libpthread/arch/i386/pthread_md.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.12 2008/02/10 18:50:55 ad Exp $ */
+/* $NetBSD: pthread_md.h,v 1.13 2008/03/22 17:59:12 ad Exp $ */
/*-
* Copyright (c) 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -182,7 +182,7 @@ pthread__sp(void)
} while (/*CONSTCOND*/0)
#define pthread__smt_pause() __asm __volatile("rep; nop" ::: "memory")
-/* #define PTHREAD__HAVE_THREADREG */
+/* #define PTHREAD__HAVE_THREADREG */
/* Don't need additional memory barriers. */
#define PTHREAD__ATOMIC_IS_MEMBAR
@@ -201,4 +201,30 @@ pthread__threadreg_get(void)
return self;
}
+static inline void *
+_atomic_cas_ptr(volatile void *ptr, void *old, void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("lock; cmpxchgl %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
+static inline void *
+_atomic_cas_ptr_ni(volatile void *ptr, void *old, void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("cmpxchgl %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
#endif /* _LIB_PTHREAD_I386_MD_H */
diff --git a/lib/libpthread/arch/x86_64/pthread_md.h b/lib/libpthread/arch/x86_64/pthread_md.h
index 6db24f0faf0..bb98adefffe 100644
--- a/lib/libpthread/arch/x86_64/pthread_md.h
+++ b/lib/libpthread/arch/x86_64/pthread_md.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_md.h,v 1.8 2008/02/10 18:50:55 ad Exp $ */
+/* $NetBSD: pthread_md.h,v 1.9 2008/03/22 17:59:12 ad Exp $ */
/*-
* Copyright (c) 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -108,4 +108,30 @@ pthread__sp(void)
/* Don't need additional memory barriers. */
#define PTHREAD__ATOMIC_IS_MEMBAR
+static inline void *
+_atomic_cas_ptr(volatile void *ptr, void *old, void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("lock; cmpxchgq %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
+static inline void *
+_atomic_cas_ptr_ni(volatile void *ptr, void *old, void *new)
+{
+ volatile uintptr_t *cast = ptr;
+ void *ret;
+
+ __asm __volatile ("cmpxchgq %2, %1"
+ : "=a" (ret), "=m" (*cast)
+ : "r" (new), "m" (*cast), "0" (old));
+
+ return ret;
+}
+
#endif /* _LIB_PTHREAD_X86_64_MD_H */