Kernel: Migrate FIFO table locking to ProtectedValue

This commit is contained in:
Jean-Baptiste Boric 2021-07-18 11:47:09 +02:00 committed by Andreas Kling
parent 25d7beec6b
commit 6d83b2d8f0
Notes: sideshowbarker 2024-07-18 07:20:26 +09:00

View File

@ -10,16 +10,16 @@
#include <AK/StdLibExtras.h>
#include <Kernel/FileSystem/FIFO.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/Locking/Lockable.h>
#include <Kernel/Locking/Mutex.h>
#include <Kernel/Locking/ProtectedValue.h>
#include <Kernel/Process.h>
#include <Kernel/Thread.h>
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;
}
@ -79,8 +79,9 @@ FIFO::FIFO(uid_t uid, NonnullOwnPtr<DoubleBuffer> buffer)
: m_buffer(move(buffer))
, m_uid(uid)
{
MutexLocker locker(all_fifos().lock());
all_fifos().resource().set(this);
all_fifos().with_exclusive([&](auto& table) {
table.set(this);
});
m_fifo_id = ++s_next_fifo_id;
// Use the same block condition for read and write
@ -91,8 +92,9 @@ FIFO::FIFO(uid_t uid, NonnullOwnPtr<DoubleBuffer> buffer)
FIFO::~FIFO()
{
MutexLocker locker(all_fifos().lock());
all_fifos().resource().remove(this);
all_fifos().with_exclusive([&](auto& table) {
table.remove(this);
});
}
void FIFO::attach(Direction direction)