// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_TASKSCHEDULERIMPL_HPP #define NAZARA_TASKSCHEDULERIMPL_HPP #include #include #include #include #include #include namespace Nz { class TaskSchedulerImpl { public: TaskSchedulerImpl() = delete; ~TaskSchedulerImpl() = delete; static bool Initialize(std::size_t workerCount); static bool IsInitialized(); static void Run(Functor** tasks, std::size_t count); static void Uninitialize(); static void WaitForTasks(); private: static Functor* StealTask(std::size_t workerID); static unsigned int __stdcall WorkerProc(void* userdata); struct Worker { std::atomic_size_t workCount; std::queue queue; CRITICAL_SECTION queueMutex; HANDLE wakeEvent; volatile bool running; }; static std::unique_ptr s_doneEvents; // Doivent être contigus static std::unique_ptr s_workers; static std::unique_ptr s_workerThreads; // Doivent être contigus static DWORD s_workerCount; }; } #endif // NAZARA_TASKSCHEDULERIMPL_HPP