diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 76eb82328f..474706b7a2 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -212,7 +212,7 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t } load_receive_deadline(); - current->block(*new Thread::ThreadBlockerReceive(description)); + current->block(*new Thread::ReceiveBlocker(description)); LOCKER(lock()); if (!m_can_read) { diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 4f6772491d..1e803e279a 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -162,7 +162,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh m_state = State::Connecting; if (should_block == ShouldBlock::Yes) { - current->block(*new Thread::ThreadBlockerConnect(description)); + current->block(*new Thread::ConnectBlocker(description)); ASSERT(is_connected()); return KSuccess; } diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 1244c73886..b2e2f7ebcc 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -900,7 +900,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data #ifdef IO_DEBUG dbgprintf("block write on %d\n", fd); #endif - current->block(*new Thread::ThreadBlockerWrite(description)); + current->block(*new Thread::WriteBlocker(description)); } ssize_t rc = description.write(data + nwritten, data_size - nwritten); #ifdef IO_DEBUG @@ -962,7 +962,7 @@ ssize_t Process::sys$read(int fd, u8* buffer, ssize_t size) return -EBADF; if (description->is_blocking()) { if (!description->can_read()) { - current->block(*new Thread::ThreadBlockerRead(*description)); + current->block(*new Thread::ReadBlocker(*description)); if (current->m_was_interrupted_while_blocked) return -EINTR; } @@ -1442,7 +1442,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) } pid_t waitee_pid = waitee; - current->block(*new Thread::ThreadBlockerWait(options, waitee_pid)); + current->block(*new Thread::WaitBlocker(options, waitee_pid)); if (current->m_was_interrupted_while_blocked) return -EINTR; @@ -1827,7 +1827,7 @@ int Process::sys$select(const Syscall::SC_select_params* params) #endif if (!params->timeout || select_has_timeout) - current->block(*new Thread::ThreadBlockerSelect(timeout, select_has_timeout, rfds, wfds, efds)); + current->block(*new Thread::SelectBlocker(timeout, select_has_timeout, rfds, wfds, efds)); int marked_fd_count = 0; auto mark_fds = [&](auto* fds, auto& vector, auto should_mark) { @@ -1882,7 +1882,7 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout) #endif if (has_timeout|| timeout < 0) - current->block(*new Thread::ThreadBlockerSelect(actual_timeout, has_timeout, rfds, wfds, Vector())); + current->block(*new Thread::SelectBlocker(actual_timeout, has_timeout, rfds, wfds, Vector())); int fds_with_revents = 0; @@ -2125,7 +2125,7 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a auto& socket = *accepting_socket_description->socket(); if (!socket.can_accept()) { if (accepting_socket_description->is_blocking()) { - current->block(*new Thread::ThreadBlockerAccept(*accepting_socket_description)); + current->block(*new Thread::AcceptBlocker(*accepting_socket_description)); if (current->m_was_interrupted_while_blocked) return -EINTR; } else { diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 0b57e72a63..070c40584e 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -51,21 +51,21 @@ void Scheduler::beep() s_beep_timeout = g_uptime + 100; } -Thread::ThreadBlockerFileDescription::ThreadBlockerFileDescription(const RefPtr& description) +Thread::FileDescriptionBlocker::FileDescriptionBlocker(const RefPtr& description) : m_blocked_description(description) {} -RefPtr Thread::ThreadBlockerFileDescription::blocked_description() const +RefPtr Thread::FileDescriptionBlocker::blocked_description() const { return m_blocked_description; } -Thread::ThreadBlockerAccept::ThreadBlockerAccept(const RefPtr& description) - : ThreadBlockerFileDescription(description) +Thread::AcceptBlocker::AcceptBlocker(const RefPtr& description) + : FileDescriptionBlocker(description) { } -bool Thread::ThreadBlockerAccept::should_unblock(Thread&, time_t, long) +bool Thread::AcceptBlocker::should_unblock(Thread&, time_t, long) { auto& description = *blocked_description(); auto& socket = *description.socket(); @@ -73,12 +73,12 @@ bool Thread::ThreadBlockerAccept::should_unblock(Thread&, time_t, long) return socket.can_accept(); } -Thread::ThreadBlockerReceive::ThreadBlockerReceive(const RefPtr& description) - : ThreadBlockerFileDescription(description) +Thread::ReceiveBlocker::ReceiveBlocker(const RefPtr& description) + : FileDescriptionBlocker(description) { } -bool Thread::ThreadBlockerReceive::should_unblock(Thread&, time_t now_sec, long now_usec) +bool Thread::ReceiveBlocker::should_unblock(Thread&, time_t now_sec, long now_usec) { auto& description = *blocked_description(); auto& socket = *description.socket(); @@ -89,61 +89,61 @@ bool Thread::ThreadBlockerReceive::should_unblock(Thread&, time_t now_sec, long return false; } -Thread::ThreadBlockerConnect::ThreadBlockerConnect(const RefPtr& description) - : ThreadBlockerFileDescription(description) +Thread::ConnectBlocker::ConnectBlocker(const RefPtr& description) + : FileDescriptionBlocker(description) { } -bool Thread::ThreadBlockerConnect::should_unblock(Thread&, time_t, long) +bool Thread::ConnectBlocker::should_unblock(Thread&, time_t, long) { auto& description = *blocked_description(); auto& socket = *description.socket(); return socket.is_connected(); } -Thread::ThreadBlockerWrite::ThreadBlockerWrite(const RefPtr& description) - : ThreadBlockerFileDescription(description) +Thread::WriteBlocker::WriteBlocker(const RefPtr& description) + : FileDescriptionBlocker(description) { } -bool Thread::ThreadBlockerWrite::should_unblock(Thread&, time_t, long) +bool Thread::WriteBlocker::should_unblock(Thread&, time_t, long) { return blocked_description()->can_write(); } -Thread::ThreadBlockerRead::ThreadBlockerRead(const RefPtr& description) - : ThreadBlockerFileDescription(description) +Thread::ReadBlocker::ReadBlocker(const RefPtr& description) + : FileDescriptionBlocker(description) { } -bool Thread::ThreadBlockerRead::should_unblock(Thread&, time_t, long) +bool Thread::ReadBlocker::should_unblock(Thread&, time_t, long) { // FIXME: Block until the amount of data wanted is available. return blocked_description()->can_read(); } -Thread::ThreadBlockerCondition::ThreadBlockerCondition(Function &condition) +Thread::ConditionBlocker::ConditionBlocker(Function &condition) : m_block_until_condition(move(condition)) { ASSERT(m_block_until_condition); } -bool Thread::ThreadBlockerCondition::should_unblock(Thread&, time_t, long) +bool Thread::ConditionBlocker::should_unblock(Thread&, time_t, long) { return m_block_until_condition(); } -Thread::ThreadBlockerSleep::ThreadBlockerSleep(u64 wakeup_time) +Thread::SleepBlocker::SleepBlocker(u64 wakeup_time) : m_wakeup_time(wakeup_time) { } -bool Thread::ThreadBlockerSleep::should_unblock(Thread&, time_t, long) +bool Thread::SleepBlocker::should_unblock(Thread&, time_t, long) { return m_wakeup_time <= g_uptime; } -Thread::ThreadBlockerSelect::ThreadBlockerSelect(const timeval& tv, bool select_has_timeout, const Vector& read_fds, const Vector& write_fds, const Vector& except_fds) +Thread::SelectBlocker::SelectBlocker(const timeval& tv, bool select_has_timeout, const Vector& read_fds, const Vector& write_fds, const Vector& except_fds) : m_select_timeout(tv) , m_select_has_timeout(select_has_timeout) , m_select_read_fds(read_fds) @@ -152,7 +152,7 @@ Thread::ThreadBlockerSelect::ThreadBlockerSelect(const timeval& tv, bool select_ { } -bool Thread::ThreadBlockerSelect::should_unblock(Thread& thread, time_t now_sec, long now_usec) +bool Thread::SelectBlocker::should_unblock(Thread& thread, time_t now_sec, long now_usec) { if (m_select_has_timeout) { if (now_sec > m_select_timeout.tv_sec || (now_sec == m_select_timeout.tv_sec && now_usec >= m_select_timeout.tv_usec)) @@ -172,13 +172,13 @@ bool Thread::ThreadBlockerSelect::should_unblock(Thread& thread, time_t now_sec, return false; } -Thread::ThreadBlockerWait::ThreadBlockerWait(int wait_options, pid_t& waitee_pid) +Thread::WaitBlocker::WaitBlocker(int wait_options, pid_t& waitee_pid) : m_wait_options(wait_options) , m_waitee_pid(waitee_pid) { } -bool Thread::ThreadBlockerWait::should_unblock(Thread& thread, time_t, long) +bool Thread::WaitBlocker::should_unblock(Thread& thread, time_t, long) { bool should_unblock = false; thread.process().for_each_child([&](Process& child) { diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 41ff119c18..9aa6f45698 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -110,7 +110,7 @@ void Thread::unblock() void Thread::block_until(Function&& condition) { - m_blocker = make(condition); + m_blocker = make(condition); block(Thread::BlockedCondition); Scheduler::yield(); } @@ -129,7 +129,7 @@ void Thread::block(Thread::State new_state) process().big_lock().lock(); } -void Thread::block(ThreadBlocker& blocker) +void Thread::block(Blocker& blocker) { m_blocker = &blocker; block(Thread::BlockedCondition); @@ -139,7 +139,7 @@ u64 Thread::sleep(u32 ticks) { ASSERT(state() == Thread::Running); u64 wakeup_time = g_uptime + ticks; - current->block(*new Thread::ThreadBlockerSleep(wakeup_time)); + current->block(*new Thread::SleepBlocker(wakeup_time)); return wakeup_time; } @@ -543,7 +543,7 @@ KResult Thread::wait_for_connect(FileDescription& description) auto& socket = *description.socket(); if (socket.is_connected()) return KSuccess; - block(*new Thread::ThreadBlockerConnect(description)); + block(*new Thread::ConnectBlocker(description)); Scheduler::yield(); if (!socket.is_connected()) return KResult(-ECONNREFUSED); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index c1b1b9b7a5..b5e3998836 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -70,72 +70,72 @@ public: __End_Blocked_States__ }; - class ThreadBlocker { + class Blocker { public: - virtual ~ThreadBlocker() {} + virtual ~Blocker() {} virtual bool should_unblock(Thread&, time_t now_s, long us) = 0; }; - class ThreadBlockerFileDescription : public ThreadBlocker { + class FileDescriptionBlocker : public Blocker { public: - ThreadBlockerFileDescription(const RefPtr& description); + FileDescriptionBlocker(const RefPtr& description); RefPtr blocked_description() const; private: RefPtr m_blocked_description; }; - class ThreadBlockerAccept : public ThreadBlockerFileDescription { + class AcceptBlocker : public FileDescriptionBlocker { public: - ThreadBlockerAccept(const RefPtr& description); + AcceptBlocker(const RefPtr& description); virtual bool should_unblock(Thread&, time_t, long) override; }; - class ThreadBlockerReceive : public ThreadBlockerFileDescription { + class ReceiveBlocker : public FileDescriptionBlocker { public: - ThreadBlockerReceive(const RefPtr& description); + ReceiveBlocker(const RefPtr& description); virtual bool should_unblock(Thread&, time_t, long) override; }; - class ThreadBlockerConnect : public ThreadBlockerFileDescription { + class ConnectBlocker : public FileDescriptionBlocker { public: - ThreadBlockerConnect(const RefPtr& description); + ConnectBlocker(const RefPtr& description); virtual bool should_unblock(Thread&, time_t, long) override; }; - class ThreadBlockerWrite : public ThreadBlockerFileDescription { + class WriteBlocker : public FileDescriptionBlocker { public: - ThreadBlockerWrite(const RefPtr& description); + WriteBlocker(const RefPtr& description); virtual bool should_unblock(Thread&, time_t, long) override; }; - class ThreadBlockerRead : public ThreadBlockerFileDescription { + class ReadBlocker : public FileDescriptionBlocker { public: - ThreadBlockerRead(const RefPtr& description); + ReadBlocker(const RefPtr& description); virtual bool should_unblock(Thread&, time_t, long) override; }; - class ThreadBlockerCondition : public ThreadBlocker { + class ConditionBlocker : public Blocker { public: - ThreadBlockerCondition(Function &condition); + ConditionBlocker(Function &condition); virtual bool should_unblock(Thread&, time_t, long) override; private: Function m_block_until_condition; }; - class ThreadBlockerSleep : public ThreadBlocker { + class SleepBlocker : public Blocker { public: - ThreadBlockerSleep(u64 wakeup_time); + SleepBlocker(u64 wakeup_time); virtual bool should_unblock(Thread&, time_t, long) override; private: u64 m_wakeup_time { 0 }; }; - class ThreadBlockerSelect : public ThreadBlocker { + class SelectBlocker : public Blocker { public: - ThreadBlockerSelect(const timeval& tv, bool select_has_timeout, const Vector& read_fds, const Vector& write_fds, const Vector& except_fds); + SelectBlocker(const timeval& tv, bool select_has_timeout, const Vector& read_fds, const Vector& write_fds, const Vector& except_fds); virtual bool should_unblock(Thread&, time_t, long) override; private: @@ -146,9 +146,9 @@ public: const Vector& m_select_exceptional_fds; }; - class ThreadBlockerWait : public ThreadBlocker { + class WaitBlocker : public Blocker { public: - ThreadBlockerWait(int wait_options, pid_t& waitee_pid); + WaitBlocker(int wait_options, pid_t& waitee_pid); virtual bool should_unblock(Thread&, time_t, long) override; private: @@ -176,7 +176,7 @@ public: u64 sleep(u32 ticks); void block(Thread::State); - void block(ThreadBlocker& blocker); + void block(Blocker& blocker); void unblock(); void block_until(Function&&); @@ -260,7 +260,7 @@ private: RefPtr m_kernel_stack_for_signal_handler_region; SignalActionData m_signal_action_data[32]; Region* m_signal_stack_user_region { nullptr }; - OwnPtr m_blocker; + OwnPtr m_blocker; FPUState* m_fpu_state { nullptr }; InlineLinkedList* m_thread_list { nullptr }; State m_state { Invalid };