Kernel: Use the AK SetOnce container class in various cases

We have many places in the kernel code that we have boolean flags that
are only set once, and never reset again but are checked multiple times
before and after the time they're being set, which matches the purpose
of the SetOnce class.
This commit is contained in:
Liav A.
2024-04-22 13:30:09 +03:00
committed by Andrew Kaster
parent 122c82a2a1
commit 2bba9411ca
41 changed files with 135 additions and 111 deletions

View File

@@ -97,19 +97,19 @@ void IPv4Socket::get_peer_address(sockaddr* address, socklen_t* address_size)
ErrorOr<void> IPv4Socket::ensure_bound()
{
dbgln_if(IPV4_SOCKET_DEBUG, "IPv4Socket::ensure_bound() m_bound {}", m_bound);
if (m_bound)
dbgln_if(IPV4_SOCKET_DEBUG, "IPv4Socket::ensure_bound() m_bound {}", m_bound.was_set());
if (m_bound.was_set())
return {};
auto result = protocol_bind();
if (!result.is_error())
m_bound = true;
m_bound.set();
return result;
}
ErrorOr<void> IPv4Socket::bind(Credentials const& credentials, Userspace<sockaddr const*> user_address, socklen_t address_size)
{
if (m_bound)
if (m_bound.was_set())
return set_so_error(EINVAL);
VERIFY(setup_state() == SetupState::Unstarted);