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