boost::asio for resource manager threads
This commit is contained in:
parent
06652bfa0d
commit
a68e798a89
@ -55,10 +55,10 @@ public:
|
||||
|
||||
boost::thread::id MainThreadId;
|
||||
|
||||
std::vector<boost::function<void()>> MainThreadAsyncFunctionArr;
|
||||
//std::vector<boost::function<void()>> MainThreadAsyncFunctionArr;
|
||||
|
||||
boost::mutex FuncListMutex;
|
||||
std::list<TFuncToPerform> MainThreadSyncFunctionList;
|
||||
//boost::mutex FuncListMutex;
|
||||
//std::list<TFuncToPerform> MainThreadSyncFunctionList;
|
||||
|
||||
TTextureListClass TexList;
|
||||
TModelManager ModelManager;
|
||||
|
@ -1,13 +1,18 @@
|
||||
#ifndef THREAD_UTILS_H_INCLUDED
|
||||
#define THREAD_UTILS_H_INCLUDED
|
||||
|
||||
#include "boost/asio.hpp"
|
||||
#include "boost/signal.hpp"
|
||||
#include "boost/thread.hpp"
|
||||
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
extern boost::asio::io_service MainThreadIoService;
|
||||
|
||||
#ifndef UTILS_ENGINE
|
||||
/*
|
||||
struct TFuncToPerform
|
||||
{
|
||||
private:
|
||||
@ -23,7 +28,7 @@ namespace SE
|
||||
std::shared_ptr<boost::mutex> LockerPtr;
|
||||
|
||||
boost::function<void()> Func;
|
||||
};
|
||||
};*/
|
||||
|
||||
void AssertIfInMainThread();
|
||||
|
||||
|
@ -24,7 +24,21 @@ namespace SE
|
||||
template<typename RETURNTYPE>
|
||||
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f)
|
||||
{
|
||||
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
|
||||
{
|
||||
return f();
|
||||
}
|
||||
else
|
||||
{
|
||||
RETURNTYPE result;
|
||||
|
||||
boost::function<void()> cover_f = [&result, f]() { result = f(); };
|
||||
|
||||
MainThreadIoService.post(cover_f);
|
||||
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
|
||||
{
|
||||
return f();
|
||||
@ -57,7 +71,7 @@ namespace SE
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
} //namespace SE
|
||||
|
@ -15,10 +15,12 @@ Here goes all functions that are platform-specific
|
||||
When I make iOS/Mac/Linux port, I will make same API pair h/cpp
|
||||
*/
|
||||
|
||||
//Not in use, wow
|
||||
/*
|
||||
void GetWindowWidthHeight(int& width, int& height);
|
||||
|
||||
int GetWindowWidth();
|
||||
|
||||
int GetWindowHeight();
|
||||
int GetWindowHeight();*/
|
||||
|
||||
} //namespace SE
|
@ -25,12 +25,12 @@ TResourceManager* ResourceManager;
|
||||
void TResourceManager::Update(cardinal timer)
|
||||
{
|
||||
|
||||
FuncListMutex.lock();
|
||||
//FuncListMutex.lock();
|
||||
|
||||
SoundManager.Update(timer);
|
||||
|
||||
GUIManager.Update(timer);
|
||||
|
||||
/*
|
||||
if (MainThreadAsyncFunctionArr.size() != 0)
|
||||
{
|
||||
MainThreadAsyncFunctionArr[0]();
|
||||
@ -52,7 +52,9 @@ void TResourceManager::Update(cardinal timer)
|
||||
itr->LockerPtr->unlock();
|
||||
}
|
||||
|
||||
FuncListMutex.unlock();
|
||||
FuncListMutex.unlock();*/
|
||||
MainThreadIoService.run();
|
||||
MainThreadIoService.reset();
|
||||
}
|
||||
|
||||
TResourceManager::~TResourceManager()
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace SE
|
||||
{
|
||||
|
||||
boost::asio::io_service MainThreadIoService;
|
||||
|
||||
#ifndef UTILS_ENGINE
|
||||
void AssertIfInMainThread()
|
||||
{
|
||||
@ -22,6 +24,7 @@ namespace SE
|
||||
|
||||
void PerformInMainThreadAsync(boost::function<void()> f)
|
||||
{
|
||||
/*
|
||||
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
|
||||
{
|
||||
f();
|
||||
@ -29,7 +32,17 @@ namespace SE
|
||||
else
|
||||
{
|
||||
ResourceManager->MainThreadAsyncFunctionArr.push_back(f);
|
||||
}*/
|
||||
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
|
||||
{
|
||||
f();
|
||||
}
|
||||
else
|
||||
{
|
||||
MainThreadIoService.dispatch(f);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -8,6 +8,8 @@ Here goes all functions that are platform-specific
|
||||
When I make iOS/Mac/Linux port, I will make same API pair h/cpp
|
||||
*/
|
||||
|
||||
//Not in use, wow
|
||||
/*
|
||||
void GetWindowWidthHeight(HWND hwnd, int& width, int& height)
|
||||
{
|
||||
RECT rc;
|
||||
@ -32,5 +34,5 @@ int GetWindowHeight(HWND hwnd)
|
||||
|
||||
return rc.bottom;
|
||||
}
|
||||
|
||||
*/
|
||||
} //namespace SE
|
Loading…
Reference in New Issue
Block a user