mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
Kernel: Migrate FIFO table locking to ProtectedValue
This commit is contained in:
parent
25d7beec6b
commit
6d83b2d8f0
Notes:
sideshowbarker
2024-07-18 07:20:26 +09:00
Author: https://github.com/boricj Commit: https://github.com/SerenityOS/serenity/commit/6d83b2d8f0a Pull-request: https://github.com/SerenityOS/serenity/pull/8851 Reviewed-by: https://github.com/awesomekling ✅ Reviewed-by: https://github.com/bgianfo
@ -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…
Reference in New Issue
Block a user