libutil: make PushActivity movable

while not copy-assignable it was still copy-constructible, which can
lead to some very unfortunate interactions with closure captures. we
will also need to move current-activity handles in upcoming changes.

Change-Id: I63cede83b9790820c6bd8784fb5d47e5246b7c4a
This commit is contained in:
eldritch horrors
2025-02-23 17:18:48 +00:00
parent f9a05605c1
commit a4e7cfdb57
+27 -4
View File
@@ -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<ActivityId> 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;