29 lines
702 B
C++
29 lines
702 B
C++
#pragma once
|
|
|
|
#include <mutex>
|
|
#include <vector>
|
|
#include <list>
|
|
|
|
namespace Feather
|
|
{
|
|
template <typename T>
|
|
class Lockable {
|
|
public:
|
|
auto borrow() { return std::pair< T&, std::lock_guard<std::mutex>>{object, mutex}; }
|
|
auto borrow() const { return std::pair<const T&, std::lock_guard<std::mutex>>{object, mutex}; }
|
|
|
|
T& steal() { return object; }
|
|
const T& steal() const { return object; }
|
|
|
|
private:
|
|
T object;
|
|
mutable std::mutex mutex;
|
|
};
|
|
|
|
template <typename T>
|
|
using LockableVector = Lockable<std::vector<T>>;
|
|
|
|
template <typename T>
|
|
using LockableList = Lockable<std::list<T>>;
|
|
}
|