summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/support/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/support/rand.c')
-rw-r--r--src/third_party/wiredtiger/src/support/rand.c98
1 files changed, 46 insertions, 52 deletions
diff --git a/src/third_party/wiredtiger/src/support/rand.c b/src/third_party/wiredtiger/src/support/rand.c
index dff19325429..264ee711755 100644
--- a/src/third_party/wiredtiger/src/support/rand.c
+++ b/src/third_party/wiredtiger/src/support/rand.c
@@ -40,83 +40,77 @@
* of zero, in which case they will be stuck on zero forever. Take a local copy
* of the values to avoid that, and read/write in atomic, 8B chunks.
*/
-#undef M_W
-#define M_W(r) r.x.w
-#undef M_Z
-#define M_Z(r) r.x.z
+#undef M_W
+#define M_W(r) r.x.w
+#undef M_Z
+#define M_Z(r) r.x.z
/*
* __wt_random_init --
- * Initialize return of a 32-bit pseudo-random number.
+ * Initialize return of a 32-bit pseudo-random number.
*/
void
-__wt_random_init(WT_RAND_STATE volatile * rnd_state)
- WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
+__wt_random_init(WT_RAND_STATE volatile *rnd_state) WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
{
- WT_RAND_STATE rnd;
+ WT_RAND_STATE rnd;
- M_W(rnd) = 521288629;
- M_Z(rnd) = 362436069;
- *rnd_state = rnd;
+ M_W(rnd) = 521288629;
+ M_Z(rnd) = 362436069;
+ *rnd_state = rnd;
}
/*
* __wt_random_init_seed --
- * Initialize the state of a 32-bit pseudo-random number.
- * Use this, instead of __wt_random_init if we are running with multiple
- * threads and we want each thread to initialize its own random state based
- * on a different random seed.
+ * Initialize the state of a 32-bit pseudo-random number. Use this, instead of __wt_random_init
+ * if we are running with multiple threads and we want each thread to initialize its own random
+ * state based on a different random seed.
*/
void
-__wt_random_init_seed(
- WT_SESSION_IMPL *session, WT_RAND_STATE volatile * rnd_state)
- WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
+__wt_random_init_seed(WT_SESSION_IMPL *session, WT_RAND_STATE volatile *rnd_state)
+ WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
{
- struct timespec ts;
- WT_RAND_STATE rnd;
+ struct timespec ts;
+ WT_RAND_STATE rnd;
- __wt_epoch(session, &ts);
- M_W(rnd) = (uint32_t)(ts.tv_nsec + 521288629);
- M_Z(rnd) = (uint32_t)(ts.tv_nsec + 362436069);
+ __wt_epoch(session, &ts);
+ M_W(rnd) = (uint32_t)(ts.tv_nsec + 521288629);
+ M_Z(rnd) = (uint32_t)(ts.tv_nsec + 362436069);
- *rnd_state = rnd;
+ *rnd_state = rnd;
}
/*
* __wt_random --
- * Return a 32-bit pseudo-random number.
+ * Return a 32-bit pseudo-random number.
*/
uint32_t
-__wt_random(WT_RAND_STATE volatile * rnd_state)
- WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
+__wt_random(WT_RAND_STATE volatile *rnd_state) WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
{
- WT_RAND_STATE rnd;
- uint32_t w, z;
+ WT_RAND_STATE rnd;
+ uint32_t w, z;
- /*
- * Take a copy of the random state so we can ensure that the
- * calculation operates on the state consistently regardless of
- * concurrent calls with the same random state.
- */
- rnd = *rnd_state;
- w = M_W(rnd);
- z = M_Z(rnd);
+ /*
+ * Take a copy of the random state so we can ensure that the calculation operates on the state
+ * consistently regardless of concurrent calls with the same random state.
+ */
+ rnd = *rnd_state;
+ w = M_W(rnd);
+ z = M_Z(rnd);
- /*
- * Check if the value goes to 0 (from which we won't recover), and reset
- * to the initial state. This has additional benefits if a caller fails
- * to initialize the state, or initializes with a seed that results in a
- * short period.
- */
- if (z == 0 || w == 0) {
- __wt_random_init(&rnd);
- w = M_W(rnd);
- z = M_Z(rnd);
- }
+ /*
+ * Check if the value goes to 0 (from which we won't recover), and reset to the initial state.
+ * This has additional benefits if a caller fails to initialize the state, or initializes with a
+ * seed that results in a short period.
+ */
+ if (z == 0 || w == 0) {
+ __wt_random_init(&rnd);
+ w = M_W(rnd);
+ z = M_Z(rnd);
+ }
- M_Z(rnd) = z = 36969 * (z & 65535) + (z >> 16);
- M_W(rnd) = w = 18000 * (w & 65535) + (w >> 16);
- *rnd_state = rnd;
+ M_Z(rnd) = z = 36969 * (z & 65535) + (z >> 16);
+ M_W(rnd) = w = 18000 * (w & 65535) + (w >> 16);
+ *rnd_state = rnd;
- return ((z << 16) + (w & 65535));
+ return ((z << 16) + (w & 65535));
}