diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-24 01:52:10 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-24 01:52:10 +0100 |
commit | 239c0bd6a6b52323fbf393fd084d97d4d4acfc1b (patch) | |
tree | 367492e66cab3a027c8af0c9b41565b87bdb95a3 /Kernel | |
parent | 5713c3a0cb804a71ab4ce0ccef1aad7915ed80f7 (diff) | |
download | serenity-239c0bd6a6b52323fbf393fd084d97d4d4acfc1b.zip |
Kernel: Make block() and yield() automatically call Scheduler::yield().
This exposed some places we were accidentally doing a double yield().
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/IPv4Socket.cpp | 3 | ||||
-rw-r--r-- | Kernel/Process.cpp | 17 | ||||
-rw-r--r-- | Kernel/TCPSocket.cpp | 3 | ||||
-rw-r--r-- | Kernel/Thread.cpp | 10 | ||||
-rw-r--r-- | Kernel/Thread.h | 3 | ||||
-rw-r--r-- | Kernel/init.cpp | 2 |
6 files changed, 10 insertions, 28 deletions
diff --git a/Kernel/IPv4Socket.cpp b/Kernel/IPv4Socket.cpp index 3d3ea4664b..5820cc0a31 100644 --- a/Kernel/IPv4Socket.cpp +++ b/Kernel/IPv4Socket.cpp @@ -189,8 +189,7 @@ ssize_t IPv4Socket::recvfrom(void* buffer, size_t buffer_length, int flags, sock current->set_blocked_socket(this); load_receive_deadline(); - block(Thread::BlockedReceive); - Scheduler::yield(); + current->block(Thread::BlockedReceive); LOCKER(lock()); if (!m_can_read) { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 67bfa24abb..9cbe0fc673 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -840,7 +840,6 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size) #endif current->m_blocked_fd = fd; current->block(Thread::State::BlockedWrite); - Scheduler::yield(); } ssize_t rc = descriptor->write(*this, (const byte*)data + nwritten, size - nwritten); #ifdef IO_DEBUG @@ -855,7 +854,6 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size) break; if (current->has_unmasked_pending_signals()) { current->block(Thread::State::BlockedSignal); - Scheduler::yield(); if (nwritten == 0) return -EINTR; } @@ -866,7 +864,6 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size) } if (current->has_unmasked_pending_signals()) { current->block(Thread::State::BlockedSignal); - Scheduler::yield(); if (nwritten == 0) return -EINTR; } @@ -889,7 +886,6 @@ ssize_t Process::sys$read(int fd, byte* buffer, ssize_t size) if (!descriptor->can_read(*this)) { current->m_blocked_fd = fd; current->block(Thread::State::BlockedRead); - Scheduler::yield(); if (current->m_was_interrupted_while_blocked) return -EINTR; } @@ -1218,7 +1214,7 @@ int Process::sys$usleep(useconds_t usec) if (!usec) return 0; - sleep(usec / 1000); + current->sleep(usec / 1000); if (current->m_wakeup_time > system.uptime) { ASSERT(current->m_was_interrupted_while_blocked); dword ticks_left_until_original_wakeup_time = current->m_wakeup_time - system.uptime; @@ -1231,7 +1227,7 @@ int Process::sys$sleep(unsigned seconds) { if (!seconds) return 0; - sleep(seconds * TICKS_PER_SECOND); + current->sleep(seconds * TICKS_PER_SECOND); if (current->m_wakeup_time > system.uptime) { ASSERT(current->m_was_interrupted_while_blocked); dword ticks_left_until_original_wakeup_time = current->m_wakeup_time - system.uptime; @@ -1357,7 +1353,6 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) current->m_waitee_pid = waitee; current->block(Thread::State::BlockedWait); - Scheduler::yield(); if (current->m_was_interrupted_while_blocked) return -EINTR; Process* waitee_process; @@ -1758,10 +1753,8 @@ int Process::sys$select(const Syscall::SC_select_params* params) dbgprintf("%s<%u> selecting on (read:%u, write:%u), timeout=%p\n", name().characters(), pid(), current->m_select_read_fds.size(), current->m_select_write_fds.size(), timeout); #endif - if (!timeout || (timeout->tv_sec || timeout->tv_usec)) { + if (!timeout || (timeout->tv_sec || timeout->tv_usec)) current->block(Thread::State::BlockedSelect); - Scheduler::yield(); - } int markedfds = 0; @@ -1812,10 +1805,8 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout) current->m_select_write_fds.append(fds[i].fd); } - if (timeout < 0) { + if (timeout < 0) current->block(Thread::State::BlockedSelect); - Scheduler::yield(); - } int fds_with_revents = 0; diff --git a/Kernel/TCPSocket.cpp b/Kernel/TCPSocket.cpp index 2f7f759914..f7eddb3b0b 100644 --- a/Kernel/TCPSocket.cpp +++ b/Kernel/TCPSocket.cpp @@ -167,8 +167,7 @@ KResult TCPSocket::protocol_connect() m_state = State::Connecting; current->set_blocked_socket(this); - block(Thread::BlockedConnect); - Scheduler::yield(); + current->block(Thread::BlockedConnect); ASSERT(is_connected()); return KSuccess; diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 0f2277380e..ef1a6ec5af 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -118,20 +118,14 @@ void Thread::block(Thread::State new_state) system.nblocked++; m_was_interrupted_while_blocked = false; set_state(new_state); -} - -void block(Thread::State state) -{ - current->block(state); Scheduler::yield(); } -void sleep(dword ticks) +void Thread::sleep(dword ticks) { - ASSERT(current->state() == Thread::Running); + ASSERT(state() == Thread::Running); current->set_wakeup_time(system.uptime + ticks); current->block(Thread::BlockedSleep); - Scheduler::yield(); } const char* to_string(Thread::State state) diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 8899c256d8..abfb99251e 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -83,6 +83,7 @@ public: dword ticks() const { return m_ticks; } pid_t waitee_pid() const { return m_waitee_pid; } + void sleep(dword ticks); void block(Thread::State); void unblock(); @@ -167,8 +168,6 @@ private: extern InlineLinkedList<Thread>* g_threads; const char* to_string(Thread::State); -void block(Thread::State); -void sleep(dword ticks); template<typename Callback> inline void Thread::for_each_in_state(State state, Callback callback) diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 6fc8797bf3..09ae0b49b9 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -184,7 +184,7 @@ VFS* vfs; Process::create_kernel_process("syncd", [] { for (;;) { Syscall::sync(); - sleep(1 * TICKS_PER_SECOND); + current->sleep(1 * TICKS_PER_SECOND); } }); Process::create_kernel_process("Finalizer", [] { |