X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FSpinLockTest.cpp;h=67279a700f82367151b122f673fcb118616c2617;hb=a0c640e8e2ff45bc43b9f8d96cd108bb66635bee;hp=6d028af1e0f923a8436f4f247c641f8afe0fad19;hpb=fe33916f8b77db93ca0737ad9d00cd48d216c6e4;p=folly.git diff --git a/folly/test/SpinLockTest.cpp b/folly/test/SpinLockTest.cpp index 6d028af1..67279a70 100644 --- a/folly/test/SpinLockTest.cpp +++ b/folly/test/SpinLockTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 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. @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include #include -#include #include #include +#include using folly::SpinLockGuardImpl; @@ -45,8 +46,8 @@ void spinlockTestThread(LockedVal* v) { SpinLockGuardImpl g(v->lock); int first = v->ar[0]; - for (size_t i = 1; i < sizeof v->ar / sizeof i; ++i) { - EXPECT_EQ(first, v->ar[i]); + for (size_t j = 1; j < sizeof v->ar / sizeof j; ++j) { + EXPECT_EQ(first, v->ar[j]); } int byte = folly::Random::rand32(rng); @@ -67,16 +68,19 @@ template void trylockTestThread(TryLockState* state, size_t count) { while (true) { folly::asm_pause(); + bool ret = state->lock2.try_lock(); SpinLockGuardImpl g(state->lock1); if (state->obtained >= count) { + if (ret) { + state->lock2.unlock(); + } break; } - bool ret = state->lock2.trylock(); - EXPECT_NE(state->locked, ret); if (ret) { // We got lock2. + EXPECT_NE(state->locked, ret); ++state->obtained; state->locked = true; @@ -132,36 +136,9 @@ void trylockTest() { } // unnamed namespace -#if __x86_64__ -TEST(SpinLock, MslCorrectness) { - correctnessTest(); -} -TEST(SpinLock, MslTryLock) { - trylockTest(); -} -#endif - -#if __APPLE__ -TEST(SpinLock, AppleCorrectness) { - correctnessTest(); -} -TEST(SpinLock, AppleTryLock) { - trylockTest(); -} -#endif - -#if FOLLY_HAVE_PTHREAD_SPINLOCK_T -TEST(SpinLock, PthreadCorrectness) { - correctnessTest(); -} -TEST(SpinLock, PthreadTryLock) { - trylockTest(); -} -#endif - -TEST(SpinLock, MutexCorrectness) { - correctnessTest(); +TEST(SpinLock, Correctness) { + correctnessTest(); } -TEST(SpinLock, MutexTryLock) { - trylockTest(); +TEST(SpinLock, TryLock) { + trylockTest(); }