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:
+27
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user