X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6a908b79ea45f85f305620c09375b72483b7eee9..3f4f5e63dadc0023c0a02a08af8e9e9801b38e8e:/src/sthread/ObjectAccess.cpp diff --git a/src/sthread/ObjectAccess.cpp b/src/sthread/ObjectAccess.cpp index 6e19b61279..25e9b52c32 100644 --- a/src/sthread/ObjectAccess.cpp +++ b/src/sthread/ObjectAccess.cpp @@ -35,7 +35,6 @@ public: } void serialize(std::stringstream& stream) const override; std::string to_string() const override; - bool is_visible() const override { return true; } }; void ObjectAccessObserver::serialize(std::stringstream& stream) const { @@ -52,6 +51,7 @@ struct ObjectOwner { simgrid::kernel::actor::ActorImpl* owner = nullptr; const char* file = nullptr; int line = -1; + int recursive_depth = 0; explicit ObjectOwner(simgrid::kernel::actor::ActorImpl* o) : owner(o) {} }; @@ -67,15 +67,14 @@ static ObjectOwner* get_owner(void* object) { if (owners.empty()) std::atexit(clean_owners); - auto it = owners.find(object); - if (it != owners.end()) + if (auto it = owners.find(object); it != owners.end()) return it->second; auto* o = new ObjectOwner(nullptr); - owners.insert({object, o}); + owners.emplace(object, o); return o; } -int sthread_access_begin(void* objaddr, const char* objname, const char* file, int line) +int sthread_access_begin(void* objaddr, const char* objname, const char* file, int line, const char* func) { sthread_disable(); auto* self = simgrid::kernel::actor::ActorImpl::self(); @@ -85,10 +84,23 @@ int sthread_access_begin(void* objaddr, const char* objname, const char* file, i [self, objaddr, objname, file, line]() -> bool { XBT_INFO("%s takes %s", self->get_cname(), objname); auto* ownership = get_owner(objaddr); - if (ownership->owner != nullptr) { + if (ownership->owner == self) { + ownership->recursive_depth++; + return true; + } else if (ownership->owner != nullptr) { auto msg = std::string("Unprotected concurent access to ") + objname + ": " + ownership->owner->get_name(); - if (not xbt_log_no_loc) + if (not xbt_log_no_loc) { msg += simgrid::xbt::string_printf(" at %s:%d", ownership->file, ownership->line); + if (ownership->recursive_depth > 1) { + msg += simgrid::xbt::string_printf(" (and %d other locations)", ownership->recursive_depth - 1); + if (ownership->recursive_depth != 2) + msg += "s"; + } + } else { + msg += simgrid::xbt::string_printf(" from %d location", ownership->recursive_depth); + if (ownership->recursive_depth != 1) + msg += "s"; + } msg += " vs " + self->get_name(); if (xbt_log_no_loc) msg += std::string(" (locations hidden because of --log=no_loc)."); @@ -100,6 +112,7 @@ int sthread_access_begin(void* objaddr, const char* objname, const char* file, i ownership->owner = self; ownership->file = file; ownership->line = line; + ownership->recursive_depth = 1; return true; }, &observer); @@ -108,7 +121,7 @@ int sthread_access_begin(void* objaddr, const char* objname, const char* file, i sthread_enable(); return true; } -void sthread_access_end(void* objaddr, const char* objname, const char* file, int line) +void sthread_access_end(void* objaddr, const char* objname, const char* file, int line, const char* func) { sthread_disable(); auto* self = simgrid::kernel::actor::ActorImpl::self(); @@ -118,9 +131,12 @@ void sthread_access_end(void* objaddr, const char* objname, const char* file, in [self, objaddr, objname]() -> void { XBT_INFO("%s releases %s", self->get_cname(), objname); auto* ownership = get_owner(objaddr); - xbt_assert(ownership->owner == self, "safety check failed: %s is not owner of the object it's releasing.", - self->get_cname()); - ownership->owner = nullptr; + xbt_assert(ownership->owner == self, + "safety check failed: %s is not owner of the object it's releasing. That object owned by %s.", + self->get_cname(), (ownership->owner == nullptr ? "nobody" : ownership->owner->get_cname())); + ownership->recursive_depth--; + if (ownership->recursive_depth == 0) + ownership->owner = nullptr; }, &observer); sthread_enable();