mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +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:
parent
df52061cdb
commit
f4a5c9b6c2
15 changed files with 60 additions and 77 deletions
|
@ -113,7 +113,7 @@ KResult Process::do_killself(int signal)
|
|||
auto current_thread = Thread::current();
|
||||
if (!current_thread->should_ignore_signal(signal)) {
|
||||
current_thread->send_signal(signal, this);
|
||||
(void)current_thread->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal);
|
||||
(void)current_thread->block<Thread::SemiPermanentBlocker>(nullptr, Thread::SemiPermanentBlocker::Reason::Signal);
|
||||
}
|
||||
|
||||
return KSuccess;
|
||||
|
|
|
@ -50,7 +50,7 @@ ssize_t Process::sys$read(int fd, Userspace<u8*> buffer, ssize_t size)
|
|||
return -EISDIR;
|
||||
if (description->is_blocking()) {
|
||||
if (!description->can_read()) {
|
||||
if (Thread::current()->block<Thread::ReadBlocker>(*description).was_interrupted())
|
||||
if (Thread::current()->block<Thread::ReadBlocker>(nullptr, *description).was_interrupted())
|
||||
return -EINTR;
|
||||
if (!description->can_read())
|
||||
return -EAGAIN;
|
||||
|
|
|
@ -105,7 +105,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
|||
#endif
|
||||
|
||||
if (!timeout || select_has_timeout) {
|
||||
if (current_thread->block<Thread::SelectBlocker>(computed_timeout, select_has_timeout, rfds, wfds, efds).was_interrupted())
|
||||
if (current_thread->block<Thread::SelectBlocker>(select_has_timeout ? &computed_timeout : nullptr, rfds, wfds, efds).was_interrupted())
|
||||
return -EINTR;
|
||||
// While we blocked, the process lock was dropped. This gave other threads
|
||||
// the opportunity to mess with the memory. For example, it could free the
|
||||
|
@ -191,7 +191,7 @@ int Process::sys$poll(const Syscall::SC_poll_params* params)
|
|||
#endif
|
||||
|
||||
if (!timeout || has_timeout) {
|
||||
if (current_thread->block<Thread::SelectBlocker>(actual_timeout, has_timeout, rfds, wfds, Thread::SelectBlocker::FDVector()).was_interrupted())
|
||||
if (current_thread->block<Thread::SelectBlocker>(has_timeout ? &actual_timeout : nullptr, rfds, wfds, Thread::SelectBlocker::FDVector()).was_interrupted())
|
||||
return -EINTR;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* user_address, socklen
|
|||
|
||||
if (!socket.can_accept()) {
|
||||
if (accepting_socket_description->is_blocking()) {
|
||||
if (Thread::current()->block<Thread::AcceptBlocker>(*accepting_socket_description).was_interrupted())
|
||||
if (Thread::current()->block<Thread::AcceptBlocker>(nullptr, *accepting_socket_description).was_interrupted())
|
||||
return -EINTR;
|
||||
} else {
|
||||
return -EAGAIN;
|
||||
|
|
|
@ -146,7 +146,7 @@ int Process::sys$join_thread(int tid, void** exit_value)
|
|||
|
||||
// NOTE: pthread_join() cannot be interrupted by signals. Only by death.
|
||||
for (;;) {
|
||||
auto result = current_thread->block<Thread::JoinBlocker>(*thread, joinee_exit_value);
|
||||
auto result = current_thread->block<Thread::JoinBlocker>(nullptr, *thread, joinee_exit_value);
|
||||
if (result == Thread::BlockResult::InterruptedByDeath) {
|
||||
// NOTE: This cleans things up so that Thread::finalize() won't
|
||||
// get confused about a missing joiner when finalizing the joinee.
|
||||
|
|
|
@ -48,7 +48,7 @@ KResultOr<siginfo_t> Process::do_waitid(idtype_t idtype, int id, int options)
|
|||
return KResult(-EINVAL);
|
||||
}
|
||||
|
||||
if (Thread::current()->block<Thread::WaitBlocker>(options, waitee_pid).was_interrupted())
|
||||
if (Thread::current()->block<Thread::WaitBlocker>(nullptr, options, waitee_pid).was_interrupted())
|
||||
return KResult(-EINTR);
|
||||
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
|
|
|
@ -100,7 +100,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data
|
|||
#ifdef IO_DEBUG
|
||||
dbg() << "block write on " << description.absolute_path();
|
||||
#endif
|
||||
if (Thread::current()->block<Thread::WriteBlocker>(description).was_interrupted()) {
|
||||
if (Thread::current()->block<Thread::WriteBlocker>(nullptr, description).was_interrupted()) {
|
||||
if (nwritten == 0)
|
||||
return -EINTR;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue