93#error "s_lock.h may not be included from frontend code"
96#if defined(__GNUC__) || defined(__INTEL_COMPILER)
131#define HAS_TEST_AND_SET
135#define TAS(lock) tas(lock)
159:
"+q"(
_res),
"+m"(*lock)
165#define SPIN_DELAY() spin_delay()
201#define HAS_TEST_AND_SET
205#define TAS(lock) tas(lock)
216#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
226:
"+q"(
_res),
"+m"(*lock)
232#define SPIN_DELAY() spin_delay()
254#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
255#ifdef HAVE_GCC__SYNC_INT32_TAS
256#define HAS_TEST_AND_SET
258#define TAS(lock) tas(lock)
268#define S_UNLOCK(lock) __sync_lock_release(lock)
270#if defined(__aarch64__)
276#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
278#define SPIN_DELAY() spin_delay()
298#if defined(__s390__) || defined(__s390x__)
299#define HAS_TEST_AND_SET
303#define TAS(lock) tas(lock)
312:
"+d"(
_res),
"+m"(*lock)
321#if defined(__sparc__)
328#define HAS_TEST_AND_SET
332#define TAS(lock) tas(lock)
345 " ldstub [%2], %0 \n"
346:
"=r"(
_res),
"+m"(*lock)
349#if defined(__sparcv7) || defined(__sparc_v7__)
354#elif defined(__sparcv8) || defined(__sparc_v8__)
367#if defined(__sparcv7) || defined(__sparc_v7__)
373#elif defined(__sparcv8) || defined(__sparc_v8__)
375#define S_UNLOCK(lock) \
378 __asm__ __volatile__ ("stbar \n":::"memory"); \
379 *((volatile slock_t *) (lock)) = 0; \
386#define S_UNLOCK(lock) \
389 __asm__ __volatile__ ("membar #LoadStore | #StoreStore \n":::"memory"); \
390 *((volatile slock_t *) (lock)) = 0; \
398#if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__)
399#define HAS_TEST_AND_SET
403#define TAS(lock) tas(lock)
406#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
439:
"=&b"(
_t),
"=r"(
_res),
"+m"(*lock)
449#define S_UNLOCK(lock) \
452 __asm__ __volatile__ (" lwsync \n" ::: "memory"); \
453 *((volatile slock_t *) (lock)) = 0; \
459#if defined(__mips__) && !defined(__sgi)
460#define HAS_TEST_AND_SET
464#define TAS(lock) tas(lock)
480#define MIPS_SET_MIPS2 " .set mips2 \n"
482#define MIPS_SET_MIPS2
511#define S_UNLOCK(lock) \
514 __asm__ __volatile__( \
517 " .set noreorder \n" \
524 *((volatile slock_t *) (lock)) = 0; \
538#if !defined(HAS_TEST_AND_SET)
540#if defined(HAVE_GCC__SYNC_INT32_TAS)
541#define HAS_TEST_AND_SET
543#define TAS(lock) tas(lock)
553#define S_UNLOCK(lock) __sync_lock_release(lock)
555#elif defined(HAVE_GCC__SYNC_CHAR_TAS)
556#define HAS_TEST_AND_SET
558#define TAS(lock) tas(lock)
568#define S_UNLOCK(lock) __sync_lock_release(lock)
585#if !defined(S_UNLOCK)
586#define S_UNLOCK(lock) \
587 do { __asm__ __volatile__("" : : : "memory"); *(lock) = 0; } while (0)
599#if !defined(HAS_TEST_AND_SET)
604#define HAS_TEST_AND_SET
605#define TAS(lock) (InterlockedCompareExchange(lock, 1, 0))
607#define SPIN_DELAY() spin_delay()
643#pragma intrinsic(_InterlockedExchange)
644#define S_UNLOCK(lock) _InterlockedExchange(lock, 0)
648#pragma intrinsic(_ReadWriteBarrier)
649#define S_UNLOCK(lock) \
650 do { _ReadWriteBarrier(); (*(lock)) = 0; } while (0)
660#ifndef HAS_TEST_AND_SET
661#error PostgreSQL does not have spinlock support on this platform. Please report this to pgsql-bugs@lists.postgresql.org.
670#define S_LOCK(lock) \
671 (TAS(lock) ? s_lock((lock), __FILE__, __LINE__, __func__) : 0)
674#if !defined(S_LOCK_FREE)
675#define S_LOCK_FREE(lock) (*(lock) == 0)
678#if !defined(S_UNLOCK)
695#define USE_DEFAULT_S_UNLOCK
697#define S_UNLOCK(lock) s_unlock(lock)
700#if !defined(S_INIT_LOCK)
701#define S_INIT_LOCK(lock) S_UNLOCK(lock)
704#if !defined(SPIN_DELAY)
705#define SPIN_DELAY() ((void) 0)
712#define TAS(lock) tas(lock)
715#if !defined(TAS_SPIN)
716#define TAS_SPIN(lock) TAS(lock)
723extern int s_lock(
volatile slock_t *lock,
const char *file,
int line,
const char *func);
726#define DEFAULT_SPINS_PER_DELAY 100
747 const char *file,
int line,
const char *func)
757#define init_local_spin_delay(status) init_spin_delay(status, __FILE__, __LINE__, __func__)
void set_spins_per_delay(int shared_spins_per_delay)
void perform_spin_delay(SpinDelayStatus *status)
int tas(volatile slock_t *lock)
static void init_spin_delay(SpinDelayStatus *status, const char *file, int line, const char *func)
void finish_spin_delay(SpinDelayStatus *status)
int s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
void s_unlock(volatile slock_t *lock)
int update_spins_per_delay(int shared_spins_per_delay)