55 virtual ~ResourceLock() =
default;
58 template <
typename T>
class ResourceLockImpl :
public ResourceLock {
59 std::shared_ptr<T> m_resource;
62 explicit ResourceLockImpl(std::shared_ptr<T> resource)
63 : m_resource(std::move(resource)) {}
64 ~ResourceLockImpl()
override { m_resource.reset(); }
67 template <
typename T>
using LifoList = std::stack<T, std::list<T>>;
69 LifoList<std::unique_ptr<ResourceLock>> m_resources;
75 while (not m_resources.empty()) {
80 template <
typename T>
void acquire_lock(std::shared_ptr<T> resource) {
81 m_resources.emplace(std::make_unique<ResourceLockImpl<T>>(resource));