core_timing: Lock CoreTiming event queue while deserializing

To handle those classic asymmetric constructor/destructor side effects
This commit is contained in:
zhupengfei 2021-02-08 11:24:05 +08:00
parent b2531310b4
commit 996ca25a2e
No known key found for this signature in database
GPG key ID: DD129E108BD09378
3 changed files with 23 additions and 0 deletions

View file

@ -280,6 +280,11 @@ public:
std::shared_ptr<Timer> GetTimer(std::size_t cpu_id);
// Used after deserializing to unprotect the event queue.
void UnlockEventQueue() {
event_queue_locked = false;
}
private:
// unordered_map stores each element separately as a linked list node so pointers to
// elements remain stable regardless of rehashes/resizing.
@ -292,6 +297,10 @@ private:
// under/overclocking the guest cpu
double cpu_clock_scale = 1.0;
// When true, the event queue can't be modified. Used while deserializing to workaround
// destructor side effects.
bool event_queue_locked = false;
template <class Archive>
void serialize(Archive& ar, const unsigned int file_version) {
// event_types set during initialization of other things
@ -303,6 +312,9 @@ private:
} else {
ar& current_timer;
}
if (Archive::is_loading::value) {
event_queue_locked = true;
}
}
friend class boost::serialization::access;
};