proxygen
|
#include <LifoSem.h>
Public Member Functions | |
constexpr | LifoSemBase (uint32_t initialValue=0) |
Constructor. More... | |
LifoSemBase (LifoSemBase const &)=delete | |
LifoSemBase & | operator= (LifoSemBase const &)=delete |
bool | post () |
Silently saturates if value is already 2^32-1. More... | |
void | post (uint32_t n) |
bool | isShutdown () const |
Returns true iff shutdown() has been called. More... | |
void | shutdown () |
bool | tryWait () |
Returns true iff value was decremented. More... | |
uint32_t | tryWait (uint32_t n) |
void | wait () |
template<typename Rep , typename Period > | |
bool | try_wait_for (const std::chrono::duration< Rep, Period > &timeout) |
template<typename Clock , typename Duration > | |
bool | try_wait_until (const std::chrono::time_point< Clock, Duration > &deadline) |
uint32_t | valueGuess () const |
Protected Types | |
enum | WaitResult { WaitResult::PUSH, WaitResult::DECR, WaitResult::SHUTDOWN } |
typedef std::unique_ptr< LifoSemNode< Handoff, Atom >, LifoSemNodeRecycler< Handoff, Atom > > | UniquePtr |
Protected Member Functions | |
template<typename... Args> | |
UniquePtr | allocateNode (Args &&...args) |
Returns a node that can be passed to decrOrLink. More... | |
WaitResult | tryWaitOrPush (LifoSemNode< Handoff, Atom > &waiterNode) |
Private Member Functions | |
bool | tryRemoveNode (const LifoSemNode< Handoff, Atom > &removenode) |
uint32_t | incrOrPop (uint32_t n) |
WaitResult | decrOrPush (uint32_t &n, uint32_t idx) |
Static Private Member Functions | |
static LifoSemNode< Handoff, Atom > & | idxToNode (uint32_t idx) |
static uint32_t | nodeToIdx (const LifoSemNode< Handoff, Atom > &node) |
Private Attributes | |
CachelinePadded< folly::AtomicStruct< LifoSemHead, Atom > > | head_ |
LifoSemBase is the engine for several different types of LIFO semaphore. LifoSemBase handles storage of positive semaphore values and wait nodes, but the actual waiting and notification mechanism is up to the client.
The Handoff type is responsible for arranging one wakeup notification. See LifoSemNode for more information on how to make your own.
|
protected |
The type of a std::unique_ptr that will automatically return a LifoSemNode to the appropriate IndexedMemPool
|
strongprotected |
|
inlineexplicit |
Constructor.
Definition at line 354 of file LifoSem.h.
|
delete |
|
inlineprotected |
Returns a node that can be passed to decrOrLink.
Definition at line 551 of file LifoSem.h.
|
inlineprivate |
Returns DECR if some amount was decremented, with that amount subtracted from n. If n is 1 and this function returns DECR then n must be 0 afterward. Returns PUSH if no value could be decremented and idx was pushed, or if idx was zero and no push was performed but a push would have been performed with a valid node. Returns SHUTDOWN if the caller should have blocked but isShutdown(). If idx == 0, may return PUSH even after isShutdown() or may return SHUTDOWN
Definition at line 678 of file LifoSem.h.
|
inlinestaticprivate |
|
inlineprivate |
Either increments by n and returns 0, or pops a node and returns it. If n + the stripe's value overflows, then the stripe's value saturates silently at 2^32-1
Definition at line 645 of file LifoSem.h.
|
inline |
Returns true iff shutdown() has been called.
Definition at line 389 of file LifoSem.h.
Referenced by TEST_F().
|
inlinestaticprivate |
Definition at line 587 of file LifoSem.h.
|
delete |
|
inline |
Silently saturates if value is already 2^32-1.
Definition at line 361 of file LifoSem.h.
Referenced by folly::UnboundedBlockingQueue< T >::add(), folly::LifoSemMPMCQueue< T, kBehavior >::add(), folly::ManualExecutor::add(), folly::PriorityLifoSemMPMCQueue< T, kBehavior >::addWithPriority(), BENCHMARK(), folly::ManualExecutor::scheduleAt(), TEST(), and TEST_F().
|
inline |
Equivalent to n calls to post(), except may be much more efficient. At any point in time at which the semaphore's value would exceed 2^32-1 if tracked with infinite precision, it may be silently truncated to 2^32-1. This saturation is not guaranteed to be exact, although it is guaranteed that overflow won't result in wrap-around. There would be a substantial performance and complexity cost in guaranteeing exact saturation (similar to the cost of maintaining linearizability near the zero value, but without as much of a benefit).
Definition at line 379 of file LifoSem.h.
|
inline |
Prevents blocking on this semaphore, causing all blocking wait() calls to throw ShutdownSemError. Both currently blocked wait() and future calls to wait() for which tryWait() would return false will cause an exception. Calls to wait() for which the matching post() has already occurred will proceed normally.
Definition at line 398 of file LifoSem.h.
Referenced by TEST_F().
|
inline |
Definition at line 472 of file LifoSem.h.
Referenced by TEST_F(), folly::UnboundedBlockingQueue< T >::try_take_for(), folly::LifoSemMPMCQueue< T, kBehavior >::try_take_for(), and folly::PriorityLifoSemMPMCQueue< T, kBehavior >::try_take_for().
|
inline |
Definition at line 477 of file LifoSem.h.
|
inlineprivate |
Definition at line 594 of file LifoSem.h.
|
inline |
Returns true iff value was decremented.
Definition at line 430 of file LifoSem.h.
Referenced by BENCHMARK(), folly::ManualExecutor::run(), TEST(), and TEST_F().
|
inline |
Equivalent to (but may be much more efficient than) n calls to tryWait(). Returns the total amount by which the semaphore's value was decreased
Definition at line 443 of file LifoSem.h.
|
inlineprotected |
Returns DECR if the semaphore value was decremented (and waiterNode was untouched), PUSH if a reference to the wait node was pushed, or SHUTDOWN if decrement was not possible and push wasn't allowed because isShutdown(). Ownership of the wait node remains the responsibility of the caller, who must not release it until after the node's Handoff has been posted.
Definition at line 574 of file LifoSem.h.
|
inline |
Returns a guess at the current value, designed for debugging. If there are no concurrent posters or waiters then this will be correct
Definition at line 528 of file LifoSem.h.
Referenced by TEST_F().
|
inline |
Blocks the current thread until there is a matching post or the semaphore is shut down. Throws ShutdownSemError if the semaphore has been shut down and this method would otherwise be blocking. Note that wait() doesn't throw during shutdown if tryWait() would return true
Definition at line 465 of file LifoSem.h.
Referenced by BENCHMARK(), folly::UnboundedBlockingQueue< T >::take(), folly::LifoSemMPMCQueue< T, kBehavior >::take(), folly::PriorityLifoSemMPMCQueue< T, kBehavior >::take(), TEST(), TEST_F(), and folly::ManualExecutor::wait().
|
private |