2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-07-31 18:33:49 +08:00
|
|
|
|
|
|
|
#include <mutex>
|
2016-06-17 02:07:49 +08:00
|
|
|
|
2016-08-10 16:39:02 +08:00
|
|
|
#include "threading/sync/spinlock.hpp"
|
2015-07-31 18:33:49 +08:00
|
|
|
|
|
|
|
template <class lock_t = SpinLock>
|
|
|
|
class Lockable
|
|
|
|
{
|
2015-10-08 06:58:29 +08:00
|
|
|
public:
|
|
|
|
using lock_type = lock_t;
|
|
|
|
|
2015-11-09 02:05:34 +08:00
|
|
|
std::lock_guard<lock_t> acquire_guard() const
|
2015-10-04 15:47:15 +08:00
|
|
|
{
|
|
|
|
return std::lock_guard<lock_t>(lock);
|
|
|
|
}
|
|
|
|
|
2015-11-09 02:05:34 +08:00
|
|
|
std::unique_lock<lock_t> acquire_unique() const
|
2015-07-31 18:33:49 +08:00
|
|
|
{
|
|
|
|
return std::unique_lock<lock_t>(lock);
|
|
|
|
}
|
2015-11-09 02:05:34 +08:00
|
|
|
|
|
|
|
mutable lock_t lock;
|
2015-07-31 18:33:49 +08:00
|
|
|
};
|