mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:47:34 +00:00
Kernel: Migrate FIFO table locking to ProtectedValue
This commit is contained in:
parent
25d7beec6b
commit
6d83b2d8f0
1 changed files with 9 additions and 7 deletions
|
@ -10,16 +10,16 @@
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <Kernel/FileSystem/FIFO.h>
|
#include <Kernel/FileSystem/FIFO.h>
|
||||||
#include <Kernel/FileSystem/FileDescription.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/Locking/Lockable.h>
|
|
||||||
#include <Kernel/Locking/Mutex.h>
|
#include <Kernel/Locking/Mutex.h>
|
||||||
|
#include <Kernel/Locking/ProtectedValue.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/Thread.h>
|
#include <Kernel/Thread.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
static AK::Singleton<Lockable<HashTable<FIFO*>>> s_table;
|
static AK::Singleton<ProtectedValue<HashTable<FIFO*>>> s_table;
|
||||||
|
|
||||||
static Lockable<HashTable<FIFO*>>& all_fifos()
|
static ProtectedValue<HashTable<FIFO*>>& all_fifos()
|
||||||
{
|
{
|
||||||
return *s_table;
|
return *s_table;
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,9 @@ FIFO::FIFO(uid_t uid, NonnullOwnPtr<DoubleBuffer> buffer)
|
||||||
: m_buffer(move(buffer))
|
: m_buffer(move(buffer))
|
||||||
, m_uid(uid)
|
, m_uid(uid)
|
||||||
{
|
{
|
||||||
MutexLocker locker(all_fifos().lock());
|
all_fifos().with_exclusive([&](auto& table) {
|
||||||
all_fifos().resource().set(this);
|
table.set(this);
|
||||||
|
});
|
||||||
m_fifo_id = ++s_next_fifo_id;
|
m_fifo_id = ++s_next_fifo_id;
|
||||||
|
|
||||||
// Use the same block condition for read and write
|
// Use the same block condition for read and write
|
||||||
|
@ -91,8 +92,9 @@ FIFO::FIFO(uid_t uid, NonnullOwnPtr<DoubleBuffer> buffer)
|
||||||
|
|
||||||
FIFO::~FIFO()
|
FIFO::~FIFO()
|
||||||
{
|
{
|
||||||
MutexLocker locker(all_fifos().lock());
|
all_fifos().with_exclusive([&](auto& table) {
|
||||||
all_fifos().resource().remove(this);
|
table.remove(this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FIFO::attach(Direction direction)
|
void FIFO::attach(Direction direction)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue