summaryrefslogtreecommitdiff
path: root/include/atomic
diff options
context:
space:
mode:
authorMikael Ronstrom <mikael@mysql.com>2009-11-27 18:11:05 +0100
committerMikael Ronstrom <mikael@mysql.com>2009-11-27 18:11:05 +0100
commit566bcab328d05c215ef7f4bddd603e0361f40e72 (patch)
tree87365effe6f9f67269ad7c47f5136f34a867ae52 /include/atomic
parent9ea65e5fa98ad56925d709d853a621de38cf1a71 (diff)
parent3c11750e363da6e1017d5bc86e9e7e03b2c4e101 (diff)
downloadmariadb-git-566bcab328d05c215ef7f4bddd603e0361f40e72.tar.gz
Merge WL#5138 to mysql-next-mr
Diffstat (limited to 'include/atomic')
-rw-r--r--include/atomic/rwlock.h45
-rw-r--r--include/atomic/x86-gcc.h3
2 files changed, 42 insertions, 6 deletions
diff --git a/include/atomic/rwlock.h b/include/atomic/rwlock.h
index 29e22fcb3d5..a31f8ed6ca1 100644
--- a/include/atomic/rwlock.h
+++ b/include/atomic/rwlock.h
@@ -1,7 +1,7 @@
#ifndef ATOMIC_RWLOCK_INCLUDED
#define ATOMIC_RWLOCK_INCLUDED
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (C) 2006 MySQL AB, 2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,7 +16,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
#define MY_ATOMIC_MODE_RWLOCKS 1
#ifdef MY_ATOMIC_MODE_DUMMY
@@ -27,6 +26,9 @@ typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
implementations (another way is to run a UP build on an SMP box).
*/
#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible
+
+typedef char my_atomic_rwlock_t;
+
#define my_atomic_rwlock_destroy(name)
#define my_atomic_rwlock_init(name)
#define my_atomic_rwlock_rdlock(name)
@@ -34,7 +36,12 @@ typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
#define my_atomic_rwlock_rdunlock(name)
#define my_atomic_rwlock_wrunlock(name)
#define MY_ATOMIC_MODE "dummy (non-atomic)"
-#else
+#else /* not MY_ATOMIC_MODE_DUMMY */
+
+typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
+
+#ifndef SAFE_MUTEX
+
/*
we're using read-write lock macros but map them to mutex locks, and they're
faster. Still, having semantically rich API we can change the
@@ -46,6 +53,38 @@ typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw)
#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw)
#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw)
+
+#else /* SAFE_MUTEX */
+
+/*
+ SAFE_MUTEX pollutes the compiling name space with macros
+ that alter pthread_mutex_t, pthread_mutex_init, etc.
+ Atomic operations should never use the safe mutex wrappers.
+ Unfortunately, there is no way to have both:
+ - safe mutex macros expanding pthread_mutex_lock to safe_mutex_lock
+ - my_atomic macros expanding to unmodified pthread_mutex_lock
+ inlined in the same compilation unit.
+ So, in case of SAFE_MUTEX, a function call is required.
+ Given that SAFE_MUTEX is a debugging facility,
+ this extra function call is not a performance concern for
+ production builds.
+*/
+C_MODE_START
+extern void plain_pthread_mutex_init(safe_mutex_t *);
+extern void plain_pthread_mutex_destroy(safe_mutex_t *);
+extern void plain_pthread_mutex_lock(safe_mutex_t *);
+extern void plain_pthread_mutex_unlock(safe_mutex_t *);
+C_MODE_END
+
+#define my_atomic_rwlock_destroy(name) plain_pthread_mutex_destroy(&(name)->rw)
+#define my_atomic_rwlock_init(name) plain_pthread_mutex_init(&(name)->rw)
+#define my_atomic_rwlock_rdlock(name) plain_pthread_mutex_lock(&(name)->rw)
+#define my_atomic_rwlock_wrlock(name) plain_pthread_mutex_lock(&(name)->rw)
+#define my_atomic_rwlock_rdunlock(name) plain_pthread_mutex_unlock(&(name)->rw)
+#define my_atomic_rwlock_wrunlock(name) plain_pthread_mutex_unlock(&(name)->rw)
+
+#endif /* SAFE_MUTEX */
+
#define MY_ATOMIC_MODE "mutex"
#ifndef MY_ATOMIC_MODE_RWLOCKS
#define MY_ATOMIC_MODE_RWLOCKS 1
diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h
index cbdb2d11e68..e5e88fa58ff 100644
--- a/include/atomic/x86-gcc.h
+++ b/include/atomic/x86-gcc.h
@@ -88,7 +88,4 @@
#define make_atomic_store_body(S) \
asm volatile ("; xchg %0, %1;" : "+m" (*a), "+r" (v))
#endif
-
-/* TODO test on intel whether the below helps. on AMD it makes no difference */
-//#define LF_BACKOFF ({asm volatile ("rep; nop"); 1; })
#endif /* ATOMIC_X86_GCC_INCLUDED */