mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:47:34 +00:00
Kernel: Protect PTYMultiplexer freelist with spinlock instead of mutex
This commit is contained in:
parent
6fbb924bbf
commit
0899153170
2 changed files with 4 additions and 5 deletions
|
@ -24,7 +24,7 @@ PTYMultiplexer& PTYMultiplexer::the()
|
||||||
UNMAP_AFTER_INIT PTYMultiplexer::PTYMultiplexer()
|
UNMAP_AFTER_INIT PTYMultiplexer::PTYMultiplexer()
|
||||||
: CharacterDevice(5, 2)
|
: CharacterDevice(5, 2)
|
||||||
{
|
{
|
||||||
m_freelist.with_exclusive([&](auto& freelist) {
|
m_freelist.with([&](auto& freelist) {
|
||||||
freelist.ensure_capacity(max_pty_pairs);
|
freelist.ensure_capacity(max_pty_pairs);
|
||||||
for (int i = max_pty_pairs; i > 0; --i)
|
for (int i = max_pty_pairs; i > 0; --i)
|
||||||
freelist.unchecked_append(i - 1);
|
freelist.unchecked_append(i - 1);
|
||||||
|
@ -42,7 +42,7 @@ UNMAP_AFTER_INIT void PTYMultiplexer::initialize()
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
ErrorOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||||
{
|
{
|
||||||
return m_freelist.with_exclusive([&](auto& freelist) -> ErrorOr<NonnullRefPtr<OpenFileDescription>> {
|
return m_freelist.with([&](auto& freelist) -> ErrorOr<NonnullRefPtr<OpenFileDescription>> {
|
||||||
if (freelist.is_empty())
|
if (freelist.is_empty())
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ ErrorOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||||
|
|
||||||
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
|
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
|
||||||
{
|
{
|
||||||
m_freelist.with_exclusive([&](auto& freelist) {
|
m_freelist.with([&](auto& freelist) {
|
||||||
freelist.append(index);
|
freelist.append(index);
|
||||||
dbgln_if(PTMX_DEBUG, "PTYMultiplexer: {} added to freelist", index);
|
dbgln_if(PTMX_DEBUG, "PTYMultiplexer: {} added to freelist", index);
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include <AK/Badge.h>
|
#include <AK/Badge.h>
|
||||||
#include <Kernel/Devices/CharacterDevice.h>
|
#include <Kernel/Devices/CharacterDevice.h>
|
||||||
#include <Kernel/Locking/Mutex.h>
|
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ private:
|
||||||
virtual StringView class_name() const override { return "PTYMultiplexer"sv; }
|
virtual StringView class_name() const override { return "PTYMultiplexer"sv; }
|
||||||
|
|
||||||
static constexpr size_t max_pty_pairs = 64;
|
static constexpr size_t max_pty_pairs = 64;
|
||||||
MutexProtected<Vector<unsigned, max_pty_pairs>> m_freelist;
|
SpinlockProtected<Vector<unsigned, max_pty_pairs>> m_freelist;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue