2026-02-24 16:03:58 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2026, the Ladybird developers.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
|
#include <AK/Queue.h>
|
|
|
|
|
#include <AK/Vector.h>
|
2025-10-30 09:29:29 -03:00
|
|
|
#include <LibSync/ConditionVariable.h>
|
|
|
|
|
#include <LibSync/Mutex.h>
|
2026-02-24 16:03:58 -03:00
|
|
|
#include <LibThreading/Thread.h>
|
|
|
|
|
|
|
|
|
|
namespace Threading {
|
|
|
|
|
|
|
|
|
|
class ThreadPool {
|
|
|
|
|
public:
|
|
|
|
|
static ThreadPool& the();
|
|
|
|
|
|
|
|
|
|
void submit(Function<void()>);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ThreadPool();
|
|
|
|
|
|
|
|
|
|
intptr_t worker_thread_func();
|
|
|
|
|
|
2025-10-30 09:29:29 -03:00
|
|
|
Sync::Mutex m_mutex;
|
|
|
|
|
Sync::ConditionVariable m_condition { m_mutex };
|
2026-02-24 16:03:58 -03:00
|
|
|
Queue<Function<void()>> m_work_queue;
|
|
|
|
|
Vector<NonnullRefPtr<Thread>> m_threads;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|