Commit a1b77701 authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 3

Have internal tests use folly::Random instead of rand_r

Summary: rand_r is not provided on all platforms, so use `folly::Random` instead.

Reviewed By: yfeldblum

Differential Revision: D3000351

fb-gh-sync-id: 45df3e1957c4b529ab2d2cb4db13b71d13dcef5d
shipit-source-id: 45df3e1957c4b529ab2d2cb4db13b71d13dcef5d
parent 863a22ad
......@@ -15,6 +15,9 @@
*/
#include <folly/SmallLocks.h>
#include <folly/Random.h>
#include <cassert>
#include <cstdio>
#include <mutex>
......@@ -58,7 +61,7 @@ LockedVal v;
void splock_test() {
const int max = 1000;
unsigned int seed = (uintptr_t)pthread_self();
auto rng = folly::ThreadLocalPRNG();
for (int i = 0; i < max; i++) {
folly::asm_pause();
MSLGuard g(v.lock);
......@@ -68,7 +71,7 @@ void splock_test() {
EXPECT_EQ(first, v.ar[i]);
}
int byte = rand_r(&seed);
int byte = folly::Random::rand32(rng);
memset(v.ar, char(byte), sizeof v.ar);
}
}
......
......@@ -15,6 +15,8 @@
*/
#include <folly/SpinLock.h>
#include <folly/Random.h>
#include <gtest/gtest.h>
#include <thread>
......@@ -35,7 +37,7 @@ struct LockedVal {
template <typename LOCK>
void spinlockTestThread(LockedVal<LOCK>* v) {
const int max = 1000;
unsigned int seed = (uintptr_t)pthread_self();
auto rng = folly::ThreadLocalPRNG();
for (int i = 0; i < max; i++) {
folly::asm_pause();
SpinLockGuardImpl<LOCK> g(v->lock);
......@@ -45,7 +47,7 @@ void spinlockTestThread(LockedVal<LOCK>* v) {
EXPECT_EQ(first, v->ar[i]);
}
int byte = rand_r(&seed);
int byte = folly::Random::rand32(rng);
memset(v->ar, char(byte), sizeof v->ar);
}
}
......
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