X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/39c935d6d5ee86d153f6f7e6a10d723ae7c57f6f..7f671da878195261904d4bbc180a697902799dad:/src/smpi/include/smpi_keyvals.hpp diff --git a/src/smpi/include/smpi_keyvals.hpp b/src/smpi/include/smpi_keyvals.hpp index 7fd5e301e8..d1c647d582 100644 --- a/src/smpi/include/smpi_keyvals.hpp +++ b/src/smpi/include/smpi_keyvals.hpp @@ -44,7 +44,8 @@ class Keyval{ private: std::unordered_map attributes_; protected: - std::unordered_map* attributes(); + std::unordered_map& attributes() { return attributes_; } + public: // Each subclass should have two members, as we want to separate the ones for Win, Comm, and Datatypes : // static std::unordered_map keyvals_; @@ -72,7 +73,7 @@ int Keyval::keyval_create(const smpi_copy_fn& copy_fn, const smpi_delete_fn& del value->refcount=1; *keyval = T::keyval_id_; - T::keyvals_.insert({*keyval, value}); + T::keyvals_.emplace(*keyval, value); T::keyval_id_++; return MPI_SUCCESS; } @@ -90,6 +91,7 @@ template int Keyval::keyval_free(int* keyval){ }else{ elem->refcount--; } + *keyval = MPI_KEYVAL_INVALID; return MPI_SUCCESS; } @@ -105,9 +107,9 @@ template int Keyval::attr_delete(int keyval){ if(ret!=MPI_SUCCESS) return ret; } - if(attributes()->empty()) + if (attributes().empty()) return MPI_ERR_ARG; - attributes()->erase(keyval); + attributes().erase(keyval); return MPI_SUCCESS; } @@ -116,13 +118,9 @@ template int Keyval::attr_get(int keyval, void* attr_value, int* fl const s_smpi_key_elem_t* elem = T::keyvals_.at(keyval); if(elem==nullptr) return MPI_ERR_ARG; - if(attributes()->empty()){ - *flag=0; - return MPI_SUCCESS; - } - const auto& attribs = attributes(); - auto attr = attribs->find(keyval); - if (attr != attribs->end()) { + + auto attr = attributes().find(keyval); + if (attr != attributes().end()) { *static_cast(attr_value) = attr->second; *flag=1; } else { @@ -137,8 +135,8 @@ template int Keyval::attr_put(int keyval, void* attr_value){ return MPI_ERR_ARG; elem->refcount++; int flag=0; - auto p = attributes()->insert({keyval, attr_value}); - if (!p.second) { + auto p = attributes().emplace(keyval, attr_value); + if (not p.second) { int ret = call_deleter((T*)this, elem, keyval,p.first->second,&flag); // overwrite previous value p.first->second = attr_value; @@ -149,19 +147,17 @@ template int Keyval::attr_put(int keyval, void* attr_value){ } template void Keyval::cleanup_attr(){ - if (not attributes()->empty()) { - int flag=0; - for (auto const& it : attributes_) { - auto elm = T::keyvals_.find(it.first); - if (elm != T::keyvals_.end()) { - smpi_key_elem elem = elm->second; - if(elem != nullptr){ - call_deleter((T*)this, elem, it.first,it.second,&flag); - } - } else { - // already deleted, not a problem - flag=0; + int flag = 0; + for (auto const& it : attributes()) { + auto elm = T::keyvals_.find(it.first); + if (elm != T::keyvals_.end()) { + smpi_key_elem elem = elm->second; + if (elem != nullptr) { + call_deleter((T*)this, elem, it.first, it.second, &flag); } + } else { + // already deleted, not a problem + flag = 0; } } }