1
#pragma once
2

            
3
#include <atomic>
4

            
5
#include "envoy/server/watchdog.h"
6

            
7
namespace Envoy {
8
namespace Server {
9

            
10
/**
11
 * This class stores the actual data about when the WatchDog was last touched
12
 * along with thread metadata.
13
 */
14
class WatchDogImpl : public WatchDog {
15
public:
16
  /**
17
   * @param thread_id ThreadId of the monitored thread
18
   */
19
21277
  WatchDogImpl(Thread::ThreadId thread_id) : thread_id_(thread_id) {}
20

            
21
228
  Thread::ThreadId threadId() const override { return thread_id_; }
22
  // Used by GuardDogImpl determine if the watchdog was touched recently and reset the touch status.
23
57770
  bool getTouchedAndReset() { return touched_.exchange(false, std::memory_order_relaxed); }
24

            
25
  // Server::WatchDog
26
8275390
  void touch() override {
27
    // Set touched_ if not already set.
28
8275390
    bool expected = false;
29
8275390
    touched_.compare_exchange_strong(expected, true, std::memory_order_relaxed);
30
8275390
  }
31

            
32
private:
33
  const Thread::ThreadId thread_id_;
34
  std::atomic<bool> touched_{false};
35
};
36

            
37
} // namespace Server
38
} // namespace Envoy