From a1b77701d8619afc907ba0408d03aadecf852e02 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 3 Mar 2016 15:51:18 -0800 Subject: [PATCH] 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 --- folly/test/SmallLocksTest.cpp | 7 +++++-- folly/test/SpinLockTest.cpp | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/folly/test/SmallLocksTest.cpp b/folly/test/SmallLocksTest.cpp index 61cea467..50964126 100644 --- a/folly/test/SmallLocksTest.cpp +++ b/folly/test/SmallLocksTest.cpp @@ -15,6 +15,9 @@ */ #include + +#include + #include #include #include @@ -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); } } diff --git a/folly/test/SpinLockTest.cpp b/folly/test/SpinLockTest.cpp index 2477bfc1..ee12ab16 100644 --- a/folly/test/SpinLockTest.cpp +++ b/folly/test/SpinLockTest.cpp @@ -15,6 +15,8 @@ */ #include +#include + #include #include @@ -35,7 +37,7 @@ struct LockedVal { template void spinlockTestThread(LockedVal* 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 g(v->lock); @@ -45,7 +47,7 @@ void spinlockTestThread(LockedVal* 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); } } -- 2.34.1