Start working on a VFS implementation #22

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

View File

@ -104,19 +104,6 @@ template <typename T> class SharedPtr
RefCount* m_ref_count;
};
template <typename T, class... Args> Result<SharedPtr<T>> make_shared(Args... args)
{
using RefCount = __detail::RefCount;
RefCount* const ref_count = TRY(make<RefCount>());
auto guard = make_scope_guard([&] { delete ref_count; });
T* const ptr = TRY(make<T>(args...));
guard.deactivate();
return SharedPtr<T> { ptr, ref_count };
}
// 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)
{
@ -131,6 +118,12 @@ 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)
{
T* raw_ptr = TRY(make<T>(args...));
return adopt_shared(raw_ptr);
}
template <typename T> Result<SharedPtr<T>> adopt_shared_if_nonnull(T* ptr)
{
if (ptr) return adopt_shared(ptr);