Kernel: Remove FIFO::{attach,detach}(Direction)

These functions would have caused a `-Woverloaded-virtual` warning with
GCC 13, as they shadow `File::{attach,detach}(OpenFileDescription&)`.

Both of these functions had a single call site. This commit inlines
`attach` into its only caller, `FIFO::open_direction`.

Instead of explicitly checking `is_fifo()` in `~OpenFileDescription`
before running the `detach(Direction)` overload, let's just override the
regular `detach(OpenFileDescription&)` for `FIFO` to perform this action
instead.
This commit is contained in:
Daniel Bertalan 2023-05-11 11:02:37 +02:00 committed by Andreas Kling
parent f666989c9e
commit 2123fdd678
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
3 changed files with 10 additions and 20 deletions

View file

@ -25,7 +25,12 @@ ErrorOr<NonnullRefPtr<FIFO>> FIFO::try_create(UserID uid)
ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction) ErrorOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
{ {
auto description = TRY(OpenFileDescription::try_create(*this)); auto description = TRY(OpenFileDescription::try_create(*this));
attach(direction); if (direction == Direction::Reader) {
++m_readers;
} else if (direction == Direction::Writer) {
++m_writers;
}
evaluate_block_conditions();
description->set_fifo_direction({}, direction); description->set_fifo_direction({}, direction);
return description; return description;
} }
@ -73,19 +78,11 @@ FIFO::FIFO(UserID uid, NonnullOwnPtr<DoubleBuffer> buffer)
FIFO::~FIFO() = default; FIFO::~FIFO() = default;
void FIFO::attach(Direction direction) void FIFO::detach(OpenFileDescription& description)
{ {
if (direction == Direction::Reader) { File::detach(description);
++m_readers;
} else if (direction == Direction::Writer) {
++m_writers;
}
evaluate_block_conditions(); auto direction = description.fifo_direction();
}
void FIFO::detach(Direction direction)
{
if (direction == Direction::Reader) { if (direction == Direction::Reader) {
VERIFY(m_readers); VERIFY(m_readers);
--m_readers; --m_readers;

View file

@ -32,17 +32,12 @@ public:
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction(Direction); ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction(Direction);
ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction_blocking(Direction); ErrorOr<NonnullRefPtr<OpenFileDescription>> open_direction_blocking(Direction);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
void attach(Direction);
void detach(Direction);
#pragma GCC diagnostic pop
private: private:
// ^File // ^File
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override; virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<struct stat> stat() const override; virtual ErrorOr<struct stat> stat() const override;
virtual void detach(OpenFileDescription&) override;
virtual bool can_read(OpenFileDescription const&, u64) const override; virtual bool can_read(OpenFileDescription const&, u64) const override;
virtual bool can_write(OpenFileDescription const&, u64) const override; virtual bool can_write(OpenFileDescription const&, u64) const override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override; virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;

View file

@ -53,8 +53,6 @@ OpenFileDescription::OpenFileDescription(File& file)
OpenFileDescription::~OpenFileDescription() OpenFileDescription::~OpenFileDescription()
{ {
m_file->detach(*this); m_file->detach(*this);
if (is_fifo())
static_cast<FIFO*>(m_file.ptr())->detach(fifo_direction());
// FIXME: Should this error path be observed somehow? // FIXME: Should this error path be observed somehow?
(void)m_file->close(); (void)m_file->close();
if (m_inode) if (m_inode)