diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-07-19 09:04:12 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-19 11:03:22 +0200 |
commit | 750dbe986de0b80772c1bd32627850b1105c0e60 (patch) | |
tree | 4ade181d0b3a7f494b0c9e2bf067b608d7110166 | |
parent | 52743f9eecb93176f74ba31da20b8cd07ada3723 (diff) | |
download | serenity-750dbe986de0b80772c1bd32627850b1105c0e60.zip |
Kernel: Avoid allocations for Select vectors by using inline capacity
Good tip by Andreas :)
-rw-r--r-- | Kernel/Process.cpp | 12 | ||||
-rw-r--r-- | Kernel/Scheduler.cpp | 2 | ||||
-rw-r--r-- | Kernel/Thread.h | 10 |
3 files changed, 13 insertions, 11 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index b2e2f7ebcc..07141a7ba3 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1798,9 +1798,9 @@ int Process::sys$select(const Syscall::SC_select_params* params) select_has_timeout = true; } - Vector<int> rfds; - Vector<int> wfds; - Vector<int> efds; + Thread::SelectBlocker::FDVector rfds; + Thread::SelectBlocker::FDVector wfds; + Thread::SelectBlocker::FDVector efds; auto transfer_fds = [&](auto* fds, auto& vector) -> int { vector.clear_with_capacity(); @@ -1852,8 +1852,8 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout) if (!validate_read_typed(fds)) return -EFAULT; - Vector<int> rfds; - Vector<int> wfds; + Thread::SelectBlocker::FDVector rfds; + Thread::SelectBlocker::FDVector wfds; for (int i = 0; i < nfds; ++i) { if (fds[i].events & POLLIN) @@ -1882,7 +1882,7 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout) #endif if (has_timeout|| timeout < 0) - current->block(*new Thread::SelectBlocker(actual_timeout, has_timeout, rfds, wfds, Vector<int>())); + current->block(*new Thread::SelectBlocker(actual_timeout, has_timeout, rfds, wfds, Thread::SelectBlocker::FDVector())); int fds_with_revents = 0; diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 070c40584e..60c0819f4d 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -143,7 +143,7 @@ bool Thread::SleepBlocker::should_unblock(Thread&, time_t, long) return m_wakeup_time <= g_uptime; } -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) +Thread::SelectBlocker::SelectBlocker(const timeval& tv, bool select_has_timeout, const FDVector& read_fds, const FDVector& write_fds, const FDVector& except_fds) : m_select_timeout(tv) , m_select_has_timeout(select_has_timeout) , m_select_read_fds(read_fds) diff --git a/Kernel/Thread.h b/Kernel/Thread.h index b5e3998836..6144fb8db2 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -10,6 +10,7 @@ #include <Kernel/KResult.h> #include <Kernel/UnixTypes.h> #include <Kernel/VM/Region.h> +#include <LibC/fd_set.h> class Alarm; class FileDescription; @@ -135,15 +136,16 @@ public: class SelectBlocker : public Blocker { public: - SelectBlocker(const timeval& tv, bool select_has_timeout, const Vector<int>& read_fds, const Vector<int>& write_fds, const Vector<int>& except_fds); + typedef Vector<int, FD_SETSIZE> FDVector; + SelectBlocker(const timeval& tv, bool select_has_timeout, const FDVector& read_fds, const FDVector& write_fds, const FDVector& except_fds); virtual bool should_unblock(Thread&, time_t, long) override; private: timeval m_select_timeout; bool m_select_has_timeout { false }; - const Vector<int>& m_select_read_fds; - const Vector<int>& m_select_write_fds; - const Vector<int>& m_select_exceptional_fds; + const FDVector& m_select_read_fds; + const FDVector& m_select_write_fds; + const FDVector& m_select_exceptional_fds; }; class WaitBlocker : public Blocker { |