Coverage Report

Created: 2023-11-12 09:30

/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
5.29k
  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
985
  bool getTouchedAndReset() { return touched_.exchange(false, std::memory_order_relaxed); }
24
25
  // Server::WatchDog
26
100k
  void touch() override {
27
    // Set touched_ if not already set.
28
100k
    bool expected = false;
29
100k
    touched_.compare_exchange_strong(expected, true, std::memory_order_relaxed);
30
100k
  }
31
32
private:
33
  const Thread::ThreadId thread_id_;
34
  std::atomic<bool> touched_{false};
35
};
36
37
} // namespace Server
38
} // namespace Envoy