- /*
- * We loop tightly for awhile, then delay using pg_usleep() and try again.
- * Preferably, "awhile" should be a small multiple of the maximum time we
- * expect a spinlock to be held. 100 iterations seems about right as an
- * initial guess. However, on a uniprocessor the loop is a waste of
- * cycles, while in a multi-CPU scenario it's usually better to spin a bit
- * longer than to call the kernel, so we try to adapt the spin loop count
- * depending on whether we seem to be in a uniprocessor or multiprocessor.
- *
- * Note: you might think MIN_SPINS_PER_DELAY should be just 1, but you'd
- * be wrong; there are platforms where that can result in a "stuck
- * spinlock" failure. This has been seen particularly on Alphas; it seems
- * that the first TAS after returning from kernel space will always fail
- * on that hardware.
- *
- * Once we do decide to block, we use randomly increasing pg_usleep()
- * delays. The first delay is 1 msec, then the delay randomly increases to
- * about one second, after which we reset to 1 msec and start again. The
- * idea here is that in the presence of heavy contention we need to
- * increase the delay, else the spinlock holder may never get to run and
- * release the lock. (Consider situation where spinlock holder has been
- * nice'd down in priority by the scheduler --- it will not get scheduled
- * until all would-be acquirers are sleeping, so if we always use a 1-msec
- * sleep, there is a real possibility of starvation.) But we can't just
- * clamp the delay to an upper bound, else it would take a long time to
- * make a reasonable number of tries.
- *
- * We time out and declare error after NUM_DELAYS delays (thus, exactly
- * that many tries). With the given settings, this will usually take 2 or
- * so minutes. It seems better to fix the total number of tries (and thus
- * the probability of unintended failure) than to fix the total time
- * spent.
- *
- * The pg_usleep() delays are measured in milliseconds because 1 msec is a
- * common resolution limit at the OS level for newer platforms. On older
- * platforms the resolution limit is usually 10 msec, in which case the
- * total delay before timeout will be a bit more.
- */
-#define MIN_SPINS_PER_DELAY 10
-#define MAX_SPINS_PER_DELAY 1000
-#define NUM_DELAYS 1000
-#define MIN_DELAY_MSEC 1
-#define MAX_DELAY_MSEC 1000