vg
tools for working with variation graphs
|
#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_t > | state |
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 | |
Watchdog & | operator= (const Watchdog &other)=delete |
Watchdog & | operator= (Watchdog &&other)=delete |
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.
using vg::Watchdog::clock = chrono::steady_clock |
using vg::Watchdog::duration = clock::duration |
using vg::Watchdog::time_point = clock::time_point |
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.
vg::Watchdog::~Watchdog | ( | ) |
Destroy the Watchdog. Automatically stops and joins on the monitoring thread.
|
privatedelete |
|
privatedelete |
void vg::Watchdog::check_in | ( | size_t | thread, |
const string & | task | ||
) |
Check the given thread in, to do the given task.
void vg::Watchdog::check_out | ( | size_t | thread | ) |
Check the given thread out of the task it is checked in for.
|
protected |
Function run in the watcher thread.
|
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.
|
protected |
Holds the state of each thread, along with its mutex.
|
protected |
Have we been asked to stop the watcher thread?
|
protected |
How long should we give a task to be checked in before complaining?
|
protected |
We have a thread that does our watchdogging.