-
Notifications
You must be signed in to change notification settings - Fork 1
/
watchdog_impl.h
38 lines (30 loc) · 1002 Bytes
/
watchdog_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include <atomic>
#include "envoy/server/watchdog.h"
namespace Envoy {
namespace Server {
/**
* This class stores the actual data about when the WatchDog was last touched
* along with thread metadata.
*/
class WatchDogImpl : public WatchDog {
public:
/**
* @param thread_id ThreadId of the monitored thread
*/
WatchDogImpl(Thread::ThreadId thread_id) : thread_id_(thread_id) {}
Thread::ThreadId threadId() const override { return thread_id_; }
// Used by GuardDogImpl determine if the watchdog was touched recently and reset the touch status.
bool getTouchedAndReset() { return touched_.exchange(false, std::memory_order_relaxed); }
// Server::WatchDog
void touch() override {
// Set touched_ if not already set.
bool expected = false;
touched_.compare_exchange_strong(expected, true, std::memory_order_relaxed);
}
private:
const Thread::ThreadId thread_id_;
std::atomic<bool> touched_{false};
};
} // namespace Server
} // namespace Envoy