summaryrefslogtreecommitdiff
path: root/src/include/storage/s_lock.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-01-07 15:38:52 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-01-07 15:38:52 -0500
commit0a41e865845bfa5d7aafcc5fe000dafa26573fef (patch)
treed11383fae426e60b58c5fd5a231297a51245b3a6 /src/include/storage/s_lock.h
parent1fc3d18faa8f4476944bc6854be0f7f6adf4aec8 (diff)
downloadpostgresql-0a41e865845bfa5d7aafcc5fe000dafa26573fef.tar.gz
Use __sync_lock_test_and_set() for spinlocks on ARM, if available.
Historically we've used the SWPB instruction for TAS() on ARM, but this is deprecated and not available on ARMv6 and later. Instead, make use of a GCC builtin if available. We'll still fall back to SWPB if not, so as not to break existing ports using older GCC versions. Eventually we might want to try using __sync_lock_test_and_set() on some other architectures too, but for now that seems to present only risk and not reward. Back-patch to all supported versions, since people might want to use any of them on more recent ARM chips. Martin Pitt
Diffstat (limited to 'src/include/storage/s_lock.h')
-rw-r--r--src/include/storage/s_lock.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 9b02d1f5a4..074838e525 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -275,13 +275,33 @@ tas(volatile slock_t *lock)
#endif /* __ia64__ || __ia64 */
+/*
+ * On ARM, we use __sync_lock_test_and_set(int *, int) if available, and if
+ * not fall back on the SWPB instruction. SWPB does not work on ARMv6 or
+ * later, so the compiler builtin is preferred if available. Note also that
+ * the int-width variant of the builtin works on more chips than other widths.
+ */
#if defined(__arm__) || defined(__arm)
#define HAS_TEST_AND_SET
-typedef unsigned char slock_t;
-
#define TAS(lock) tas(lock)
+#ifdef HAVE_GCC_INT_ATOMICS
+
+typedef int slock_t;
+
+static __inline__ int
+tas(volatile slock_t *lock)
+{
+ return __sync_lock_test_and_set(lock, 1);
+}
+
+#define S_UNLOCK(lock) __sync_lock_release(lock)
+
+#else /* !HAVE_GCC_INT_ATOMICS */
+
+typedef unsigned char slock_t;
+
static __inline__ int
tas(volatile slock_t *lock)
{
@@ -295,6 +315,7 @@ tas(volatile slock_t *lock)
return (int) _res;
}
+#endif /* HAVE_GCC_INT_ATOMICS */
#endif /* __arm__ */