IoService included

This commit is contained in:
Vladislav Khorev 2013-02-21 08:35:47 +00:00
parent 407ee3868f
commit 61ada33ee1
3 changed files with 36 additions and 50 deletions

View File

@ -12,7 +12,7 @@ namespace SE
extern boost::asio::io_service MainThreadIoService;
#ifndef UTILS_ENGINE
/*
struct TFuncToPerform
{
private:
@ -23,13 +23,10 @@ namespace SE
{
}
bool Executed;
std::shared_ptr<boost::mutex> LockerPtr;
boost::function<void()> Func;
};*/
};
void AssertIfInMainThread();
void TryUpdateMainThreadId();

View File

@ -7,23 +7,10 @@
namespace SE
{
template<typename RETURNTYPE>
struct TCoverFunc
{
public:
typedef void result_type;
boost::function<RETURNTYPE()> Func;
void operator()(RETURNTYPE& rx)
{
rx = Func();
}
};
template<typename RETURNTYPE>
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f)
{
/*
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{
return f();
@ -48,8 +35,8 @@ namespace SE
ServiceLock.unlock();
return result;
}
/*
}*/
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{
return f();
@ -58,31 +45,25 @@ namespace SE
{
RETURNTYPE result;
TCoverFunc<RETURNTYPE> cover_f;
boost::mutex serviceLock;
cover_f.Func = f;
boost::function<void()> func =
[&result, &f, &serviceLock] ()
{
result = f();
serviceLock.unlock();
};
TFuncToPerform funcToPerform;
serviceLock.lock();
funcToPerform.Executed = false;
funcToPerform.Func = boost::bind(cover_f, boost::ref(result));
funcToPerform.LockerPtr->lock();
ResourceManager->FuncListMutex.lock();
auto itr = ResourceManager->MainThreadSyncFunctionList.insert(ResourceManager->MainThreadSyncFunctionList.end(), funcToPerform);
ResourceManager->FuncListMutex.unlock();
itr->LockerPtr->lock(); //wait until lock will be released
itr->LockerPtr->unlock();
ResourceManager->FuncListMutex.lock();
ResourceManager->MainThreadSyncFunctionList.erase(itr);
ResourceManager->FuncListMutex.unlock();
MainThreadIoService.post(func);
serviceLock.lock();
serviceLock.unlock();
return result;
}*/
}
}
} //namespace SE

View File

@ -24,25 +24,33 @@ namespace SE
void PerformInMainThreadAsync(boost::function<void()> f)
{
/*
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{
f();
}
else
{
ResourceManager->MainThreadAsyncFunctionArr.push_back(f);
}*/
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{
f();
}
else
{
MainThreadIoService.post(f);
boost::mutex serviceLock;
boost::function<void()> func =
[&f, &serviceLock] ()
{
f();
serviceLock.unlock();
};
serviceLock.lock();
MainThreadIoService.post(func);
serviceLock.lock();
serviceLock.unlock();
}
}
#endif