LCOV - code coverage report
Current view: top level - source/server - watchdog_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 6 8 75.0 %
Date: 2024-01-05 06:35:25 Functions: 3 4 75.0 %

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

Generated by: LCOV version 1.15