1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:27:35 +00:00

Kernel: Use shared locking mode in some places

The notable piece of code that remains to be converted is Ext2FS.
This commit is contained in:
Sergey Bugaev 2020-04-18 12:50:35 +03:00 committed by Andreas Kling
parent 05ba4295e9
commit 54550365eb
11 changed files with 26 additions and 26 deletions

View file

@ -45,9 +45,9 @@ Lockable<InlineLinkedList<LocalSocket>>& LocalSocket::all_sockets()
return *s_list;
}
void LocalSocket::for_each(Function<void(LocalSocket&)> callback)
void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
{
LOCKER(all_sockets().lock());
LOCKER(all_sockets().lock(), Lock::Mode::Shared);
for (auto& socket : all_sockets().resource())
callback(socket);
}

View file

@ -42,7 +42,7 @@ public:
static KResultOr<NonnullRefPtr<Socket>> create(int type);
virtual ~LocalSocket() override;
static void for_each(Function<void(LocalSocket&)>);
static void for_each(Function<void(const LocalSocket&)>);
StringView socket_path() const;
String absolute_path(const FileDescription& description) const override;

View file

@ -38,9 +38,9 @@
namespace Kernel {
void TCPSocket::for_each(Function<void(TCPSocket&)> callback)
void TCPSocket::for_each(Function<void(const TCPSocket&)> callback)
{
LOCKER(sockets_by_tuple().lock());
LOCKER(sockets_by_tuple().lock(), Lock::Mode::Shared);
for (auto& it : sockets_by_tuple().resource())
callback(*it.value);
}
@ -80,7 +80,7 @@ Lockable<HashMap<IPv4SocketTuple, TCPSocket*>>& TCPSocket::sockets_by_tuple()
RefPtr<TCPSocket> TCPSocket::from_tuple(const IPv4SocketTuple& tuple)
{
LOCKER(sockets_by_tuple().lock());
LOCKER(sockets_by_tuple().lock(), Lock::Mode::Shared);
auto exact_match = sockets_by_tuple().resource().get(tuple);
if (exact_match.has_value())
@ -230,7 +230,7 @@ void TCPSocket::send_outgoing_packets()
auto now = kgettimeofday();
LOCKER(m_not_acked_lock);
LOCKER(m_not_acked_lock, Lock::Mode::Shared);
for (auto& packet : m_not_acked) {
timeval diff;
timeval_sub(packet.tx_time, now, diff);

View file

@ -37,7 +37,7 @@ namespace Kernel {
class TCPSocket final : public IPv4Socket
, public Weakable<TCPSocket> {
public:
static void for_each(Function<void(TCPSocket&)>);
static void for_each(Function<void(const TCPSocket&)>);
static NonnullRefPtr<TCPSocket> create(int protocol);
virtual ~TCPSocket() override;

View file

@ -34,9 +34,9 @@
namespace Kernel {
void UDPSocket::for_each(Function<void(UDPSocket&)> callback)
void UDPSocket::for_each(Function<void(const UDPSocket&)> callback)
{
LOCKER(sockets_by_port().lock());
LOCKER(sockets_by_port().lock(), Lock::Mode::Shared);
for (auto it : sockets_by_port().resource())
callback(*it.value);
}
@ -53,7 +53,7 @@ SocketHandle<UDPSocket> UDPSocket::from_port(u16 port)
{
RefPtr<UDPSocket> socket;
{
LOCKER(sockets_by_port().lock());
LOCKER(sockets_by_port().lock(), Lock::Mode::Shared);
auto it = sockets_by_port().resource().find(port);
if (it == sockets_by_port().resource().end())
return {};

View file

@ -36,7 +36,7 @@ public:
virtual ~UDPSocket() override;
static SocketHandle<UDPSocket> from_port(u16);
static void for_each(Function<void(UDPSocket&)>);
static void for_each(Function<void(const UDPSocket&)>);
private:
explicit UDPSocket(int protocol);