1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

Kernel: Migrate IPv4 socket table locking to ProtectedValue

This commit is contained in:
Jean-Baptiste Boric 2021-07-18 11:59:25 +02:00 committed by Andreas Kling
parent edd6c04024
commit 583abc27d8
4 changed files with 15 additions and 15 deletions

View file

@ -26,11 +26,11 @@
namespace Kernel {
static AK::Singleton<Lockable<HashTable<IPv4Socket*>>> s_table;
static AK::Singleton<ProtectedValue<HashTable<IPv4Socket*>>> s_table;
using BlockFlags = Thread::FileDescriptionBlocker::BlockFlags;
Lockable<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
ProtectedValue<HashTable<IPv4Socket*>>& IPv4Socket::all_sockets()
{
return *s_table;
}
@ -77,14 +77,17 @@ IPv4Socket::IPv4Socket(int type, int protocol, NonnullOwnPtr<DoubleBuffer> recei
if (m_buffer_mode == BufferMode::Bytes) {
VERIFY(m_scratch_buffer);
}
MutexLocker locker(all_sockets().lock());
all_sockets().resource().set(this);
all_sockets().with_exclusive([&](auto& table) {
table.set(this);
});
}
IPv4Socket::~IPv4Socket()
{
MutexLocker locker(all_sockets().lock());
all_sockets().resource().remove(this);
all_sockets().with_exclusive([&](auto& table) {
table.remove(this);
});
}
void IPv4Socket::get_local_address(sockaddr* address, socklen_t* address_size)