Start working on a VFS implementation #22

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

View File

@ -117,12 +117,17 @@ template <typename T, class... Args> Result<SharedPtr<T>> make_shared(Args... ar
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)
{
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 };
}
@ -138,13 +143,7 @@ template <typename T> Result<SharedPtr<T>> adopt_shared_from_owned(OwnedPtr<T>&&
T* ptr = other.m_ptr;
other.m_ptr = nullptr;
// FIXME: Should the pointee magically vanish on failure? Or go back into the OwnedPtr, even though it's been
// moved...
auto guard = make_scope_guard([&] { delete ptr; });
const SharedPtr<T> shared_ptr = TRY(adopt_shared(ptr));
guard.deactivate();
return shared_ptr;
}