mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:58:13 +00:00
Kernel: Use KResultOr and TRY() for FIFO
This commit is contained in:
parent
631b8e90cd
commit
ed5d04b0ea
6 changed files with 10 additions and 18 deletions
|
@ -16,12 +16,10 @@ namespace Kernel {
|
|||
|
||||
static Atomic<int> s_next_fifo_id = 1;
|
||||
|
||||
RefPtr<FIFO> FIFO::try_create(UserID uid)
|
||||
KResultOr<NonnullRefPtr<FIFO>> FIFO::try_create(UserID uid)
|
||||
{
|
||||
auto buffer_or_error = DoubleBuffer::try_create();
|
||||
if (buffer_or_error.is_error())
|
||||
return {};
|
||||
return adopt_ref_if_nonnull(new (nothrow) FIFO(uid, buffer_or_error.release_value()));
|
||||
auto buffer = TRY(DoubleBuffer::try_create());
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer)));
|
||||
}
|
||||
|
||||
KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
Writer
|
||||
};
|
||||
|
||||
static RefPtr<FIFO> try_create(UserID);
|
||||
static KResultOr<NonnullRefPtr<FIFO>> try_create(UserID);
|
||||
virtual ~FIFO() override;
|
||||
|
||||
UserID uid() const { return m_uid; }
|
||||
|
|
|
@ -163,19 +163,15 @@ void Inode::unregister_watcher(Badge<InodeWatcher>, InodeWatcher& watcher)
|
|||
m_watchers.remove(&watcher);
|
||||
}
|
||||
|
||||
NonnullRefPtr<FIFO> Inode::fifo()
|
||||
KResultOr<NonnullRefPtr<FIFO>> Inode::fifo()
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
VERIFY(metadata().is_fifo());
|
||||
|
||||
// FIXME: Release m_fifo when it is closed by all readers and writers
|
||||
if (!m_fifo) {
|
||||
m_fifo = FIFO::try_create(metadata().uid);
|
||||
// FIXME: We need to be able to observe OOM here.
|
||||
VERIFY(!m_fifo.is_null());
|
||||
}
|
||||
if (!m_fifo)
|
||||
m_fifo = TRY(FIFO::try_create(metadata().uid));
|
||||
|
||||
VERIFY(m_fifo);
|
||||
return *m_fifo;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
void register_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
||||
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
|
||||
|
||||
NonnullRefPtr<FIFO> fifo();
|
||||
KResultOr<NonnullRefPtr<FIFO>> fifo();
|
||||
|
||||
KResult can_apply_flock(OpenFileDescription const&, flock const&) const;
|
||||
KResult apply_flock(Process const&, OpenFileDescription const&, Userspace<flock const*>);
|
||||
|
|
|
@ -250,7 +250,7 @@ KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(StringView
|
|||
return *preopen_fd;
|
||||
|
||||
if (metadata.is_fifo()) {
|
||||
auto fifo = inode.fifo();
|
||||
auto fifo = TRY(inode.fifo());
|
||||
if (options & O_WRONLY) {
|
||||
auto description = TRY(fifo->open_direction_blocking(FIFO::Direction::Writer));
|
||||
description->set_rw_mode(options);
|
||||
|
|
|
@ -20,9 +20,7 @@ KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags)
|
|||
return EINVAL;
|
||||
|
||||
u32 fd_flags = (flags & O_CLOEXEC) ? FD_CLOEXEC : 0;
|
||||
auto fifo = FIFO::try_create(uid());
|
||||
if (!fifo)
|
||||
return ENOMEM;
|
||||
auto fifo = TRY(FIFO::try_create(uid()));
|
||||
|
||||
auto reader_fd_allocation = TRY(m_fds.allocate());
|
||||
auto writer_fd_allocation = TRY(m_fds.allocate());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue