diff options
author | Josh Blum | 2013-06-01 23:12:21 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-01 23:12:21 -0700 |
commit | ab1f7e5871d9323242e9b3d21e2f7811f1567c43 (patch) | |
tree | 3046176a463a3938a86563bdbf274467ff30974e /lib | |
parent | d15ca88acfbd71c5d4f8ab3dabe0f4fbde205985 (diff) | |
download | sandhi-ab1f7e5871d9323242e9b3d21e2f7811f1567c43.tar.gz sandhi-ab1f7e5871d9323242e9b3d21e2f7811f1567c43.tar.bz2 sandhi-ab1f7e5871d9323242e9b3d21e2f7811f1567c43.zip |
gras: mutex fixes for uid API calls
Diffstat (limited to 'lib')
-rw-r--r-- | lib/element.cpp | 7 | ||||
-rw-r--r-- | lib/element_uid.cpp | 21 |
2 files changed, 16 insertions, 12 deletions
diff --git a/lib/element.cpp b/lib/element.cpp index 04a638b..c06d96d 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -33,7 +33,7 @@ Element::Element(const std::string &name) catch(const std::invalid_argument &ex) { extra = str(boost::format("%04x") % short(h++)); - uid = name+"#"+extra; + uid = name+" "+extra; } } if (not extra.empty()) (*this)->repr = name; @@ -74,6 +74,11 @@ bool Element::equals(const Element &rhs) return this->get() == rhs.get(); } +std::string Element::to_string(void) const +{ + return (*this)->repr; +} + void Element::adopt_element(const std::string &name, const Element &child) { if (child->parent) throw std::invalid_argument(str(boost::format( diff --git a/lib/element_uid.cpp b/lib/element_uid.cpp index 89035b4..49daad9 100644 --- a/lib/element_uid.cpp +++ b/lib/element_uid.cpp @@ -15,32 +15,31 @@ static std::set<std::string> &get_uid_set(void) return uid_set; } -static void free_uid(void *p) +static void free_uid(std::string *s) { boost::mutex::scoped_lock l(uid_mutex); - std::string *uid = reinterpret_cast<std::string *>(p); - get_uid_set().erase(*uid); - delete uid; + get_uid_set().erase(*s); + delete s; } -void Element::set_uid(const std::string &uid) +static std::string *alloc_uid(const std::string &uid) { boost::mutex::scoped_lock l(uid_mutex); if (get_uid_set().count(uid) > 0) { throw std::invalid_argument("Element::set_uid - uid already in use: " + uid); } - (*this)->uid.reset(new std::string(uid), &free_uid); get_uid_set().insert(uid); + return new std::string(uid); } -std::string Element::get_uid(void) const +void Element::set_uid(const std::string &uid) { - boost::mutex::scoped_lock l(uid_mutex); - return *((*this)->uid); + (*this)->uid.reset(alloc_uid(uid), &free_uid); } -std::string Element::to_string(void) const +std::string Element::get_uid(void) const { - return (*this)->repr; + boost::mutex::scoped_lock l(uid_mutex); + return *((*this)->uid); } |