1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

Kernel: Use RefPtr instead of LockRefPtr for File and subclasses

This was mostly straightforward, as all the storage locations are
guarded by some related mutex.

The use of old-school associated mutexes instead of MutexProtected
is unfortunate, but the process to modernize such code is ongoing.
This commit is contained in:
Andreas Kling 2023-03-10 07:53:02 +01:00
parent 61bb9103c2
commit 03cc45e5a2
20 changed files with 63 additions and 63 deletions

View file

@ -13,9 +13,9 @@ namespace Kernel {
class AnonymousFile final : public File {
public:
static ErrorOr<NonnullLockRefPtr<AnonymousFile>> try_create(NonnullLockRefPtr<Memory::AnonymousVMObject> vmobject)
static ErrorOr<NonnullRefPtr<AnonymousFile>> try_create(NonnullLockRefPtr<Memory::AnonymousVMObject> vmobject)
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
}
virtual ~AnonymousFile() override;

View file

@ -16,10 +16,10 @@ namespace Kernel {
static Atomic<int> s_next_fifo_id = 1;
ErrorOr<NonnullLockRefPtr<FIFO>> FIFO::try_create(UserID uid)
ErrorOr<NonnullRefPtr<FIFO>> FIFO::try_create(UserID uid)
{
auto buffer = TRY(DoubleBuffer::try_create("FIFO: Buffer"sv));
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
return adopt_nonnull_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
}
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)

View file

@ -24,7 +24,7 @@ public:
Writer
};
static ErrorOr<NonnullLockRefPtr<FIFO>> try_create(UserID);
static ErrorOr<NonnullRefPtr<FIFO>> try_create(UserID);
virtual ~FIFO() override;
UserID uid() const { return m_uid; }

View file

@ -180,7 +180,7 @@ void Inode::unregister_watcher(Badge<InodeWatcher>, InodeWatcher& watcher)
});
}
ErrorOr<NonnullLockRefPtr<FIFO>> Inode::fifo()
ErrorOr<NonnullRefPtr<FIFO>> Inode::fifo()
{
MutexLocker locker(m_inode_lock);
VERIFY(metadata().is_fifo());
@ -189,7 +189,7 @@ ErrorOr<NonnullLockRefPtr<FIFO>> Inode::fifo()
if (!m_fifo)
m_fifo = TRY(FIFO::try_create(metadata().uid));
return NonnullLockRefPtr { *m_fifo };
return NonnullRefPtr { *m_fifo };
}
void Inode::set_metadata_dirty(bool metadata_dirty)

View file

@ -102,7 +102,7 @@ public:
ErrorOr<void> register_watcher(Badge<InodeWatcher>, InodeWatcher&);
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
ErrorOr<NonnullLockRefPtr<FIFO>> fifo();
ErrorOr<NonnullRefPtr<FIFO>> fifo();
bool can_apply_flock(flock const&, Optional<OpenFileDescription const&> = {}) const;
ErrorOr<void> apply_flock(Process const&, OpenFileDescription const&, Userspace<flock const*>, ShouldBlock);
@ -134,7 +134,7 @@ private:
LockWeakPtr<LocalSocket> m_bound_socket;
SpinlockProtected<HashTable<InodeWatcher*>, LockRank::None> m_watchers {};
bool m_metadata_dirty { false };
LockRefPtr<FIFO> m_fifo;
RefPtr<FIFO> m_fifo;
IntrusiveListNode<Inode> m_inode_list_node;
struct Flock {

View file

@ -14,9 +14,9 @@ class Inode;
class InodeFile final : public File {
public:
static ErrorOr<NonnullLockRefPtr<InodeFile>> create(NonnullRefPtr<Inode> inode)
static ErrorOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode> inode)
{
auto file = adopt_lock_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
if (!file)
return ENOMEM;
return file.release_nonnull();

View file

@ -11,9 +11,9 @@
namespace Kernel {
ErrorOr<NonnullLockRefPtr<InodeWatcher>> InodeWatcher::try_create()
ErrorOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::try_create()
{
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) InodeWatcher);
return adopt_nonnull_ref_or_enomem(new (nothrow) InodeWatcher);
}
InodeWatcher::~InodeWatcher()

View file

@ -40,7 +40,7 @@ private:
class InodeWatcher final : public File {
public:
static ErrorOr<NonnullLockRefPtr<InodeWatcher>> try_create();
static ErrorOr<NonnullRefPtr<InodeWatcher>> try_create();
virtual ~InodeWatcher() override;
virtual bool can_read(OpenFileDescription const&, u64) const override;

View file

@ -141,7 +141,7 @@ private:
}
RefPtr<Inode> m_inode;
NonnullLockRefPtr<File> m_file;
NonnullRefPtr<File> m_file;
struct State {
OwnPtr<OpenFileDescriptionData> data;