93#error "s_lock.h may not be included from frontend code"
96#if defined(__GNUC__) || defined(__INTEL_COMPILER)
127#define HAS_TEST_AND_SET
131#define TAS(lock) tas(lock)
155:
"+q"(
_res),
"+m"(*lock)
161#define SPIN_DELAY() spin_delay()
197#define HAS_TEST_AND_SET
201#define TAS(lock) tas(lock)
212#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
222:
"+q"(
_res),
"+m"(*lock)
228#define SPIN_DELAY() spin_delay()
250#if defined(__arm__) || defined(__arm) || defined(__aarch64__)
251#ifdef HAVE_GCC__SYNC_INT32_TAS
252#define HAS_TEST_AND_SET
254#define TAS(lock) tas(lock)
264#define S_UNLOCK(lock) __sync_lock_release(lock)
266#if defined(__aarch64__)
272#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
274#define SPIN_DELAY() spin_delay()
294#if defined(__s390__) || defined(__s390x__)
295#define HAS_TEST_AND_SET
299#define TAS(lock) tas(lock)
308:
"+d"(
_res),
"+m"(*lock)
317#if defined(__sparc__)
324#define HAS_TEST_AND_SET
328#define TAS(lock) tas(lock)
341 " ldstub [%2], %0 \n"
342:
"=r"(
_res),
"+m"(*lock)
345#if defined(__sparcv7) || defined(__sparc_v7__)
350#elif defined(__sparcv8) || defined(__sparc_v8__)
363#if defined(__sparcv7) || defined(__sparc_v7__)
369#elif defined(__sparcv8) || defined(__sparc_v8__)
371#define S_UNLOCK(lock) \
374 __asm__ __volatile__ ("stbar \n":::"memory"); \
375 *((volatile slock_t *) (lock)) = 0; \
382#define S_UNLOCK(lock) \
385 __asm__ __volatile__ ("membar #LoadStore | #StoreStore \n":::"memory"); \
386 *((volatile slock_t *) (lock)) = 0; \
394#if defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__) || defined(__powerpc64__)
395#define HAS_TEST_AND_SET
399#define TAS(lock) tas(lock)
402#define TAS_SPIN(lock) (*(lock) ? 1 : TAS(lock))
435:
"=&b"(
_t),
"=r"(
_res),
"+m"(*lock)
445#define S_UNLOCK(lock) \
448 __asm__ __volatile__ (" lwsync \n" ::: "memory"); \
449 *((volatile slock_t *) (lock)) = 0; \
455#if defined(__mips__) && !defined(__sgi)
456#define HAS_TEST_AND_SET
460#define TAS(lock) tas(lock)
476#define MIPS_SET_MIPS2 " .set mips2 \n"
478#define MIPS_SET_MIPS2
507#define S_UNLOCK(lock) \
510 __asm__ __volatile__( \
513 " .set noreorder \n" \
520 *((volatile slock_t *) (lock)) = 0; \
534#if !defined(HAS_TEST_AND_SET)
536#if defined(HAVE_GCC__SYNC_INT32_TAS)
537#define HAS_TEST_AND_SET
539#define TAS(lock) tas(lock)
549#define S_UNLOCK(lock) __sync_lock_release(lock)
551#elif defined(HAVE_GCC__SYNC_CHAR_TAS)
552#define HAS_TEST_AND_SET
554#define TAS(lock) tas(lock)
564#define S_UNLOCK(lock) __sync_lock_release(lock)
581#if !defined(S_UNLOCK)
582#define S_UNLOCK(lock) \
583 do { __asm__ __volatile__("" : : : "memory"); *(lock) = 0; } while (0)
595#if !defined(HAS_TEST_AND_SET)
600#define HAS_TEST_AND_SET
601#define TAS(lock) (InterlockedCompareExchange(lock, 1, 0))
603#define SPIN_DELAY() spin_delay()
639#pragma intrinsic(_InterlockedExchange)
640#define S_UNLOCK(lock) _InterlockedExchange(lock, 0)
644#pragma intrinsic(_ReadWriteBarrier)
645#define S_UNLOCK(lock) \
646 do { _ReadWriteBarrier(); (*(lock)) = 0; } while (0)
656#ifndef HAS_TEST_AND_SET
657#error PostgreSQL does not have spinlock support on this platform. Please report this to pgsql-bugs@lists.postgresql.org.
666#define S_LOCK(lock) \
667 (TAS(lock) ? s_lock((lock), __FILE__, __LINE__, __func__) : 0)
670#if !defined(S_LOCK_FREE)
671#define S_LOCK_FREE(lock) (*(lock) == 0)
674#if !defined(S_UNLOCK)
691#define USE_DEFAULT_S_UNLOCK
693#define S_UNLOCK(lock) s_unlock(lock)
696#if !defined(S_INIT_LOCK)
697#define S_INIT_LOCK(lock) S_UNLOCK(lock)
700#if !defined(SPIN_DELAY)
701#define SPIN_DELAY() ((void) 0)
708#define TAS(lock) tas(lock)
711#if !defined(TAS_SPIN)
712#define TAS_SPIN(lock) TAS(lock)
719extern int s_lock(
volatile slock_t *lock,
const char *file,
int line,
const char *func);
722#define DEFAULT_SPINS_PER_DELAY 100
743 const char *file,
int line,
const char *func)
753#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)