return XW_OK;
}
+std::mutex Instance::instances_mutex_;
std::unordered_set<Instance*> Instance::all_instances_;
Instance::Instance() : xw_instance_(0) {
ScopeLogger();
- { all_instances_.insert(this); }
+ {
+ std::lock_guard<std::mutex> lock{instances_mutex_};
+ all_instances_.insert(this);
+ }
}
Instance::~Instance() {
ScopeLogger();
- { all_instances_.erase(this); }
+ {
+ std::lock_guard<std::mutex> lock{instances_mutex_};
+ all_instances_.erase(this);
+ }
Assert(xw_instance_ == 0);
}
void Instance::PostMessage(Instance* that, const char* msg) {
ScopeLogger();
- if (that && all_instances_.end() != all_instances_.find(that)) {
- that->PostMessage(msg);
- } else {
- LoggerE("Trying to post message to non-existing instance: [%p], ignoring", that);
+ if (nullptr != that) {
+ std::lock_guard<std::mutex> lock{instances_mutex_};
+ if (all_instances_.end() != all_instances_.find(that)) {
+ that->PostMessage(msg);
+ return;
+ }
}
+ LoggerE("Trying to post message to non-existing instance: [%p], ignoring", that);
}
void Instance::PostMessage(const char* msg) {