mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
Kernel: Port PTYMultiplexer to ProtectedValue
This commit is contained in:
parent
7f2791f02e
commit
4c582b57e9
2 changed files with 27 additions and 24 deletions
|
@ -24,9 +24,11 @@ PTYMultiplexer& PTYMultiplexer::the()
|
|||
UNMAP_AFTER_INIT PTYMultiplexer::PTYMultiplexer()
|
||||
: CharacterDevice(5, 2)
|
||||
{
|
||||
m_freelist.ensure_capacity(max_pty_pairs);
|
||||
for (int i = max_pty_pairs; i > 0; --i)
|
||||
m_freelist.unchecked_append(i - 1);
|
||||
m_freelist.with_exclusive([&](auto& freelist) {
|
||||
freelist.ensure_capacity(max_pty_pairs);
|
||||
for (int i = max_pty_pairs; i > 0; --i)
|
||||
freelist.unchecked_append(i - 1);
|
||||
});
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT PTYMultiplexer::~PTYMultiplexer()
|
||||
|
@ -35,27 +37,30 @@ UNMAP_AFTER_INIT PTYMultiplexer::~PTYMultiplexer()
|
|||
|
||||
KResultOr<NonnullRefPtr<FileDescription>> PTYMultiplexer::open(int options)
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
if (m_freelist.is_empty())
|
||||
return EBUSY;
|
||||
auto master_index = m_freelist.take_last();
|
||||
auto master = MasterPTY::try_create(master_index);
|
||||
if (!master)
|
||||
return ENOMEM;
|
||||
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
|
||||
auto description = FileDescription::create(*master);
|
||||
if (!description.is_error()) {
|
||||
description.value()->set_rw_mode(options);
|
||||
description.value()->set_file_flags(options);
|
||||
}
|
||||
return description;
|
||||
return m_freelist.with_exclusive([&](auto& freelist) -> KResultOr<NonnullRefPtr<FileDescription>> {
|
||||
if (freelist.is_empty())
|
||||
return EBUSY;
|
||||
|
||||
auto master_index = freelist.take_last();
|
||||
auto master = MasterPTY::try_create(master_index);
|
||||
if (!master)
|
||||
return ENOMEM;
|
||||
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
|
||||
auto description = FileDescription::create(*master);
|
||||
if (!description.is_error()) {
|
||||
description.value()->set_rw_mode(options);
|
||||
description.value()->set_file_flags(options);
|
||||
}
|
||||
return description;
|
||||
});
|
||||
}
|
||||
|
||||
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
m_freelist.append(index);
|
||||
dbgln_if(PTMX_DEBUG, "PTYMultiplexer: {} added to freelist", index);
|
||||
m_freelist.with_exclusive([&](auto& freelist) {
|
||||
freelist.append(index);
|
||||
dbgln_if(PTMX_DEBUG, "PTYMultiplexer: {} added to freelist", index);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue