From: Gabriel Corona Date: Mon, 11 Jul 2016 10:12:55 +0000 (+0200) Subject: [mc] Remove xbt_dict in ModelChecker X-Git-Tag: v3_14~778 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/76871aa367f5100a2ac974818c477dc46406bc73 [mc] Remove xbt_dict in ModelChecker --- diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index 61a946d6ff..20236555df 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -48,7 +48,6 @@ namespace simgrid { namespace mc { ModelChecker::ModelChecker(std::unique_ptr process) : - hostnames_(xbt_dict_new()), page_store_(500), process_(std::move(process)), parent_snapshot_(nullptr) @@ -56,22 +55,7 @@ ModelChecker::ModelChecker(std::unique_ptr process) : } -ModelChecker::~ModelChecker() -{ - xbt_dict_free(&this->hostnames_); -} - -const char* ModelChecker::get_host_name(const char* hostname) -{ - // Lookup the host name in the dictionary (or create it): - xbt_dictelm_t elt = xbt_dict_get_elm_or_null(this->hostnames_, hostname); - if (!elt) { - xbt_dict_set(this->hostnames_, hostname, nullptr, nullptr); - elt = xbt_dict_get_elm_or_null(this->hostnames_, hostname); - assert(elt); - } - return elt->key; -} +ModelChecker::~ModelChecker() {} void ModelChecker::start() { diff --git a/src/mc/ModelChecker.hpp b/src/mc/ModelChecker.hpp index 6619f25c87..0e7ed9d9f3 100644 --- a/src/mc/ModelChecker.hpp +++ b/src/mc/ModelChecker.hpp @@ -10,10 +10,12 @@ #include #include + #include +#include +#include #include -#include #include #include @@ -32,7 +34,7 @@ class ModelChecker { struct pollfd fds_[2]; /** String pool for host names */ // TODO, use std::set with heterogeneous comparison lookup (C++14)? - xbt_dict_t /* */ hostnames_; + std::set hostnames_; // This is the parent snapshot of the current state: PageStore page_store_; std::unique_ptr process_; @@ -54,7 +56,15 @@ public: { return page_store_; } - const char* get_host_name(const char* name); + + std::string const& get_host_name(const char* hostname) + { + return *this->hostnames_.insert(hostname).first; + } + std::string const& get_host_name(std::string const& hostname) + { + return *this->hostnames_.insert(hostname).first; + } void start(); void shutdown(); diff --git a/src/mc/mc_smx.cpp b/src/mc/mc_smx.cpp index 85039bf283..e3d50c9b18 100644 --- a/src/mc/mc_smx.cpp +++ b/src/mc/mc_smx.cpp @@ -172,7 +172,7 @@ const char* MC_smx_process_get_host_name(smx_process_t p) simgrid::xbt::string_data remote_string = process->read(remote_string_address); char hostname[remote_string.len]; process->read_bytes(hostname, remote_string.len + 1, remote(remote_string.data)); - info->hostname = mc_model_checker->get_host_name(hostname); + info->hostname = mc_model_checker->get_host_name(hostname).c_str(); return info->hostname; }