From: Yedidya Feldblum Date: Tue, 26 Dec 2017 18:57:54 +0000 (-0800) Subject: Move folly/detail/Sleeper.h to folly/synchronization/detail/ X-Git-Tag: v2018.01.01.00~18 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e50d7df41cf5371584281bbf4208fd8c54bbf7f5;p=folly.git Move folly/detail/Sleeper.h to folly/synchronization/detail/ Summary: [Folly] Move `folly/detail/Sleeper.h` to `folly/synchronization/detail/`. Reviewed By: Orvid Differential Revision: D6636459 fbshipit-source-id: e0b37459fe721c96837b653e652c1bc6bfeb5dce --- diff --git a/folly/Makefile.am b/folly/Makefile.am index ec1e2e67..19f31af4 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -80,7 +80,6 @@ nobase_follyinclude_HEADERS = \ detail/PolyDetail.h \ detail/RangeCommon.h \ detail/RangeSse42.h \ - detail/Sleeper.h \ detail/SlowFingerprint.h \ detail/SocketFastOpen.h \ detail/StaticSingletonManager.h \ @@ -440,6 +439,7 @@ nobase_follyinclude_HEADERS = \ synchronization/CallOnce.h \ synchronization/LifoSem.h \ synchronization/detail/AtomicUtils.h \ + synchronization/detail/Sleeper.h \ system/MemoryMapping.h \ system/Shell.h \ system/ThreadId.h \ diff --git a/folly/MicroSpinLock.h b/folly/MicroSpinLock.h index dab80c67..8996f8c3 100644 --- a/folly/MicroSpinLock.h +++ b/folly/MicroSpinLock.h @@ -45,8 +45,8 @@ #include #include -#include #include +#include namespace folly { diff --git a/folly/PicoSpinLock.h b/folly/PicoSpinLock.h index d9bdf50c..eb62bee2 100644 --- a/folly/PicoSpinLock.h +++ b/folly/PicoSpinLock.h @@ -48,7 +48,7 @@ #include #include -#include +#include #if !FOLLY_X64 && !FOLLY_AARCH64 && !FOLLY_PPC64 #error "PicoSpinLock.h is currently x64, aarch64 and ppc64 only." diff --git a/folly/detail/Sleeper.h b/folly/detail/Sleeper.h deleted file mode 100644 index ad8127c2..00000000 --- a/folly/detail/Sleeper.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -/* - * @author Keith Adams - * @author Jordan DeLong - */ - -#include - -#include -#include - -namespace folly { - -////////////////////////////////////////////////////////////////////// - -namespace detail { - -/* - * A helper object for the contended case. Starts off with eager - * spinning, and falls back to sleeping for small quantums. - */ -class Sleeper { - static const uint32_t kMaxActiveSpin = 4000; - - uint32_t spinCount; - - public: - Sleeper() : spinCount(0) {} - - void wait() { - if (spinCount < kMaxActiveSpin) { - ++spinCount; - asm_volatile_pause(); - } else { - /* - * Always sleep 0.5ms, assuming this will make the kernel put - * us down for whatever its minimum timer resolution is (in - * linux this varies by kernel version from 1ms to 10ms). - */ - struct timespec ts = {0, 500000}; - nanosleep(&ts, nullptr); - } - } -}; - -} // namespace detail -} // namespace folly diff --git a/folly/synchronization/detail/Sleeper.h b/folly/synchronization/detail/Sleeper.h new file mode 100644 index 00000000..ad8127c2 --- /dev/null +++ b/folly/synchronization/detail/Sleeper.h @@ -0,0 +1,64 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +/* + * @author Keith Adams + * @author Jordan DeLong + */ + +#include + +#include +#include + +namespace folly { + +////////////////////////////////////////////////////////////////////// + +namespace detail { + +/* + * A helper object for the contended case. Starts off with eager + * spinning, and falls back to sleeping for small quantums. + */ +class Sleeper { + static const uint32_t kMaxActiveSpin = 4000; + + uint32_t spinCount; + + public: + Sleeper() : spinCount(0) {} + + void wait() { + if (spinCount < kMaxActiveSpin) { + ++spinCount; + asm_volatile_pause(); + } else { + /* + * Always sleep 0.5ms, assuming this will make the kernel put + * us down for whatever its minimum timer resolution is (in + * linux this varies by kernel version from 1ms to 10ms). + */ + struct timespec ts = {0, 500000}; + nanosleep(&ts, nullptr); + } + } +}; + +} // namespace detail +} // namespace folly