2020-07-29 01:46:31 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
2020-07-29 15:34:10 +01:00
|
|
|
#include <list>
|
2020-07-29 01:46:31 +01:00
|
|
|
|
|
|
|
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}; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
T object;
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using LockableVector = Lockable<std::vector<T>>;
|
2020-07-29 15:34:10 +01:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using LockableList = Lockable<std::list<T>>;
|
2020-08-01 00:57:33 +01:00
|
|
|
}
|