Start working on a VFS implementation #22

Closed
apio wants to merge 44 commits from oop-vfs into main
Showing only changes of commit 620810d720 - Show all commits

View File

@ -123,10 +123,18 @@ template <typename T> Result<SharedPtr<T>> adopt_shared(T* ptr)
return SharedPtr<T> { ptr, ref_count };
}
template <typename T, class... Args> Result<SharedPtr<T>> make_shared(Args... args)
// NOTE: ptr is deleted if any of the adopt_shared* functions fail to construct a SharedPtr.
template <typename T> Result<SharedPtr<T>> adopt_shared(T* ptr)
{
T* raw_ptr = TRY(make<T>(args...));
return adopt_shared(raw_ptr);
using RefCount = __detail::RefCount;
auto guard = make_scope_guard([ptr] { delete ptr; });
RefCount* const ref_count = TRY(make<RefCount>());
guard.deactivate();
return SharedPtr<T> { ptr, ref_count };
}
template <typename T> Result<SharedPtr<T>> adopt_shared_if_nonnull(T* ptr)