Zero  0.1.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
worker_thread_t Class Referenceabstract

#include <worker_thread.h>

Inheritance diagram for worker_thread_t:
thread_wrapper_t BackgroundRestorer< Coordinator, OnDoneCallback > chkpt_m log_worker_thread_t MergerDaemon page_cleaner_base restart_thread_t RunRecycler SkewShiftingThread zero::buffer_pool::PageEvictioner

Public Member Functions

 worker_thread_t (int inverval_ms=-1)
 
virtual ~worker_thread_t ()
 
void wakeup (bool wait=false, int rounds_to_wait=-1)
 
void stop ()
 
void wait_for_round (long round=0)
 
long get_rounds_completed () const
 
bool is_busy () const
 
- Public Member Functions inherited from thread_wrapper_t
 thread_wrapper_t ()
 
virtual ~thread_wrapper_t ()
 
virtual void before_run ()
 
virtual void after_run ()
 
void spawn ()
 
void fork ()
 
void join ()
 

Protected Member Functions

virtual void do_work ()=0
 
bool should_exit () const
 
void notify_one ()
 
void notify_all ()
 
void quit ()
 

Private Member Functions

virtual void run ()
 

Private Attributes

std::mutex cond_mutex
 
std::condition_variable wakeup_condvar
 
std::condition_variable done_condvar
 
int interval_msec
 
std::atomic< bool > stop_requested
 
bool wakeup_requested
 
bool worker_busy
 
long rounds_completed
 

Constructor & Destructor Documentation

§ worker_thread_t()

worker_thread_t::worker_thread_t ( int  inverval_ms = -1)

§ ~worker_thread_t()

worker_thread_t::~worker_thread_t ( )
virtual

Member Function Documentation

§ do_work()

virtual void worker_thread_t::do_work ( )
protectedpure virtual

§ get_rounds_completed()

long worker_thread_t::get_rounds_completed ( ) const
inline

§ is_busy()

bool worker_thread_t::is_busy ( ) const
inline

§ notify_all()

void worker_thread_t::notify_all ( )
protected

§ notify_one()

void worker_thread_t::notify_one ( )
protected

These methods can be called from inside the do_work() implementation to wake up threads waiting at wait_for_notify().

§ quit()

void worker_thread_t::quit ( )
protected

§ run()

void worker_thread_t::run ( )
privatevirtual

Implements thread_wrapper_t.

§ should_exit()

bool worker_thread_t::should_exit ( ) const
inlineprotected

Used to check inside work method if thread should exit without waiting for a complete do_work round

§ stop()

void worker_thread_t::stop ( )

Request worker to stop on next do_work iteration and wait.

§ wait_for_round()

void worker_thread_t::wait_for_round ( long  round = 0)

Wait until the round number given has been completed. If round <= rounds_completed, just wait for a notify instead of whole rounds.

§ wakeup()

void worker_thread_t::wakeup ( bool  wait = false,
int  rounds_to_wait = -1 
)

Wakes up the worker thread. If wait = true, the call will block until the worker has sent a notification on done_condvar AND the given number of rounds has passed. If rounds_to_wait == -1, then we only wait for a notify. If rounds_to_wait == 0, then we wait for the current round to finish if the worker is busy; if the worker is not busy, then it behaves just like the "-1" case. If rounds_to_wait > 0, then we wait for at least one full round (which means we actually wait for at least two round increments if the worker is busy)

Member Data Documentation

§ cond_mutex

std::mutex worker_thread_t::cond_mutex
private

§ done_condvar

std::condition_variable worker_thread_t::done_condvar
private

§ interval_msec

int worker_thread_t::interval_msec
private

Interval at which do_work is invoked, in milliseconds. If < 0: only invoked when explicitly woken up. If = 0: no timeout or wakeup necessary – run continuously If > 0: wait for this timeout or a wakeup signal, whatever comes first.

§ rounds_completed

long worker_thread_t::rounds_completed
private

number of do_work() rounds already completed by the worker

§ stop_requested

std::atomic<bool> worker_thread_t::stop_requested
private

whether this thread has been requested to stop.

§ wakeup_condvar

std::condition_variable worker_thread_t::wakeup_condvar
private

§ wakeup_requested

bool worker_thread_t::wakeup_requested
private

whether this thread has been requested to wakeup.

§ worker_busy

bool worker_thread_t::worker_busy
private

whether this thread is currently busy (and not waiting for wakeup


The documentation for this class was generated from the following files: