diff --git a/lix/libutil/logging.hh b/lix/libutil/logging.hh index 08c7c382d..20588c828 100644 --- a/lix/libutil/logging.hh +++ b/lix/libutil/logging.hh @@ -214,11 +214,34 @@ struct Activity friend class Logger; }; -struct PushActivity +class PushActivity { - const ActivityId prevAct; - PushActivity(ActivityId act) : prevAct(getCurActivity()) { setCurActivity(act); } - ~PushActivity() { setCurActivity(prevAct); } + std::optional prevAct; + +public: + PushActivity(ActivityId act) : prevAct(getCurActivity()) + { + setCurActivity(act); + } + + PushActivity(PushActivity && other) + { + std::swap(prevAct, other.prevAct); + } + + PushActivity & operator=(PushActivity && other) + { + auto tmp(std::move(other)); + std::swap(prevAct, tmp.prevAct); + return *this; + } + + ~PushActivity() + { + if (prevAct) { + setCurActivity(*prevAct); + } + } }; extern Logger * logger;