This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/fiber_pool.hpp

31 lines
521 B
C++
Raw Normal View History

2019-03-21 20:18:31 +01:00
#pragma once
#include "common.hpp"
namespace big
{
class fiber_pool
{
public:
explicit fiber_pool(std::size_t num_fibers);
~fiber_pool();
void queue_job(std::function<void()> func);
void execute_on_game_thread(std::function<void()> func);
2019-03-21 20:18:31 +01:00
void fiber_tick();
static void fiber_func();
int get_total_fibers();
int get_used_fibers();
void reset();
2019-03-21 20:18:31 +01:00
private:
std::recursive_mutex m_mutex;
std::stack<std::function<void()>> m_jobs;
int m_num_fibers;
2019-03-21 20:18:31 +01:00
};
inline fiber_pool* g_fiber_pool{};
2019-03-21 20:18:31 +01:00
}