Skip to content

Instantly share code, notes, and snippets.

@macdice
Last active June 15, 2018 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macdice/ba85887538b4e3f37b257b37b81967cf to your computer and use it in GitHub Desktop.
Save macdice/ba85887538b4e3f37b257b37b81967cf to your computer and use it in GitHub Desktop.
From bf72499bfecd4a6ea4757a445a2b711461639a56 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Fri, 15 Jun 2018 16:17:51 +1200
Subject: [PATCH] Experimental spinlock changes on amd64. Not tested.
Based on code review from mjg@freebsd.org, the LOCK prefix is redundant and
serves only to make the .text segment larger, and the fallback behaviour after
TAS() returns true should be to delay first, and then TAS_SPIN().
It may be that the logic in finish_spin_delay needs tweaking.
---
src/backend/storage/lmgr/s_lock.c | 4 ++--
src/include/storage/s_lock.h | 1 -
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/backend/storage/lmgr/s_lock.c b/src/backend/storage/lmgr/s_lock.c
index 7482b2d44b..84de03b0fc 100644
--- a/src/backend/storage/lmgr/s_lock.c
+++ b/src/backend/storage/lmgr/s_lock.c
@@ -95,10 +95,10 @@ s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
init_spin_delay(&delayStatus, file, line, func);
- while (TAS_SPIN(lock))
+ do
{
perform_spin_delay(&delayStatus);
- }
+ } while (TAS_SPIN(lock));
finish_spin_delay(&delayStatus);
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 04175dbaaa..aede2c7ddc 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -226,7 +226,6 @@ tas(volatile slock_t *lock)
register slock_t _res = 1;
__asm__ __volatile__(
- " lock \n"
" xchgb %0,%1 \n"
: "+q"(_res), "+m"(*lock)
: /* no inputs */
--
2.17.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment