libfoedus-core
FOEDUS Core Library
|
A polling-wait mechanism that can be placed in shared memory and used from multiple processes. More...
A polling-wait mechanism that can be placed in shared memory and used from multiple processes.
This class automatically switches from spinning to polling with sleeps, then exponentially increases the sleep interval with some upper limit. Usually, a condition-variable packages such a functionality. BUT, we got so many troubles with glibc's bugs. A fix was pushed to upstream, but there will be many environments that still have older glibc. This class is pthread-free. No glibc versioning issue. Also, does not need signaling functionality in underlying OS/hardware, which we might not have in The Machine.
A typical usage is:
Definition at line 63 of file shared_polling.hpp.
#include <shared_polling.hpp>
Public Member Functions | |
SharedPolling () | |
SharedPolling (const SharedPolling &)=delete | |
SharedPolling & | operator= (const SharedPolling &)=delete |
void | initialize () |
uint64_t | acquire_ticket () const |
Gives the ticket to. More... | |
void | wait (uint64_t demanded_ticket, uint64_t polling_spins=kDefaultPollingSpins, uint64_t max_interval_us=kDefaultPollingMaxIntervalUs) const |
Unconditionally wait for signal. More... | |
bool | timedwait (uint64_t demanded_ticket, uint64_t timeout_microsec, uint64_t polling_spins=kDefaultPollingSpins, uint64_t max_interval_us=kDefaultPollingMaxIntervalUs) const |
Wait for signal up to the given timeout. More... | |
void | signal () |
Signal it to let waiters exit. More... | |
|
inline |
Definition at line 65 of file shared_polling.hpp.
References initialize().
|
delete |
uint64_t foedus::soc::SharedPolling::acquire_ticket | ( | ) | const |
Gives the ticket to.
This method takes an acquire fence after getting the ticket. The waiter should check the real condition variable after calling this method to avoid lost signal.
Definition at line 105 of file shared_polling.cpp.
References foedus::assorted::memory_fence_acq_rel().
Referenced by foedus::xct::XctManagerPimpl::advance_current_global_epoch(), foedus::xct::XctManagerPimpl::handle_epoch_chime(), foedus::snapshot::SnapshotManagerPimpl::handle_snapshot_child(), foedus::savepoint::SavepointManagerPimpl::savepoint_main(), foedus::snapshot::SnapshotManagerPimpl::sleep_a_while(), foedus::savepoint::SavepointManagerPimpl::take_savepoint(), foedus::savepoint::SavepointManagerPimpl::take_savepoint_after_snapshot(), foedus::snapshot::SnapshotManagerPimpl::trigger_snapshot_immediate(), foedus::soc::SharedRendezvous::wait(), foedus::thread::ImpersonateSession::wait(), foedus::soc::SharedRendezvous::wait_for(), foedus::thread::ImpersonateSession::wait_for(), foedus::xct::XctManagerPimpl::wait_for_current_global_epoch(), and foedus::log::LogManagerPimpl::wait_until_durable().
void foedus::soc::SharedPolling::initialize | ( | ) |
Definition at line 32 of file shared_polling.cpp.
References foedus::assorted::memory_fence_acq_rel().
Referenced by foedus::log::MetaLogControlBlock::initialize(), foedus::savepoint::SavepointManagerControlBlock::initialize(), foedus::soc::SharedRendezvous::initialize(), foedus::xct::XctManagerControlBlock::initialize(), foedus::log::LogManagerControlBlock::initialize(), foedus::thread::ThreadControlBlock::initialize(), foedus::log::LoggerControlBlock::initialize(), foedus::snapshot::SnapshotManagerControlBlock::initialize(), and SharedPolling().
|
delete |
void foedus::soc::SharedPolling::signal | ( | ) |
Signal it to let waiters exit.
This method first takes a release fence to avoid lost signal. The signaller should set the real condition variable before calling this method to avoid lost signal.
Definition at line 100 of file shared_polling.cpp.
References foedus::assorted::memory_fence_acq_rel(), and foedus::soc::ugly_atomic_inc().
Referenced by foedus::log::LogManagerPimpl::announce_new_durable_global_epoch(), foedus::xct::XctManagerPimpl::handle_epoch_chime(), foedus::snapshot::SnapshotManagerPimpl::handle_snapshot_triggered(), foedus::log::LogManagerPimpl::refresh_global_durable_epoch(), foedus::savepoint::SavepointManagerPimpl::savepoint_main(), foedus::soc::SharedRendezvous::signal(), foedus::savepoint::SavepointManagerPimpl::take_savepoint(), foedus::savepoint::SavepointManagerPimpl::take_savepoint_after_snapshot(), foedus::thread::ThreadRef::try_impersonate(), foedus::log::MetaLogger::uninitialize_once(), foedus::xct::XctManagerPimpl::uninitialize_once(), foedus::savepoint::SavepointManagerPimpl::uninitialize_once(), foedus::thread::ThreadPimpl::uninitialize_once(), foedus::snapshot::SnapshotManagerPimpl::wakeup(), foedus::xct::XctManagerPimpl::wakeup_epoch_chime_thread(), and foedus::snapshot::SnapshotManagerControlBlock::wakeup_snapshot_children().
bool foedus::soc::SharedPolling::timedwait | ( | uint64_t | demanded_ticket, |
uint64_t | timeout_microsec, | ||
uint64_t | polling_spins = kDefaultPollingSpins , |
||
uint64_t | max_interval_us = kDefaultPollingMaxIntervalUs |
||
) | const |
Wait for signal up to the given timeout.
[in] | demanded_ticket | returns when cur_ticket_ becomes this value or larger. |
[in] | timeout_microsec | timeout in microsec |
[in] | polling_spins | we stop spinning and switch to sleeps after this number of spins |
[in] | max_interval_us | the sleep interval exponentially grows up to this value in microsec. |
Definition at line 63 of file shared_polling.cpp.
References foedus::soc::get_now_microsec(), and foedus::soc::kInitialPollingIntervalUs.
Referenced by foedus::xct::XctManagerPimpl::handle_epoch_chime(), foedus::snapshot::SnapshotManagerPimpl::handle_snapshot_child(), foedus::savepoint::SavepointManagerPimpl::savepoint_main(), foedus::snapshot::SnapshotManagerPimpl::sleep_a_while(), foedus::snapshot::SnapshotManagerPimpl::trigger_snapshot_immediate(), foedus::thread::ImpersonateSession::wait(), foedus::soc::SharedRendezvous::wait_for(), foedus::thread::ImpersonateSession::wait_for(), foedus::xct::XctManagerPimpl::wait_for_current_global_epoch(), and foedus::log::LogManagerPimpl::wait_until_durable().
void foedus::soc::SharedPolling::wait | ( | uint64_t | demanded_ticket, |
uint64_t | polling_spins = kDefaultPollingSpins , |
||
uint64_t | max_interval_us = kDefaultPollingMaxIntervalUs |
||
) | const |
Unconditionally wait for signal.
[in] | demanded_ticket | returns when cur_ticket_ becomes this value or larger. |
[in] | polling_spins | we stop spinning and switch to sleeps after this number of spins |
[in] | max_interval_us | the sleep interval exponentially grows up to this value in microsec. |
Definition at line 42 of file shared_polling.cpp.
References foedus::soc::kInitialPollingIntervalUs.
Referenced by foedus::xct::XctManagerPimpl::advance_current_global_epoch(), foedus::savepoint::SavepointManagerPimpl::take_savepoint(), foedus::savepoint::SavepointManagerPimpl::take_savepoint_after_snapshot(), foedus::soc::SharedRendezvous::wait(), foedus::xct::XctManagerPimpl::wait_for_current_global_epoch(), and foedus::log::LogManagerPimpl::wait_until_durable().