vg
tools for working with variation graphs
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
vg::Watchdog Class Reference

#include <watchdog.hpp>

Classes

struct  thread_state_t
 

Public Types

using clock = chrono::steady_clock
 
using duration = clock::duration
 
using time_point = clock::time_point
 

Public Member Functions

 Watchdog (size_t thread_count, const duration &timeout)
 
 ~Watchdog ()
 
void check_in (size_t thread, const string &task)
 
void check_out (size_t thread)
 

Protected Member Functions

void watcher_loop ()
 Function run in the watcher thread. More...
 

Protected Attributes

atomic< bool > stop_watcher
 Have we been asked to stop the watcher thread? More...
 
vector< thread_state_tstate
 Holds the state of each thread, along with its mutex. More...
 
duration timeout
 How long should we give a task to be checked in before complaining? More...
 
atomic< size_t > memory_high_water_kb
 
thread watcher
 We have a thread that does our watchdogging. More...
 

Private Member Functions

 Watchdog (const Watchdog &other)=delete
 
 Watchdog (Watchdog &&other)=delete
 
Watchdogoperator= (const Watchdog &other)=delete
 
Watchdogoperator= (Watchdog &&other)=delete
 

Detailed Description

Represents a watchdog timer. Each instance owns its own watching thread. Other threads will check in and check out as they start and complete tasks, and the watchdog thread will complain and possibly terminate the program if a thread stays checked in for too long.

All synchronization is managed internally. Threads are responsible for knowing their ID numbers, and we can only handle a certain number of threads.

Member Typedef Documentation

◆ clock

using vg::Watchdog::clock = chrono::steady_clock

◆ duration

using vg::Watchdog::duration = clock::duration

◆ time_point

using vg::Watchdog::time_point = clock::time_point

Constructor & Destructor Documentation

◆ Watchdog() [1/3]

vg::Watchdog::Watchdog ( size_t  thread_count,
const duration timeout 
)

Create a Watchdog monitoring the specified number of threads. Complain if any thread is checked in longer than timeout. Automatically starts the monitoring thread.

◆ ~Watchdog()

vg::Watchdog::~Watchdog ( )

Destroy the Watchdog. Automatically stops and joins on the monitoring thread.

◆ Watchdog() [2/3]

vg::Watchdog::Watchdog ( const Watchdog other)
privatedelete

◆ Watchdog() [3/3]

vg::Watchdog::Watchdog ( Watchdog &&  other)
privatedelete

Member Function Documentation

◆ check_in()

void vg::Watchdog::check_in ( size_t  thread,
const string &  task 
)

Check the given thread in, to do the given task.

◆ check_out()

void vg::Watchdog::check_out ( size_t  thread)

Check the given thread out of the task it is checked in for.

◆ operator=() [1/2]

Watchdog& vg::Watchdog::operator= ( const Watchdog other)
privatedelete

◆ operator=() [2/2]

Watchdog& vg::Watchdog::operator= ( Watchdog &&  other)
privatedelete

◆ watcher_loop()

void vg::Watchdog::watcher_loop ( )
protected

Function run in the watcher thread.

Member Data Documentation

◆ memory_high_water_kb

atomic<size_t> vg::Watchdog::memory_high_water_kb
protected

What's the most recent process memory high water mark estimate? We report on this when tasks take a long time in case they also are using a lot of memory.

◆ state

vector<thread_state_t> vg::Watchdog::state
protected

Holds the state of each thread, along with its mutex.

◆ stop_watcher

atomic<bool> vg::Watchdog::stop_watcher
protected

Have we been asked to stop the watcher thread?

◆ timeout

duration vg::Watchdog::timeout
protected

How long should we give a task to be checked in before complaining?

◆ watcher

thread vg::Watchdog::watcher
protected

We have a thread that does our watchdogging.


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