#pragma once #include #include namespace DB { class ActionBlocker; using StorageActionBlockType = size_t; /// Blocks related action while a ActionLock instance exists /// ActionBlocker could be destroyed before the lock, in this case ActionLock will safely do nothing in its destructor class ActionLock { public: ActionLock() = default; explicit ActionLock(const ActionBlocker & blocker); ActionLock(ActionLock && other); ActionLock & operator=(ActionLock && other); ActionLock(const ActionLock & other) = delete; ActionLock & operator=(const ActionLock & other) = delete; bool expired() const { return counter_ptr.expired(); } ~ActionLock() { if (auto counter = counter_ptr.lock()) --(*counter); } private: using Counter = std::atomic; using CounterWeakPtr = std::weak_ptr; CounterWeakPtr counter_ptr; }; }