Skip to content
Snippets Groups Projects
Commit 63aec5d4 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

parallel_util.hh: imporve lock semantics

parent 9e26bb1c
Branches
Tags
No related merge requests found
......@@ -19,6 +19,7 @@
#define PARALLEL_UTIL_HH
#include <shared_mutex>
#include <utility>
namespace graph_tool
{
......@@ -28,9 +29,10 @@ class slock
{
public:
slock(Mutex& mutex, bool lock=true)
: _lock(mutex, std::defer_lock_t())
{
if (lock)
_lock = std::shared_lock<Mutex>(mutex);
_lock.lock();
}
private:
......@@ -42,9 +44,10 @@ class ulock
{
public:
ulock(Mutex& mutex, bool lock=true)
: _lock(mutex, std::defer_lock_t())
{
if (lock)
_lock = std::unique_lock<Mutex>(mutex);
_lock.lock();
}
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment