Commit 8bf79388 authored by Chad Austin's avatar Chad Austin Committed by Facebook Github Bot

enable SharedMutex benchmarks on macOS

Summary:
Instead of using a Linux-specific API for random numbers, use
std::minstd_rand. It's not precisely identical, but probably
sufficient for these tests.

Reviewed By: yfeldblum

Differential Revision: D20039048

fbshipit-source-id: 5ace1a0552f995a48b37e4fa2209394f1b28ca84
parent 8583f02b
......@@ -17,6 +17,7 @@
#include <folly/SharedMutex.h>
#include <stdlib.h>
#include <random>
#include <thread>
#include <vector>
......@@ -664,8 +665,9 @@ static void runMixed(
BENCHMARK_SUSPEND {
for (size_t t = 0; t < numThreads; ++t) {
threads[t] = DSched::thread([&, t, numThreads] {
struct drand48_data buffer;
srand48_r(t, &buffer);
std::minstd_rand engine;
engine.seed(t);
long writeThreshold = writeFraction * 0x7fffffff;
Lock privateLock;
Lock* lock = useSeparateLocks ? &privateLock : &(padded.globalLock);
......@@ -674,8 +676,7 @@ static void runMixed(
this_thread::yield();
}
for (size_t op = t; op < numOps; op += numThreads) {
long randVal;
lrand48_r(&buffer, &randVal);
long randVal = engine();
bool writeOp = randVal < writeThreshold;
if (writeOp) {
locker.lock(lock);
......@@ -801,8 +802,8 @@ static void runAllAndValidate(size_t numOps, size_t numThreads) {
BENCHMARK_SUSPEND {
for (size_t t = 0; t < numThreads; ++t) {
threads[t] = DSched::thread([&, t, numThreads] {
struct drand48_data buffer;
srand48_r(t, &buffer);
std::minstd_rand engine;
engine.seed(t);
bool exclusive = false;
bool upgrade = false;
......@@ -818,8 +819,7 @@ static void runAllAndValidate(size_t numOps, size_t numThreads) {
}
for (size_t op = t; op < numOps; op += numThreads) {
// randVal in [0,1000)
long randVal;
lrand48_r(&buffer, &randVal);
long randVal = engine();
randVal = (long)((randVal * (uint64_t)1000) / 0x7fffffff);
// make as many assertions as possible about the global state
......@@ -1216,15 +1216,14 @@ static void runRemoteUnlock(
}
// else we're a sender
struct drand48_data buffer;
srand48_r(t, &buffer);
std::minstd_rand engine;
engine.seed(t);
while (!goPtr->load()) {
this_thread::yield();
}
for (size_t op = t; op < numOps; op += numSendingThreads) {
long unscaledRandVal;
lrand48_r(&buffer, &unscaledRandVal);
long unscaledRandVal = engine();
// randVal in [0,1]
double randVal = ((double)unscaledRandVal) / 0x7fffffff;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment