summaryrefslogtreecommitdiff
path: root/lib/element_uid.cpp
diff options
context:
space:
mode:
authorJosh Blum2013-06-01 23:12:21 -0700
committerJosh Blum2013-06-01 23:12:21 -0700
commitab1f7e5871d9323242e9b3d21e2f7811f1567c43 (patch)
tree3046176a463a3938a86563bdbf274467ff30974e /lib/element_uid.cpp
parentd15ca88acfbd71c5d4f8ab3dabe0f4fbde205985 (diff)
downloadsandhi-ab1f7e5871d9323242e9b3d21e2f7811f1567c43.tar.gz
sandhi-ab1f7e5871d9323242e9b3d21e2f7811f1567c43.tar.bz2
sandhi-ab1f7e5871d9323242e9b3d21e2f7811f1567c43.zip
gras: mutex fixes for uid API calls
Diffstat (limited to 'lib/element_uid.cpp')
-rw-r--r--lib/element_uid.cpp21
1 files changed, 10 insertions, 11 deletions
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);
}