mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +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
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/RefPtr.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
@ -15,10 +16,10 @@ ErrorOr<FlatPtr> Process::sys$chdir(Userspace<char const*> user_path, size_t pat
|
|||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
TRY(require_promise(Pledge::rpath));
|
||||
auto path = TRY(get_syscall_path_argument(user_path, path_length));
|
||||
auto current_directory = m_current_directory.with([](auto& current_directory) -> NonnullLockRefPtr<Custody> {
|
||||
auto current_directory = m_current_directory.with([](auto& current_directory) -> NonnullRefPtr<Custody> {
|
||||
return *current_directory;
|
||||
});
|
||||
LockRefPtr<Custody> new_directory = TRY(VirtualFileSystem::the().open_directory(path->view(), *current_directory));
|
||||
RefPtr<Custody> new_directory = TRY(VirtualFileSystem::the().open_directory(path->view(), *current_directory));
|
||||
m_current_directory.with([&](auto& current_directory) {
|
||||
// NOTE: We use swap() here to avoid manipulating the ref counts while holding the lock.
|
||||
swap(current_directory, new_directory);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue