mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
Kernel: Move TTY-related files into Kernel/TTY/.
This commit is contained in:
parent
f9864940eb
commit
9fca94269e
17 changed files with 16 additions and 16 deletions
51
Kernel/TTY/PTYMultiplexer.cpp
Normal file
51
Kernel/TTY/PTYMultiplexer.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "PTYMultiplexer.h"
|
||||
#include "MasterPTY.h"
|
||||
#include <Kernel/Process.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
//#define PTMX_DEBUG
|
||||
|
||||
static const unsigned s_max_pty_pairs = 8;
|
||||
static PTYMultiplexer* s_the;
|
||||
|
||||
PTYMultiplexer& PTYMultiplexer::the()
|
||||
{
|
||||
ASSERT(s_the);
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
PTYMultiplexer::PTYMultiplexer()
|
||||
: CharacterDevice(5, 2)
|
||||
, m_lock("PTYMultiplexer")
|
||||
{
|
||||
s_the = this;
|
||||
m_freelist.ensure_capacity(s_max_pty_pairs);
|
||||
for (int i = s_max_pty_pairs; i > 0; --i)
|
||||
m_freelist.unchecked_append(i - 1);
|
||||
}
|
||||
|
||||
PTYMultiplexer::~PTYMultiplexer()
|
||||
{
|
||||
}
|
||||
|
||||
KResultOr<Retained<FileDescriptor>> PTYMultiplexer::open(int options)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
if (m_freelist.is_empty())
|
||||
return KResult(-EBUSY);
|
||||
auto master_index = m_freelist.take_last();
|
||||
auto master = adopt(*new MasterPTY(master_index));
|
||||
#ifdef PTMX_DEBUG
|
||||
dbgprintf("PTYMultiplexer::open: Vending master %u\n", master->index());
|
||||
#endif
|
||||
return VFS::the().open(move(master), options);
|
||||
}
|
||||
|
||||
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
m_freelist.append(index);
|
||||
#ifdef PTMX_DEBUG
|
||||
dbgprintf("PTYMultiplexer: %u added to freelist\n", index);
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue