58 #define MIN_SPINS_PER_DELAY 10
59 #define MAX_SPINS_PER_DELAY 1000
60 #define NUM_DELAYS 1000
61 #define MIN_DELAY_USEC 1000L
62 #define MAX_DELAY_USEC 1000000L
78 #if defined(S_LOCK_TEST)
80 "\nStuck spinlock detected at %s, %s:%d.\n",
84 elog(
PANIC,
"stuck spinlock detected at %s, %s:%d",
93 s_lock(
volatile slock_t *lock,
const char *file,
int line,
const char *func)
106 return delayStatus.
delays;
109 #ifdef USE_DEFAULT_S_UNLOCK
111 s_unlock(
volatile slock_t *lock)
113 #ifdef TAS_ACTIVE_WORD
115 *TAS_ACTIVE_WORD(lock) = -1;
152 #if defined(S_LOCK_TEST)
235 #if defined(S_LOCK_TEST)
241 struct test_lock_struct
248 volatile struct test_lock_struct test_lock;
255 test_lock.pad1 = test_lock.pad2 = 0x44;
259 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
261 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
267 printf(
"S_LOCK_TEST: failed, lock not initialized\n");
273 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
275 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
281 printf(
"S_LOCK_TEST: failed, lock not locked\n");
287 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
289 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
295 printf(
"S_LOCK_TEST: failed, lock not unlocked\n");
301 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
303 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
309 printf(
"S_LOCK_TEST: failed, lock not re-locked\n");
314 printf(
" exit with a 'stuck spinlock' message\n");
315 printf(
" if S_LOCK() and TAS() are working.\n");
318 s_lock(&test_lock.lock, __FILE__, __LINE__, __func__);
320 printf(
"S_LOCK_TEST: failed, lock not locked\n");
elog(ERROR, "%s: %s", p2, msg)
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
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)
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)