mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
This commit splits out synchronization primitives from LibThreading into LibSync. This is because LibThreading depends on LibCore, while LibCore needs the synchronization primitives from LibThreading. This worked while they were header only, but when I tried to add an implementation file it ran into the circular dependency. To abstract away the pthread implementation using cpp files is necessary so the synchronization primitives were moved to a separate library.
36 lines
636 B
C++
36 lines
636 B
C++
/*
|
|
* 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>
|
|
#include <LibSync/ConditionVariable.h>
|
|
#include <LibSync/Mutex.h>
|
|
#include <LibThreading/Thread.h>
|
|
|
|
namespace Threading {
|
|
|
|
class ThreadPool {
|
|
public:
|
|
static ThreadPool& the();
|
|
|
|
void submit(Function<void()>);
|
|
|
|
private:
|
|
ThreadPool();
|
|
|
|
intptr_t worker_thread_func();
|
|
|
|
Sync::Mutex m_mutex;
|
|
Sync::ConditionVariable m_condition { m_mutex };
|
|
Queue<Function<void()>> m_work_queue;
|
|
Vector<NonnullRefPtr<Thread>> m_threads;
|
|
};
|
|
|
|
}
|