57 #define MIN_SPINS_PER_DELAY 10
58 #define MAX_SPINS_PER_DELAY 1000
59 #define NUM_DELAYS 1000
60 #define MIN_DELAY_USEC 1000L
61 #define MAX_DELAY_USEC 1000000L
77 #if defined(S_LOCK_TEST)
79 "\nStuck spinlock detected at %s, %s:%d.\n",
83 elog(
PANIC,
"stuck spinlock detected at %s, %s:%d",
92 s_lock(
volatile slock_t *lock,
const char *file,
int line,
const char *func)
105 return delayStatus.
delays;
108 #ifdef USE_DEFAULT_S_UNLOCK
110 s_unlock(
volatile slock_t *lock)
112 #ifdef TAS_ACTIVE_WORD
114 *TAS_ACTIVE_WORD(lock) = -1;
136 if (
status->cur_delay == 0)
141 #if defined(S_LOCK_TEST)
177 if (
status->cur_delay == 0)
233 #ifdef HAVE_SPINLOCKS
236 #if defined(__GNUC__)
248 #if defined(__m68k__) && !defined(__linux__)
253 __asm__ __volatile__(
254 #
if (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(__ELF__)
259 movel %sp@(0x4),%a0 \n\
271 movel sp@(0x4),a0 \n\
289 #if defined(S_LOCK_TEST)
295 struct test_lock_struct
302 volatile struct test_lock_struct test_lock;
309 test_lock.pad1 = test_lock.pad2 = 0x44;
313 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
315 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
321 printf(
"S_LOCK_TEST: failed, lock not initialized\n");
327 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
329 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
335 printf(
"S_LOCK_TEST: failed, lock not locked\n");
341 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
343 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
349 printf(
"S_LOCK_TEST: failed, lock not unlocked\n");
355 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
357 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
363 printf(
"S_LOCK_TEST: failed, lock not re-locked\n");
368 printf(
" exit with a 'stuck spinlock' message\n");
369 printf(
" if S_LOCK() and TAS() are working.\n");
374 printf(
"S_LOCK_TEST: failed, lock not locked\n");
#define PG_FUNCNAME_MACRO
static void const char fflush(stdout)
int main(int argc, char **argv)
double pg_prng_double(pg_prng_state *state)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
pg_prng_state pg_global_prng_state
static void static void status(const char *fmt,...) pg_attribute_printf(1
void set_spins_per_delay(int shared_spins_per_delay)
void perform_spin_delay(SpinDelayStatus *status)
void finish_spin_delay(SpinDelayStatus *status)
int s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
#define MAX_SPINS_PER_DELAY
#define MIN_SPINS_PER_DELAY
int update_spins_per_delay(int shared_spins_per_delay)
static int spins_per_delay
static void s_lock_stuck(const char *file, int line, const char *func)
#define DEFAULT_SPINS_PER_DELAY
#define S_LOCK_FREE(lock)
static void init_spin_delay(SpinDelayStatus *status, const char *file, int line, const char *func)
#define S_INIT_LOCK(lock)
void pg_usleep(long microsec)