Browse Source

Kernel: Rename ThreadBlocker classes to avoid stutter

Thread::ThreadBlockerFoo is a lot less nice to read than Thread::FooBlocker
Robin Burchell 6 years ago
parent
commit
52743f9eec
6 changed files with 61 additions and 61 deletions
  1. 1 1
      Kernel/Net/IPv4Socket.cpp
  2. 1 1
      Kernel/Net/TCPSocket.cpp
  3. 6 6
      Kernel/Process.cpp
  4. 25 25
      Kernel/Scheduler.cpp
  5. 4 4
      Kernel/Thread.cpp
  6. 24 24
      Kernel/Thread.h

+ 1 - 1
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) {

+ 1 - 1
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;
     }

+ 6 - 6
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<int>()));
+        current->block(*new Thread::SelectBlocker(actual_timeout, has_timeout, rfds, wfds, Vector<int>()));
 
     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 {

+ 25 - 25
Kernel/Scheduler.cpp

@@ -51,21 +51,21 @@ void Scheduler::beep()
     s_beep_timeout = g_uptime + 100;
 }
 
-Thread::ThreadBlockerFileDescription::ThreadBlockerFileDescription(const RefPtr<FileDescription>& description)
+Thread::FileDescriptionBlocker::FileDescriptionBlocker(const RefPtr<FileDescription>& description)
     : m_blocked_description(description)
 {}
 
-RefPtr<FileDescription> Thread::ThreadBlockerFileDescription::blocked_description() const
+RefPtr<FileDescription> Thread::FileDescriptionBlocker::blocked_description() const
 {
     return m_blocked_description;
 }
 
-Thread::ThreadBlockerAccept::ThreadBlockerAccept(const RefPtr<FileDescription>& description)
-    : ThreadBlockerFileDescription(description)
+Thread::AcceptBlocker::AcceptBlocker(const RefPtr<FileDescription>& 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<FileDescription>& description)
-    : ThreadBlockerFileDescription(description)
+Thread::ReceiveBlocker::ReceiveBlocker(const RefPtr<FileDescription>& 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<FileDescription>& description)
-    : ThreadBlockerFileDescription(description)
+Thread::ConnectBlocker::ConnectBlocker(const RefPtr<FileDescription>& 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<FileDescription>& description)
-    : ThreadBlockerFileDescription(description)
+Thread::WriteBlocker::WriteBlocker(const RefPtr<FileDescription>& 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<FileDescription>& description)
-    : ThreadBlockerFileDescription(description)
+Thread::ReadBlocker::ReadBlocker(const RefPtr<FileDescription>& 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<bool()> &condition)
+Thread::ConditionBlocker::ConditionBlocker(Function<bool()> &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<int>& read_fds, const Vector<int>& write_fds, const Vector<int>& except_fds)
+Thread::SelectBlocker::SelectBlocker(const timeval& tv, bool select_has_timeout, const Vector<int>& read_fds, const Vector<int>& write_fds, const Vector<int>& 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) {

+ 4 - 4
Kernel/Thread.cpp

@@ -110,7 +110,7 @@ void Thread::unblock()
 
 void Thread::block_until(Function<bool()>&& condition)
 {
-    m_blocker = make<ThreadBlockerCondition>(condition);
+    m_blocker = make<ConditionBlocker>(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);

+ 24 - 24
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<FileDescription>& description);
+        FileDescriptionBlocker(const RefPtr<FileDescription>& description);
         RefPtr<FileDescription> blocked_description() const;
 
     private:
         RefPtr<FileDescription> m_blocked_description;
     };
 
-    class ThreadBlockerAccept : public ThreadBlockerFileDescription {
+    class AcceptBlocker : public FileDescriptionBlocker {
     public:
-        ThreadBlockerAccept(const RefPtr<FileDescription>& description);
+        AcceptBlocker(const RefPtr<FileDescription>& description);
         virtual bool should_unblock(Thread&, time_t, long) override;
     };
 
-    class ThreadBlockerReceive : public ThreadBlockerFileDescription {
+    class ReceiveBlocker : public FileDescriptionBlocker {
     public:
-        ThreadBlockerReceive(const RefPtr<FileDescription>& description);
+        ReceiveBlocker(const RefPtr<FileDescription>& description);
         virtual bool should_unblock(Thread&, time_t, long) override;
     };
 
-    class ThreadBlockerConnect : public ThreadBlockerFileDescription {
+    class ConnectBlocker : public FileDescriptionBlocker {
     public:
-        ThreadBlockerConnect(const RefPtr<FileDescription>& description);
+        ConnectBlocker(const RefPtr<FileDescription>& description);
         virtual bool should_unblock(Thread&, time_t, long) override;
     };
 
-    class ThreadBlockerWrite : public ThreadBlockerFileDescription {
+    class WriteBlocker : public FileDescriptionBlocker {
     public:
-        ThreadBlockerWrite(const RefPtr<FileDescription>& description);
+        WriteBlocker(const RefPtr<FileDescription>& description);
         virtual bool should_unblock(Thread&, time_t, long) override;
     };
 
-    class ThreadBlockerRead : public ThreadBlockerFileDescription {
+    class ReadBlocker : public FileDescriptionBlocker {
     public:
-        ThreadBlockerRead(const RefPtr<FileDescription>& description);
+        ReadBlocker(const RefPtr<FileDescription>& description);
         virtual bool should_unblock(Thread&, time_t, long) override;
     };
 
-    class ThreadBlockerCondition : public ThreadBlocker {
+    class ConditionBlocker : public Blocker {
     public:
-        ThreadBlockerCondition(Function<bool()> &condition);
+        ConditionBlocker(Function<bool()> &condition);
         virtual bool should_unblock(Thread&, time_t, long) override;
 
     private:
         Function<bool()> 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<int>& read_fds, const Vector<int>& write_fds, const Vector<int>& except_fds);
+        SelectBlocker(const timeval& tv, bool select_has_timeout, const Vector<int>& read_fds, const Vector<int>& write_fds, const Vector<int>& except_fds);
         virtual bool should_unblock(Thread&, time_t, long) override;
 
     private:
@@ -146,9 +146,9 @@ public:
         const Vector<int>& 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<bool()>&&);
@@ -260,7 +260,7 @@ private:
     RefPtr<Region> m_kernel_stack_for_signal_handler_region;
     SignalActionData m_signal_action_data[32];
     Region* m_signal_stack_user_region { nullptr };
-    OwnPtr<ThreadBlocker> m_blocker;
+    OwnPtr<Blocker> m_blocker;
     FPUState* m_fpu_state { nullptr };
     InlineLinkedList<Thread>* m_thread_list { nullptr };
     State m_state { Invalid };