X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fdetail%2FAtomicHashUtils.h;h=7fb84056bd52d4aae4ced2bb99093018f4a64da9;hb=879a247afb1b651c8e8aff9ac19435360ed67d3e;hp=adf6927ce377d963b0e9e5fc03dd1fe9ff25cacb;hpb=5c77fedbef46995a71ffa268c9fcaf49efddd01b;p=folly.git diff --git a/folly/detail/AtomicHashUtils.h b/folly/detail/AtomicHashUtils.h index adf6927c..7fb84056 100644 --- a/folly/detail/AtomicHashUtils.h +++ b/folly/detail/AtomicHashUtils.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 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. @@ -14,24 +14,28 @@ * limitations under the License. */ +#pragma once + +#include + +#include + // Some utilities used by AtomicHashArray and AtomicHashMap // -// Note: no include guard; different -inl.h files include this and -// undef it more than once in a translation unit. -#if !(defined(__x86__) || defined(__i386__) || defined(__x86_64__)) -#define FOLLY_SPIN_WAIT(condition) \ - for (int counter = 0; condition; ++counter) { \ - if (counter < 10000) continue; \ - pthread_yield(); \ - } -#else -#define FOLLY_SPIN_WAIT(condition) \ - for (int counter = 0; condition; ++counter) { \ - if (counter < 10000) { \ - asm volatile("pause"); \ - continue; \ - } \ - pthread_yield(); \ +namespace folly { namespace detail { + +template +void atomic_hash_spin_wait(Cond condition) { + constexpr size_t kPauseLimit = 10000; + for (size_t i = 0; condition(); ++i) { + if (i < kPauseLimit) { + folly::asm_volatile_pause(); + } else { + std::this_thread::yield(); + } } -#endif +} + +} // namespace detail +} // namespace folly