ladybird/Kernel/TTY/SlavePTY.h
kleines Filmröllchen a6a439243f Kernel: Turn lock ranks into template parameters
This step would ideally not have been necessary (increases amount of
refactoring and templates necessary, which in turn increases build
times), but it gives us a couple of nice properties:
- SpinlockProtected inside Singleton (a very common combination) can now
  obtain any lock rank just via the template parameter. It was not
  previously possible to do this with SingletonInstanceCreator magic.
- SpinlockProtected's lock rank is now mandatory; this is the majority
  of cases and allows us to see where we're still missing proper ranks.
- The type already informs us what lock rank a lock has, which aids code
  readability and (possibly, if gdb cooperates) lock mismatch debugging.
- The rank of a lock can no longer be dynamic, which is not something we
  wanted in the first place (or made use of). Locks randomly changing
  their rank sounds like a disaster waiting to happen.
- In some places, we might be able to statically check that locks are
  taken in the right order (with the right lock rank checking
  implementation) as rank information is fully statically known.

This refactoring even more exposes the fact that Mutex has no lock rank
capabilites, which is not fixed here.
2023-01-02 18:15:27 -05:00

58 lines
1.6 KiB
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/FileSystem/InodeIdentifier.h>
#include <Kernel/TTY/TTY.h>
namespace Kernel {
class MasterPTY;
class SlavePTY final : public TTY {
public:
virtual bool unref() const override;
virtual ~SlavePTY() override;
void on_master_write(UserOrKernelBuffer const&, size_t);
unsigned index() const { return m_index; }
time_t time_of_last_write() const { return m_time_of_last_write; }
virtual FileBlockerSet& blocker_set() override;
private:
// ^Device
virtual bool is_openable_by_jailed_processes() const override { return true; }
// ^TTY
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_name() const override;
virtual ErrorOr<size_t> on_tty_write(UserOrKernelBuffer const&, size_t) override;
virtual void echo(u8) override;
// ^CharacterDevice
virtual bool can_read(OpenFileDescription const&, u64) const override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual bool can_write(OpenFileDescription const&, u64) const override;
virtual StringView class_name() const override { return "SlavePTY"sv; }
virtual ErrorOr<void> close() override;
friend class MasterPTY;
SlavePTY(MasterPTY&, unsigned index);
LockRefPtr<MasterPTY> m_master;
time_t m_time_of_last_write { 0 };
unsigned m_index { 0 };
mutable IntrusiveListNode<SlavePTY> m_list_node;
public:
using List = IntrusiveList<&SlavePTY::m_list_node>;
static SpinlockProtected<SlavePTY::List, LockRank::None>& all_instances();
};
}