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

Kernel: Consolidate timeout logic

Allow passing in an optional timeout to Thread::block and move
the timeout check out of Thread::Blocker. This way all Blockers
implicitly support timeouts and don't need to implement it
themselves. Do however allow them to override timeouts (e.g.
for sockets).
This commit is contained in:
Tom 2020-08-03 09:43:19 -06:00 committed by Andreas Kling
parent df52061cdb
commit f4a5c9b6c2
15 changed files with 60 additions and 77 deletions

View file

@ -246,7 +246,7 @@ ssize_t IPv4Socket::receive_byte_buffered(FileDescription& description, void* bu
return -EAGAIN;
locker.unlock();
auto res = Thread::current()->block<Thread::ReadBlocker>(description);
auto res = Thread::current()->block<Thread::ReadBlocker>(nullptr, description);
locker.lock();
if (!m_can_read) {
@ -296,7 +296,7 @@ ssize_t IPv4Socket::receive_packet_buffered(FileDescription& description, void*
}
locker.unlock();
auto res = Thread::current()->block<Thread::ReadBlocker>(description);
auto res = Thread::current()->block<Thread::ReadBlocker>(nullptr, description);
locker.lock();
if (!m_can_read) {

View file

@ -176,7 +176,7 @@ KResult LocalSocket::connect(FileDescription& description, const sockaddr* addre
return KSuccess;
}
if (Thread::current()->block<Thread::ConnectBlocker>(description).was_interrupted()) {
if (Thread::current()->block<Thread::ConnectBlocker>(nullptr, description).was_interrupted()) {
m_connect_side_role = Role::None;
return KResult(-EINTR);
}
@ -300,7 +300,7 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t
return -EAGAIN;
}
} else if (!can_read(description, 0)) {
if (Thread::current()->block<Thread::ReadBlocker>(description).was_interrupted())
if (Thread::current()->block<Thread::ReadBlocker>(nullptr, description).was_interrupted())
return -EINTR;
}
if (!has_attached_peer(description) && buffer_for_me.is_empty())

View file

@ -372,7 +372,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
m_direction = Direction::Outgoing;
if (should_block == ShouldBlock::Yes) {
if (Thread::current()->block<Thread::ConnectBlocker>(description).was_interrupted())
if (Thread::current()->block<Thread::ConnectBlocker>(nullptr, description).was_interrupted())
return KResult(-EINTR);
ASSERT(setup_state() == SetupState::Completed);
if (has_error()) {