X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FSpinLockTest.cpp;h=3be763d633e3f47d21be34dd0f10d242d1a909bb;hb=587e4b4d914c477b79120fb6559571d2dc5d040d;hp=9f8b279cb82cd3518c9102f1d39ea26aa3c088b4;hpb=e4ef6050fb8b853f1ff21a141448b1c1aeca574c;p=folly.git diff --git a/folly/test/SpinLockTest.cpp b/folly/test/SpinLockTest.cpp index 9f8b279c..3be763d6 100644 --- a/folly/test/SpinLockTest.cpp +++ b/folly/test/SpinLockTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014 Facebook, Inc. + * Copyright 2015 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ void spinlockTestThread(LockedVal* v) { const int max = 1000; unsigned int seed = (uintptr_t)pthread_self(); for (int i = 0; i < max; i++) { - asm("pause"); + folly::asm_pause(); SpinLockGuardImpl g(v->lock); int first = v->ar[0]; @@ -60,9 +60,9 @@ struct TryLockState { }; template -void trylockTestThread(TryLockState* state, int count) { +void trylockTestThread(TryLockState* state, size_t count) { while (true) { - asm("pause"); + folly::asm_pause(); SpinLockGuardImpl g(state->lock1); if (state->obtained >= count) { break; @@ -81,7 +81,7 @@ void trylockTestThread(TryLockState* state, int count) { auto oldFailed = state->failed; while (state->failed == oldFailed && state->obtained < count) { state->lock1.unlock(); - asm("pause"); + folly::asm_pause(); state->lock1.lock(); } @@ -111,7 +111,7 @@ void trylockTest() { int nthrs = sysconf(_SC_NPROCESSORS_ONLN) + 4; std::vector threads; TryLockState state; - int count = 100; + size_t count = 100; for (int i = 0; i < nthrs; ++i) { threads.push_back(std::thread(trylockTestThread, &state, count)); } @@ -146,7 +146,7 @@ TEST(SpinLock, AppleTryLock) { } #endif -#if !__ANDROID__ +#if FOLLY_HAVE_PTHREAD_SPINLOCK_T TEST(SpinLock, PthreadCorrectness) { correctnessTest(); }