From 03b00d6f249a3a9c90b832da1db87faea8330195 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 16 Aug 2017 16:41:29 +0200 Subject: [PATCH] Mingw64 compilation fixes. --- src/lol/sys/all.h | 2 +- src/lol/sys/thread.h | 139 +------------------------------------- src/lol/sys/threadtypes.h | 136 +++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 139 deletions(-) diff --git a/src/lol/sys/all.h b/src/lol/sys/all.h index bf18efbe..a80e717f 100644 --- a/src/lol/sys/all.h +++ b/src/lol/sys/all.h @@ -12,8 +12,8 @@ #pragma once -#include #include +#include /* requires thread.h */ #include #include #include diff --git a/src/lol/sys/thread.h b/src/lol/sys/thread.h index a47661db..8f3257c3 100644 --- a/src/lol/sys/thread.h +++ b/src/lol/sys/thread.h @@ -1,8 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar -// © 2013—2015 Benjamin “Touky” Huet +// Copyright © 2010—2017 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -18,8 +17,6 @@ // --------------------- // -#include "engine/entity.h" - #include #if LOL_FEATURE_THREADS @@ -264,139 +261,5 @@ private: std::function m_function; }; -//ThreadStatus ---------------------------------------------------------------- -struct ThreadStatusBase : public StructSafeEnum -{ - enum Type - { - NOTHING, - THREAD_STARTED, - THREAD_WORKING, - THREAD_IDLE, - THREAD_STOPPED, - }; -protected: - virtual bool BuildEnumMap(map& enum_map) - { - enum_map[NOTHING] = "NOTHING"; - enum_map[THREAD_STARTED] = "THREAD_STARTED"; - enum_map[THREAD_STOPPED] = "THREAD_STOPPED"; - return true; - } -}; -typedef SafeEnum ThreadStatus; - -struct ThreadJobTypeBase : public StructSafeEnum -{ - enum Type - { - NONE, - WORK_TODO, - WORK_SUCCEEDED, - WORK_FAILED, - WORK_DONE, - THREAD_STOP - }; -protected: - virtual bool BuildEnumMap(map& enum_map) - { - enum_map[NONE] = "NONE"; - enum_map[WORK_TODO] = "WORK_TODO"; - enum_map[WORK_SUCCEEDED] = "WORK_SUCCEEDED"; - enum_map[WORK_FAILED] = "WORK_FAILED"; - enum_map[WORK_DONE] = "WORK_DONE"; - enum_map[THREAD_STOP] = "THREAD_STOP"; - return true; - } -}; -typedef SafeEnum ThreadJobType; - -//ThreadJob ------------------------------------------------------------------- -class ThreadJob -{ - friend class BaseThreadManager; - -protected: - inline ThreadJob(ThreadJobType type) : m_type(type) {} -public: - char const *GetName() { return ""; } - inline ThreadJob() : m_type(ThreadJobType::NONE) {} - virtual ~ThreadJob() {} - - ThreadJobType GetJobType() { return m_type; } - void SetJobType(ThreadJobType type) { m_type = type; } - bool operator==(const ThreadJobType& o) { return GetJobType() == o; } -protected: - virtual bool DoWork() { return false; } - - ThreadJobType m_type; -}; - -//Base class for thread manager ----------------------------------------------- -class BaseThreadManager : public Entity -{ -public: - char const *GetName() { return ""; } - BaseThreadManager(int thread_max); - BaseThreadManager(int thread_max, int thread_min); - virtual ~BaseThreadManager(); - - //Base setup - void Setup(int thread_max); - void Setup(int thread_max, int thread_min); - - //Initialize, Ticker::Ref and start the thread - bool Start(); - //Stop the threads - bool Stop(); - -private: - //Work stuff - bool AddThreadWork(ThreadJob* job); - -protected: - //Thread count management - void AdjustThreadCount(int count); - void CleanAddedThread(bool wait = false); - void CleanRemovedThread(bool wait = false); - - int GetDispatchCount(); - int GetDispatchedCount(); - - //Dispatch job to threads - void DispatchJob(ThreadJob* job); - void DispatchJob(array const& jobs); - //Fetch Results - bool FetchResult(array& results); - //Base thread work function - void BaseThreadWork(thread* inst); - - virtual void TickGame(float seconds); - //Default behaviour : delete the job result - virtual void TreatResult(ThreadJob* result) { delete(result); } - -private: - /* Jobs */ - array m_job_dispatch; - int m_job_dispatched = 0; - -#if LOL_FEATURE_THREADS - /* Worker threads */ - int m_thread_max = 0; - int m_thread_min = 0; - int m_thread_active = 0; - array m_threads; - Timer m_thread_added_timer; - int m_thread_added = 0; - Timer m_thread_removed_timer; - int m_thread_removed = 0; - - queue m_statusqueue; - queue m_spawnqueue, m_donequeue; -#endif //LOL_FEATURE_THREADS - queue m_jobqueue; - queue m_resultqueue; -}; - } /* namespace lol */ diff --git a/src/lol/sys/threadtypes.h b/src/lol/sys/threadtypes.h index ec575aac..2acddc3d 100644 --- a/src/lol/sys/threadtypes.h +++ b/src/lol/sys/threadtypes.h @@ -18,9 +18,145 @@ // --------------------- // +#include "engine/entity.h" + namespace lol { +//ThreadStatus ---------------------------------------------------------------- +struct ThreadStatusBase : public StructSafeEnum +{ + enum Type + { + NOTHING, + THREAD_STARTED, + THREAD_WORKING, + THREAD_IDLE, + THREAD_STOPPED, + }; +protected: + virtual bool BuildEnumMap(map& enum_map) + { + enum_map[NOTHING] = "NOTHING"; + enum_map[THREAD_STARTED] = "THREAD_STARTED"; + enum_map[THREAD_STOPPED] = "THREAD_STOPPED"; + return true; + } +}; +typedef SafeEnum ThreadStatus; + +struct ThreadJobTypeBase : public StructSafeEnum +{ + enum Type + { + NONE, + WORK_TODO, + WORK_SUCCEEDED, + WORK_FAILED, + WORK_DONE, + THREAD_STOP + }; +protected: + virtual bool BuildEnumMap(map& enum_map) + { + enum_map[NONE] = "NONE"; + enum_map[WORK_TODO] = "WORK_TODO"; + enum_map[WORK_SUCCEEDED] = "WORK_SUCCEEDED"; + enum_map[WORK_FAILED] = "WORK_FAILED"; + enum_map[WORK_DONE] = "WORK_DONE"; + enum_map[THREAD_STOP] = "THREAD_STOP"; + return true; + } +}; +typedef SafeEnum ThreadJobType; + +//ThreadJob ------------------------------------------------------------------- +class ThreadJob +{ + friend class BaseThreadManager; + +protected: + inline ThreadJob(ThreadJobType type) : m_type(type) {} +public: + char const *GetName() { return ""; } + inline ThreadJob() : m_type(ThreadJobType::NONE) {} + virtual ~ThreadJob() {} + + ThreadJobType GetJobType() { return m_type; } + void SetJobType(ThreadJobType type) { m_type = type; } + bool operator==(const ThreadJobType& o) { return GetJobType() == o; } +protected: + virtual bool DoWork() { return false; } + + ThreadJobType m_type; +}; + +//Base class for thread manager ----------------------------------------------- +class BaseThreadManager : public Entity +{ +public: + char const *GetName() { return ""; } + BaseThreadManager(int thread_max); + BaseThreadManager(int thread_max, int thread_min); + virtual ~BaseThreadManager(); + + //Base setup + void Setup(int thread_max); + void Setup(int thread_max, int thread_min); + + //Initialize, Ticker::Ref and start the thread + bool Start(); + //Stop the threads + bool Stop(); + +private: + //Work stuff + bool AddThreadWork(ThreadJob* job); + +protected: + //Thread count management + void AdjustThreadCount(int count); + void CleanAddedThread(bool wait = false); + void CleanRemovedThread(bool wait = false); + + int GetDispatchCount(); + int GetDispatchedCount(); + + //Dispatch job to threads + void DispatchJob(ThreadJob* job); + void DispatchJob(array const& jobs); + //Fetch Results + bool FetchResult(array& results); + //Base thread work function + void BaseThreadWork(thread* inst); + + virtual void TickGame(float seconds); + //Default behaviour : delete the job result + virtual void TreatResult(ThreadJob* result) { delete(result); } + +private: + /* Jobs */ + array m_job_dispatch; + int m_job_dispatched = 0; + +#if LOL_FEATURE_THREADS + /* Worker threads */ + int m_thread_max = 0; + int m_thread_min = 0; + int m_thread_active = 0; + array m_threads; + Timer m_thread_added_timer; + int m_thread_added = 0; + Timer m_thread_removed_timer; + int m_thread_removed = 0; + + queue m_statusqueue; + queue m_spawnqueue, m_donequeue; +#endif //LOL_FEATURE_THREADS + queue m_jobqueue; + queue m_resultqueue; +}; + //Generic class for thread manager, executes work and store results, with no specific treatment class DefaultThreadManager : public BaseThreadManager {