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
84 #if defined(S_LOCK_TEST)
86 "\nStuck spinlock detected at %s, %s:%d.\n",
90 elog(
PANIC,
"stuck spinlock detected at %s, %s:%d",
99 s_lock(
volatile slock_t *lock,
const char *file,
int line,
const char *func)
112 return delayStatus.
delays;
115 #ifdef USE_DEFAULT_S_UNLOCK
153 #if defined(S_LOCK_TEST)
236 #if defined(S_LOCK_TEST)
242 struct test_lock_struct
249 volatile struct test_lock_struct test_lock;
256 test_lock.pad1 = test_lock.pad2 = 0x44;
260 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
262 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
268 printf(
"S_LOCK_TEST: failed, lock not initialized\n");
274 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
276 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
282 printf(
"S_LOCK_TEST: failed, lock not locked\n");
288 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
290 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
296 printf(
"S_LOCK_TEST: failed, lock not unlocked\n");
302 if (test_lock.pad1 != 0x44 || test_lock.pad2 != 0x44)
304 printf(
"S_LOCK_TEST: failed, declared datatype is wrong size\n");
310 printf(
"S_LOCK_TEST: failed, lock not re-locked\n");
315 printf(
" exit with a 'stuck spinlock' message\n");
316 printf(
" if S_LOCK() and TAS() are working.\n");
319 s_lock(&test_lock.lock, __FILE__, __LINE__, __func__);
321 printf(
"S_LOCK_TEST: failed, lock not locked\n");
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
void s_unlock(volatile slock_t *lock)
#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 uint32 local_my_wait_event_info
uint32 * my_wait_event_info
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)