Skip to content

Commit

Permalink
Kernel: Rename Socket::lock() => Socket::mutex()
Browse files Browse the repository at this point in the history
"lock" is ambiguous (verb vs noun) while "mutex" is not.
  • Loading branch information
awesomekling committed Aug 29, 2021
1 parent 0a7efb7 commit ed0e649
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Kernel/Net/IPv4Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ KResult IPv4Socket::bind(Userspace<const sockaddr*> user_address, socklen_t addr

KResult IPv4Socket::listen(size_t backlog)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
auto result = allocate_local_port_if_needed();
if (result.error_or_port.is_error() && result.error_or_port.error() != ENOPROTOOPT)
return result.error_or_port.error();
Expand Down Expand Up @@ -190,7 +190,7 @@ bool IPv4Socket::can_write(const FileDescription&, size_t) const

PortAllocationResult IPv4Socket::allocate_local_port_if_needed()
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
if (m_local_port)
return { m_local_port, false };
auto port_or_error = protocol_allocate_local_port();
Expand All @@ -202,7 +202,7 @@ PortAllocationResult IPv4Socket::allocate_local_port_if_needed()

KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& data, size_t data_length, [[maybe_unused]] int flags, Userspace<const sockaddr*> addr, socklen_t addr_length)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());

if (addr && addr_length != sizeof(sockaddr_in))
return set_so_error(EINVAL);
Expand Down Expand Up @@ -261,7 +261,7 @@ KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer&

KResultOr<size_t> IPv4Socket::receive_byte_buffered(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*>, Userspace<socklen_t*>)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
if (m_receive_buffer->is_empty()) {
if (protocol_is_disconnected())
return 0;
Expand Down Expand Up @@ -297,7 +297,7 @@ KResultOr<size_t> IPv4Socket::receive_byte_buffered(FileDescription& description

KResultOr<size_t> IPv4Socket::receive_packet_buffered(FileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> addr, Userspace<socklen_t*> addr_length, Time& packet_timestamp)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
ReceivedPacket packet;
{
if (m_receive_queue.is_empty()) {
Expand Down Expand Up @@ -412,7 +412,7 @@ KResultOr<size_t> IPv4Socket::recvfrom(FileDescription& description, UserOrKerne

bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, ReadonlyBytes packet, const Time& packet_timestamp)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());

if (is_shut_down_for_reading())
return false;
Expand Down
6 changes: 3 additions & 3 deletions Kernel/Net/LocalSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace<const socka

KResult LocalSocket::listen(size_t backlog)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
if (type() != SOCK_STREAM)
return set_so_error(EOPNOTSUPP);
set_backlog(backlog);
Expand Down Expand Up @@ -505,7 +505,7 @@ NonnullRefPtrVector<FileDescription>& LocalSocket::sendfd_queue_for(const FileDe

KResult LocalSocket::sendfd(const FileDescription& socket_description, FileDescription& passing_description)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
auto role = this->role(socket_description);
if (role != Role::Connected && role != Role::Accepted)
return set_so_error(EINVAL);
Expand All @@ -520,7 +520,7 @@ KResult LocalSocket::sendfd(const FileDescription& socket_description, FileDescr

KResultOr<NonnullRefPtr<FileDescription>> LocalSocket::recvfd(const FileDescription& socket_description)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
auto role = this->role(socket_description);
if (role != Role::Connected && role != Role::Accepted)
return set_so_error(EINVAL);
Expand Down
10 changes: 5 additions & 5 deletions Kernel/Net/NetworkTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void handle_udp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)

void send_delayed_tcp_ack(RefPtr<TCPSocket> socket)
{
VERIFY(socket->lock().is_locked());
VERIFY(socket->mutex().is_locked());
if (!socket->should_delay_next_ack()) {
[[maybe_unused]] auto result = socket->send_ack();
return;
Expand All @@ -311,7 +311,7 @@ void flush_delayed_tcp_acks()
{
Vector<RefPtr<TCPSocket>, 32> remaining_sockets;
for (auto& socket : *delayed_ack_sockets) {
MutexLocker locker(socket->lock());
MutexLocker locker(socket->mutex());
if (socket->should_delay_next_ack()) {
remaining_sockets.append(socket);
continue;
Expand Down Expand Up @@ -418,7 +418,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
return;
}

MutexLocker locker(socket->lock());
MutexLocker locker(socket->mutex());

VERIFY(socket->type() == SOCK_STREAM);
VERIFY(socket->local_port() == tcp_packet.destination_port());
Expand Down Expand Up @@ -448,7 +448,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp)
dmesgln("handle_tcp: couldn't create client socket");
return;
}
MutexLocker locker(client->lock());
MutexLocker locker(client->mutex());
dbgln_if(TCP_DEBUG, "handle_tcp: created new client socket with tuple {}", client->tuple().to_string());
client->set_sequence_number(1000);
client->set_ack_number(tcp_packet.sequence_number() + payload_size + 1);
Expand Down Expand Up @@ -648,7 +648,7 @@ void retransmit_tcp_packets()
});

for (auto& socket : sockets) {
MutexLocker socket_locker(socket.lock());
MutexLocker socket_locker(socket.mutex());
socket.retransmit_packets();
}
}
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Net/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Socket::set_setup_state(SetupState new_setup_state)

RefPtr<Socket> Socket::accept()
{
MutexLocker locker(m_lock);
MutexLocker locker(mutex());
if (m_pending.is_empty())
return nullptr;
dbgln_if(SOCKET_DEBUG, "Socket({}) de-queueing connection", this);
Expand All @@ -72,7 +72,7 @@ RefPtr<Socket> Socket::accept()
KResult Socket::queue_connection_from(NonnullRefPtr<Socket> peer)
{
dbgln_if(SOCKET_DEBUG, "Socket({}) queueing connection", this);
MutexLocker locker(m_lock);
MutexLocker locker(mutex());
if (m_pending.size() >= m_backlog)
return set_so_error(ECONNREFUSED);
if (!m_pending.try_append(peer))
Expand Down Expand Up @@ -243,7 +243,7 @@ KResultOr<size_t> Socket::write(FileDescription& description, u64, const UserOrK

KResult Socket::shutdown(int how)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
if (type() == SOCK_STREAM && !is_connected())
return set_so_error(ENOTCONN);
if (m_role == Role::Listener)
Expand All @@ -266,7 +266,7 @@ KResult Socket::stat(::stat& st) const

void Socket::set_connected(bool connected)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());
if (m_connected == connected)
return;
m_connected = connected;
Expand Down
8 changes: 4 additions & 4 deletions Kernel/Net/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Socket : public File {
GroupID acceptor_gid() const { return m_acceptor.gid; }
const RefPtr<NetworkAdapter> bound_interface() const { return m_bound_interface; }

Mutex& lock() { return m_lock; }
Mutex& mutex() { return m_mutex; }

// ^File
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override final;
Expand Down Expand Up @@ -149,7 +149,7 @@ class Socket : public File {
private:
virtual bool is_socket() const final { return true; }

Mutex m_lock { "Socket" };
Mutex m_mutex { "Socket"sv };

int m_domain { 0 };
int m_type { 0 };
Expand Down Expand Up @@ -180,7 +180,7 @@ class SocketHandle {
: m_socket(move(socket))
{
if (m_socket)
m_socket->lock().lock();
m_socket->mutex().lock();
}

SocketHandle(SocketHandle&& other)
Expand All @@ -191,7 +191,7 @@ class SocketHandle {
~SocketHandle()
{
if (m_socket)
m_socket->lock().unlock();
m_socket->mutex().unlock();
}

SocketHandle(const SocketHandle&) = delete;
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Net/TCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ KResult TCPSocket::protocol_listen(bool did_allocate_port)

KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock should_block)
{
MutexLocker locker(lock());
MutexLocker locker(mutex());

auto routing_decision = route_to(peer_address(), local_address());
if (routing_decision.is_zero())
Expand Down Expand Up @@ -497,7 +497,7 @@ void TCPSocket::shut_down_for_writing()

KResult TCPSocket::close()
{
MutexLocker socket_locker(lock());
MutexLocker locker(mutex());
auto result = IPv4Socket::close();
if (state() == State::CloseWait) {
dbgln_if(TCP_SOCKET_DEBUG, " Sending FIN from CloseWait and moving into LastAck");
Expand Down

0 comments on commit ed0e649

Please sign in to comment.