X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FRWSpinLockTest.cpp;h=1f9c9eef91cc5f98395e8c7c4fe2f0975d661191;hb=f795d501ba155f3fac9ed8bec40cbbc8eb4045ad;hp=6b58c9a1f92a94b96bcc71f79f317772f04e71d7;hpb=3692ff51d35e5e38fde557d61750c884340ec2fe;p=folly.git diff --git a/folly/test/RWSpinLockTest.cpp b/folly/test/RWSpinLockTest.cpp index 6b58c9a1..1f9c9eef 100644 --- a/folly/test/RWSpinLockTest.cpp +++ b/folly/test/RWSpinLockTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,17 @@ // @author xliu (xliux@fb.com) // +#include + #include -#include #include #include -#include "gtest/gtest.h" -#include #include -#include "folly/RWSpinLock.h" + +#include +#include +#include DEFINE_int32(num_threads, 8, "num threads"); @@ -41,8 +43,7 @@ template struct RWSpinLockTest: public testing::Test { }; typedef testing::Types, RWTicketSpinLockT<32, false>, RWTicketSpinLockT<64, true>, @@ -149,7 +150,7 @@ TYPED_TEST(RWSpinLockTest, Write_Holders) { TYPED_TEST(RWSpinLockTest, ConcurrentTests) { typedef typename TestFixture::RWSpinLockType RWSpinLockType; RWSpinLockType l; - srand(time(NULL)); + srand(time(nullptr)); std::vector threads; for (int i = 0; i < FLAGS_num_threads; ++i) { @@ -188,7 +189,7 @@ TEST(RWSpinLock, lock_unlock_tests) { } TEST(RWSpinLock, concurrent_holder_test) { - srand(time(NULL)); + srand(time(nullptr)); folly::RWSpinLock lock; std::atomic reads(0); @@ -200,11 +201,10 @@ TEST(RWSpinLock, concurrent_holder_test) { while (!stop.load(std::memory_order_acquire)) { auto r = (uint32_t)(rand()) % 10; if (r < 3) { // starts from write lock - RWSpinLock::ReadHolder rg( - RWSpinLock::UpgradedHolder ug( - RWSpinLock::WriteHolder(&lock))); + RWSpinLock::ReadHolder rg{ + RWSpinLock::UpgradedHolder{ + RWSpinLock::WriteHolder{&lock}}}; writes.fetch_add(1, std::memory_order_acq_rel);; - } else if (r < 6) { // starts from upgrade lock RWSpinLock::UpgradedHolder ug(&lock); if (r < 4) { @@ -214,9 +214,7 @@ TEST(RWSpinLock, concurrent_holder_test) { } upgrades.fetch_add(1, std::memory_order_acq_rel);; } else { - RWSpinLock::UpgradedHolder ug( - RWSpinLock::WriteHolder( - RWSpinLock::ReadHolder(&lock))); + RWSpinLock::ReadHolder rg{&lock}; reads.fetch_add(1, std::memory_order_acq_rel); } } @@ -238,9 +236,3 @@ TEST(RWSpinLock, concurrent_holder_test) { } } - -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - google::ParseCommandLineFlags(&argc, &argv, true); - return RUN_ALL_TESTS(); -}