X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FBaton.h;h=e0f66951dfc185e25a4adefc1e155c0730d92e78;hb=f57ddfc76b3835033a36343df22ae821168dcc0f;hp=4e3684a29c8eb7a697ba94be829be6b8a569a80c;hpb=275ca94d04e44f28cfa411668eb1c1dd8db90b80;p=folly.git diff --git a/folly/Baton.h b/folly/Baton.h index 4e3684a2..e0f66951 100644 --- a/folly/Baton.h +++ b/folly/Baton.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 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,17 +14,16 @@ * limitations under the License. */ -#ifndef FOLLY_BATON_H -#define FOLLY_BATON_H +#pragma once #include #include -#include #include #include #include #include +#include namespace folly { @@ -44,14 +43,17 @@ namespace folly { /// a much more restrictive lifecycle we can also add a bunch of assertions /// that can help to catch race conditions ahead of time. template class Atom = std::atomic> -struct Baton : boost::noncopyable { - Baton() : state_(INIT) {} +struct Baton { + constexpr Baton() : state_(INIT) {} + + Baton(Baton const&) = delete; + Baton& operator=(Baton const&) = delete; /// It is an error to destroy a Baton on which a thread is currently /// wait()ing. In practice this means that the waiter usually takes /// responsibility for destroying the Baton. ~Baton() { - // The docblock for this function says that is can't be called when + // The docblock for this function says that it can't be called when // there is a concurrent waiter. We assume a strong version of this // requirement in which the caller must _know_ that this is true, they // are not allowed to be merely lucky. If two threads are involved, @@ -215,6 +217,13 @@ struct Baton : boost::noncopyable { } } + /// Similar to timed_wait, but with a duration. + template + bool timed_wait(const Duration& duration) { + auto deadline = Clock::now() + duration; + return timed_wait(deadline); + } + /// Similar to wait, but doesn't block the thread if it hasn't been posted. /// /// try_wait has the following semantics: @@ -273,13 +282,11 @@ struct Baton : boost::noncopyable { // hooray! return true; } -#if FOLLY_X64 // The pause instruction is the polite way to spin, but it doesn't // actually affect correctness to omit it if we don't have it. // Pausing donates the full capabilities of the current core to // its other hyperthreads for a dozen cycles or so - asm volatile ("pause"); -#endif + asm_volatile_pause(); } return false; @@ -289,5 +296,3 @@ struct Baton : boost::noncopyable { }; } // namespace folly - -#endif