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
1 changed files with 9 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue