mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
Kernel: Remove memory allocations from the new Blocker API
This commit is contained in:
parent
99c5377653
commit
cd76b691fb
6 changed files with 27 additions and 27 deletions
|
@ -212,7 +212,7 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t
|
||||||
}
|
}
|
||||||
|
|
||||||
load_receive_deadline();
|
load_receive_deadline();
|
||||||
current->block(*new Thread::ReceiveBlocker(description));
|
current->block<Thread::ReceiveBlocker>(description);
|
||||||
|
|
||||||
LOCKER(lock());
|
LOCKER(lock());
|
||||||
if (!m_can_read) {
|
if (!m_can_read) {
|
||||||
|
|
|
@ -162,7 +162,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh
|
||||||
m_state = State::Connecting;
|
m_state = State::Connecting;
|
||||||
|
|
||||||
if (should_block == ShouldBlock::Yes) {
|
if (should_block == ShouldBlock::Yes) {
|
||||||
current->block(*new Thread::ConnectBlocker(description));
|
current->block<Thread::ConnectBlocker>(description);
|
||||||
ASSERT(is_connected());
|
ASSERT(is_connected());
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
|
@ -869,7 +869,7 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal);
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -900,7 +900,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
dbgprintf("block write on %d\n", fd);
|
dbgprintf("block write on %d\n", fd);
|
||||||
#endif
|
#endif
|
||||||
current->block(*new Thread::WriteBlocker(description));
|
current->block<Thread::WriteBlocker>(description);
|
||||||
}
|
}
|
||||||
ssize_t rc = description.write(data + nwritten, data_size - nwritten);
|
ssize_t rc = description.write(data + nwritten, data_size - nwritten);
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
|
@ -914,7 +914,7 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
break;
|
break;
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal);
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -939,7 +939,7 @@ ssize_t Process::sys$write(int fd, const u8* data, ssize_t size)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
auto nwritten = do_write(*description, data, size);
|
auto nwritten = do_write(*description, data, size);
|
||||||
if (current->has_unmasked_pending_signals()) {
|
if (current->has_unmasked_pending_signals()) {
|
||||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal);
|
||||||
if (nwritten == 0)
|
if (nwritten == 0)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -962,7 +962,7 @@ ssize_t Process::sys$read(int fd, u8* buffer, ssize_t size)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (description->is_blocking()) {
|
if (description->is_blocking()) {
|
||||||
if (!description->can_read()) {
|
if (!description->can_read()) {
|
||||||
current->block(*new Thread::ReadBlocker(*description));
|
current->block<Thread::ReadBlocker>(*description);
|
||||||
if (current->m_was_interrupted_while_blocked)
|
if (current->m_was_interrupted_while_blocked)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
|
@ -1265,7 +1265,7 @@ int Process::sys$kill(pid_t pid, int signal)
|
||||||
}
|
}
|
||||||
if (pid == m_pid) {
|
if (pid == m_pid) {
|
||||||
current->send_signal(signal, this);
|
current->send_signal(signal, this);
|
||||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Signal));
|
current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
@ -1442,7 +1442,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t waitee_pid = waitee;
|
pid_t waitee_pid = waitee;
|
||||||
current->block(*new Thread::WaitBlocker(options, waitee_pid));
|
current->block<Thread::WaitBlocker>(options, waitee_pid);
|
||||||
if (current->m_was_interrupted_while_blocked)
|
if (current->m_was_interrupted_while_blocked)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
|
|
||||||
|
@ -1827,7 +1827,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!params->timeout || select_has_timeout)
|
if (!params->timeout || select_has_timeout)
|
||||||
current->block(*new Thread::SelectBlocker(timeout, select_has_timeout, rfds, wfds, efds));
|
current->block<Thread::SelectBlocker>(timeout, select_has_timeout, rfds, wfds, efds);
|
||||||
|
|
||||||
int marked_fd_count = 0;
|
int marked_fd_count = 0;
|
||||||
auto mark_fds = [&](auto* fds, auto& vector, auto should_mark) {
|
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
|
#endif
|
||||||
|
|
||||||
if (has_timeout|| timeout < 0)
|
if (has_timeout|| timeout < 0)
|
||||||
current->block(*new Thread::SelectBlocker(actual_timeout, has_timeout, rfds, wfds, Thread::SelectBlocker::FDVector()));
|
current->block<Thread::SelectBlocker>(actual_timeout, has_timeout, rfds, wfds, Thread::SelectBlocker::FDVector());
|
||||||
|
|
||||||
int fds_with_revents = 0;
|
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();
|
auto& socket = *accepting_socket_description->socket();
|
||||||
if (!socket.can_accept()) {
|
if (!socket.can_accept()) {
|
||||||
if (accepting_socket_description->is_blocking()) {
|
if (accepting_socket_description->is_blocking()) {
|
||||||
current->block(*new Thread::AcceptBlocker(*accepting_socket_description));
|
current->block<Thread::AcceptBlocker>(*accepting_socket_description);
|
||||||
if (current->m_was_interrupted_while_blocked)
|
if (current->m_was_interrupted_while_blocked)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -110,9 +110,7 @@ void Thread::unblock()
|
||||||
|
|
||||||
void Thread::block_until(const char* state_string, Function<bool()>&& condition)
|
void Thread::block_until(const char* state_string, Function<bool()>&& condition)
|
||||||
{
|
{
|
||||||
m_blocker = make<ConditionBlocker>(state_string, condition);
|
block<ConditionBlocker>(state_string, condition);
|
||||||
block_helper();
|
|
||||||
Scheduler::yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::block_helper()
|
void Thread::block_helper()
|
||||||
|
@ -126,17 +124,11 @@ void Thread::block_helper()
|
||||||
process().big_lock().lock();
|
process().big_lock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::block(Blocker& blocker)
|
|
||||||
{
|
|
||||||
m_blocker = &blocker;
|
|
||||||
block_helper();
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 Thread::sleep(u32 ticks)
|
u64 Thread::sleep(u32 ticks)
|
||||||
{
|
{
|
||||||
ASSERT(state() == Thread::Running);
|
ASSERT(state() == Thread::Running);
|
||||||
u64 wakeup_time = g_uptime + ticks;
|
u64 wakeup_time = g_uptime + ticks;
|
||||||
current->block(*new Thread::SleepBlocker(wakeup_time));
|
current->block<Thread::SleepBlocker>(wakeup_time);
|
||||||
return wakeup_time;
|
return wakeup_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +524,7 @@ KResult Thread::wait_for_connect(FileDescription& description)
|
||||||
auto& socket = *description.socket();
|
auto& socket = *description.socket();
|
||||||
if (socket.is_connected())
|
if (socket.is_connected())
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
block(*new Thread::ConnectBlocker(description));
|
block<Thread::ConnectBlocker>(description);
|
||||||
Scheduler::yield();
|
Scheduler::yield();
|
||||||
if (!socket.is_connected())
|
if (!socket.is_connected())
|
||||||
return KResult(-ECONNREFUSED);
|
return KResult(-ECONNREFUSED);
|
||||||
|
|
|
@ -208,9 +208,17 @@ public:
|
||||||
u32 ticks() const { return m_ticks; }
|
u32 ticks() const { return m_ticks; }
|
||||||
|
|
||||||
u64 sleep(u32 ticks);
|
u64 sleep(u32 ticks);
|
||||||
void block(Blocker& blocker);
|
|
||||||
void unblock();
|
|
||||||
|
|
||||||
|
template <typename T, class... Args>
|
||||||
|
void block(Args&& ... args)
|
||||||
|
{
|
||||||
|
ASSERT(!m_blocker);
|
||||||
|
T t(AK::forward<Args>(args)...);
|
||||||
|
m_blocker = &t;
|
||||||
|
block_helper();
|
||||||
|
};
|
||||||
|
|
||||||
|
void unblock();
|
||||||
void block_until(const char* state_string, Function<bool()>&&);
|
void block_until(const char* state_string, Function<bool()>&&);
|
||||||
KResult wait_for_connect(FileDescription&);
|
KResult wait_for_connect(FileDescription&);
|
||||||
|
|
||||||
|
@ -292,7 +300,7 @@ private:
|
||||||
RefPtr<Region> m_kernel_stack_for_signal_handler_region;
|
RefPtr<Region> m_kernel_stack_for_signal_handler_region;
|
||||||
SignalActionData m_signal_action_data[32];
|
SignalActionData m_signal_action_data[32];
|
||||||
Region* m_signal_stack_user_region { nullptr };
|
Region* m_signal_stack_user_region { nullptr };
|
||||||
OwnPtr<Blocker> m_blocker;
|
Blocker* m_blocker { nullptr };
|
||||||
FPUState* m_fpu_state { nullptr };
|
FPUState* m_fpu_state { nullptr };
|
||||||
InlineLinkedList<Thread>* m_thread_list { nullptr };
|
InlineLinkedList<Thread>* m_thread_list { nullptr };
|
||||||
State m_state { Invalid };
|
State m_state { Invalid };
|
||||||
|
|
|
@ -242,7 +242,7 @@ extern "C" [[noreturn]] void init()
|
||||||
current->process().set_priority(Process::LowPriority);
|
current->process().set_priority(Process::LowPriority);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Thread::finalize_dying_threads();
|
Thread::finalize_dying_threads();
|
||||||
current->block(*new Thread::SemiPermanentBlocker(Thread::SemiPermanentBlocker::Reason::Lurking));
|
current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Lurking);
|
||||||
Scheduler::yield();
|
Scheduler::yield();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue