1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

Kernel: Remove an allocation when blocking a thread

When blocking a thread with a timeout we would previously allocate
a Timer object. This removes the allocation for that Timer object.
This commit is contained in:
Gunnar Beutner 2021-05-20 00:41:51 +02:00 committed by Andreas Kling
parent 96b75af5d1
commit 7557f2db90
Notes: sideshowbarker 2024-07-18 17:43:28 +09:00
5 changed files with 42 additions and 23 deletions

View file

@ -42,17 +42,22 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
return ENOMEM;
kernel_stack_region->set_stack(true);
auto thread = adopt_ref_if_nonnull(new Thread(move(process), kernel_stack_region.release_nonnull()));
auto block_timer = adopt_ref_if_nonnull(new Timer());
if (!block_timer)
return ENOMEM;
auto thread = adopt_ref_if_nonnull(new Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull()));
if (!thread)
return ENOMEM;
return thread.release_nonnull();
}
Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region)
Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region, NonnullRefPtr<Timer> block_timer)
: m_process(move(process))
, m_kernel_stack_region(move(kernel_stack_region))
, m_name(m_process->name())
, m_block_timer(block_timer)
{
bool is_first_thread = m_process->add_thread(*this);
if (is_first_thread) {