mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 05:47:34 +00:00
Kernel: Use RefPtr instead of LockRefPtr for Custody
By protecting all the RefPtr<Custody> objects that may be accessed from multiple threads at the same time (with spinlocks), we remove the need for using LockRefPtr<Custody> (which is basically a RefPtr with a built-in spinlock.)
This commit is contained in:
parent
5331d243c6
commit
728c3fbd14
23 changed files with 143 additions and 102 deletions
|
@ -27,7 +27,7 @@ ErrorOr<NonnullLockRefPtr<OpenFileDescription>> OpenFileDescription::try_create(
|
|||
auto inode_file = TRY(InodeFile::create(custody.inode()));
|
||||
auto description = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) OpenFileDescription(move(inode_file))));
|
||||
|
||||
description->m_custody = custody;
|
||||
description->m_state.with([&](auto& state) { state.custody = custody; });
|
||||
TRY(description->attach());
|
||||
return description;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ ErrorOr<void> OpenFileDescription::attach()
|
|||
|
||||
void OpenFileDescription::set_original_custody(Badge<VirtualFileSystem>, Custody& custody)
|
||||
{
|
||||
m_custody = custody;
|
||||
m_state.with([&](auto& state) { state.custody = custody; });
|
||||
}
|
||||
|
||||
Thread::FileBlocker::BlockFlags OpenFileDescription::should_unblock(Thread::FileBlocker::BlockFlags block_flags) const
|
||||
|
@ -355,15 +355,15 @@ ErrorOr<void> OpenFileDescription::close()
|
|||
|
||||
ErrorOr<NonnullOwnPtr<KString>> OpenFileDescription::original_absolute_path() const
|
||||
{
|
||||
if (!m_custody)
|
||||
return ENOENT;
|
||||
return m_custody->try_serialize_absolute_path();
|
||||
if (auto custody = this->custody())
|
||||
return custody->try_serialize_absolute_path();
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<KString>> OpenFileDescription::pseudo_path() const
|
||||
{
|
||||
if (m_custody)
|
||||
return m_custody->try_serialize_absolute_path();
|
||||
if (auto custody = this->custody())
|
||||
return custody->try_serialize_absolute_path();
|
||||
return m_file->pseudo_path(*this);
|
||||
}
|
||||
|
||||
|
@ -538,4 +538,14 @@ off_t OpenFileDescription::offset() const
|
|||
return m_state.with([](auto& state) { return state.current_offset; });
|
||||
}
|
||||
|
||||
RefPtr<Custody const> OpenFileDescription::custody() const
|
||||
{
|
||||
return m_state.with([](auto& state) { return state.custody; });
|
||||
}
|
||||
|
||||
RefPtr<Custody> OpenFileDescription::custody()
|
||||
{
|
||||
return m_state.with([](auto& state) { return state.custody; });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue