Kernel: Migrate local socket table locking to ProtectedValue
This commit is contained in:
parent
6d83b2d8f0
commit
edd6c04024
Notes:
sideshowbarker
2024-07-18 07:20:22 +09:00
Author: https://github.com/boricj Commit: https://github.com/SerenityOS/serenity/commit/edd6c040249 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 12 additions and 12 deletions
|
@ -9,8 +9,8 @@
|
|||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Locking/Lockable.h>
|
||||
#include <Kernel/Locking/Mutex.h>
|
||||
#include <Kernel/Locking/ProtectedValue.h>
|
||||
#include <Kernel/Net/LocalSocket.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/StdLib.h>
|
||||
|
@ -19,18 +19,18 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static AK::Singleton<Lockable<LocalSocket::List>> s_list;
|
||||
static AK::Singleton<ProtectedValue<LocalSocket::List>> s_list;
|
||||
|
||||
static Lockable<LocalSocket::List>& all_sockets()
|
||||
static ProtectedValue<LocalSocket::List>& all_sockets()
|
||||
{
|
||||
return *s_list;
|
||||
}
|
||||
|
||||
void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
|
||||
{
|
||||
MutexLocker locker(all_sockets().lock(), Mutex::Mode::Shared);
|
||||
for (auto& socket : all_sockets().resource())
|
||||
all_sockets().for_each_shared([&](const auto& socket) {
|
||||
callback(socket);
|
||||
});
|
||||
}
|
||||
|
||||
KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
|
||||
|
@ -80,11 +80,6 @@ LocalSocket::LocalSocket(int type, NonnullOwnPtr<DoubleBuffer> client_buffer, No
|
|||
, m_for_client(move(client_buffer))
|
||||
, m_for_server(move(server_buffer))
|
||||
{
|
||||
{
|
||||
MutexLocker locker(all_sockets().lock());
|
||||
all_sockets().resource().append(*this);
|
||||
}
|
||||
|
||||
auto current_process = Process::current();
|
||||
m_prebind_uid = current_process->euid();
|
||||
m_prebind_gid = current_process->egid();
|
||||
|
@ -97,13 +92,18 @@ LocalSocket::LocalSocket(int type, NonnullOwnPtr<DoubleBuffer> client_buffer, No
|
|||
evaluate_block_conditions();
|
||||
});
|
||||
|
||||
all_sockets().with_exclusive([&](auto& list) {
|
||||
list.append(*this);
|
||||
});
|
||||
|
||||
dbgln_if(LOCAL_SOCKET_DEBUG, "LocalSocket({}) created with type={}", this, type);
|
||||
}
|
||||
|
||||
LocalSocket::~LocalSocket()
|
||||
{
|
||||
MutexLocker locker(all_sockets().lock());
|
||||
all_sockets().resource().remove(*this);
|
||||
all_sockets().with_exclusive([&](auto& list) {
|
||||
list.remove(*this);
|
||||
});
|
||||
}
|
||||
|
||||
void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
|
||||
|
|
Loading…
Add table
Reference in a new issue