mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:47:47 +00:00
Kernel: Avoid allocations for Select vectors by using inline capacity
Good tip by Andreas :)
This commit is contained in:
parent
52743f9eec
commit
750dbe986d
3 changed files with 13 additions and 11 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue