Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/source/server/watchdog_impl.h
Line
Count
Source (jump to first uncovered line)
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
3.95k
  WatchDogImpl(Thread::ThreadId thread_id) : thread_id_(thread_id) {}
20
21
0
  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
268
  bool getTouchedAndReset() { return touched_.exchange(false, std::memory_order_relaxed); }
24
25
  // Server::WatchDog
26
57.1k
  void touch() override {
27
    // Set touched_ if not already set.
28
57.1k
    bool expected = false;
29
57.1k
    touched_.compare_exchange_strong(expected, true, std::memory_order_relaxed);
30
57.1k
  }
31
32
private:
33
  const Thread::ThreadId thread_id_;
34
  std::atomic<bool> touched_{false};
35
};
36
37
} // namespace Server
38
} // namespace Envoy