Use std::atomic family

This commit is contained in:
Joachim Mårtensson
2013-09-05 20:35:14 +02:00
committed by Allan Odgaard
parent aa24f237c6
commit ca98e2f86d
2 changed files with 1 additions and 11 deletions

View File

@@ -23,24 +23,14 @@ namespace scope
_parent->release();
}
static std::mutex& retain_count_lock ()
{
static std::mutex* res = new std::mutex;
return *res;
}
void scope_t::node_t::retain ()
{
retain_count_lock().lock();
++_retain_count;
retain_count_lock().unlock();
}
void scope_t::node_t::release ()
{
retain_count_lock().lock();
bool shouldDelete = --_retain_count == 0;
retain_count_lock().unlock();
if(shouldDelete)
delete this;
}

View File

@@ -61,7 +61,7 @@ namespace scope
private:
std::string _atoms;
node_t* _parent;
size_t _retain_count = 1;
std::atomic_size_t _retain_count;
};
explicit scope_t (node_t* node);