2020-12-29 18:36:35 -06:00
|
|
|
// Copyright 2020 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <functional>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <queue>
|
|
|
|
|
2021-04-05 21:23:02 -05:00
|
|
|
#include "common/common_types.h"
|
2021-03-31 23:05:45 -05:00
|
|
|
#include "common/unique_function.h"
|
|
|
|
|
2020-12-29 18:36:35 -06:00
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
class ThreadWorker final {
|
|
|
|
public:
|
|
|
|
explicit ThreadWorker(std::size_t num_workers, const std::string& name);
|
|
|
|
~ThreadWorker();
|
2021-03-31 23:05:45 -05:00
|
|
|
void QueueWork(UniqueFunction<void> work);
|
2021-03-22 19:00:48 -05:00
|
|
|
void WaitForRequests();
|
2020-12-29 18:36:35 -06:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<std::thread> threads;
|
2021-03-31 23:05:45 -05:00
|
|
|
std::queue<UniqueFunction<void>> requests;
|
2020-12-29 18:36:35 -06:00
|
|
|
std::mutex queue_mutex;
|
|
|
|
std::condition_variable condition;
|
2021-03-22 19:00:48 -05:00
|
|
|
std::condition_variable wait_condition;
|
2020-12-29 18:36:35 -06:00
|
|
|
std::atomic_bool stop{};
|
2021-04-05 21:23:02 -05:00
|
|
|
std::atomic<u64> work_scheduled{};
|
|
|
|
std::atomic<u64> work_done{};
|
|
|
|
std::atomic<u64> workers_stopped{};
|
|
|
|
std::atomic<u64> workers_queued{};
|
2020-12-29 18:36:35 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Common
|