2013-02-03 13:11:16 +00:00
|
|
|
#ifndef THREAD_UTILS_IMPL_H_INCLUDED
|
|
|
|
#define THREAD_UTILS_IMPL_H_INCLUDED
|
|
|
|
|
|
|
|
#include "include/Engine.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace SE
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename RETURNTYPE>
|
|
|
|
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f)
|
|
|
|
{
|
2013-02-21 08:35:47 +00:00
|
|
|
/*
|
2013-02-20 05:10:38 +00:00
|
|
|
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
|
|
|
|
{
|
|
|
|
return f();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RETURNTYPE result;
|
2013-02-20 17:41:51 +00:00
|
|
|
|
|
|
|
boost::mutex ServiceLock;
|
2013-02-20 05:10:38 +00:00
|
|
|
|
2013-02-20 17:41:51 +00:00
|
|
|
ServiceLock.lock();
|
|
|
|
|
|
|
|
boost::function<void()> cover_f = [&result, &ServiceLock, f]()
|
|
|
|
{
|
|
|
|
result = f();
|
|
|
|
ServiceLock.unlock();
|
|
|
|
};
|
2013-02-20 05:10:38 +00:00
|
|
|
|
|
|
|
MainThreadIoService.post(cover_f);
|
2013-02-20 17:41:51 +00:00
|
|
|
|
|
|
|
ServiceLock.lock();
|
|
|
|
ServiceLock.unlock();
|
|
|
|
|
2013-02-20 05:10:38 +00:00
|
|
|
return result;
|
2013-02-21 08:35:47 +00:00
|
|
|
}*/
|
|
|
|
|
2013-02-03 13:11:16 +00:00
|
|
|
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
|
|
|
|
{
|
|
|
|
return f();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RETURNTYPE result;
|
|
|
|
|
2013-02-21 08:35:47 +00:00
|
|
|
boost::mutex serviceLock;
|
2013-02-03 13:11:16 +00:00
|
|
|
|
2013-02-21 08:35:47 +00:00
|
|
|
boost::function<void()> func =
|
|
|
|
[&result, &f, &serviceLock] ()
|
|
|
|
{
|
|
|
|
result = f();
|
|
|
|
serviceLock.unlock();
|
|
|
|
};
|
2013-02-03 13:11:16 +00:00
|
|
|
|
2013-02-21 08:35:47 +00:00
|
|
|
serviceLock.lock();
|
2013-02-03 13:11:16 +00:00
|
|
|
|
2013-02-21 08:35:47 +00:00
|
|
|
MainThreadIoService.post(func);
|
2013-02-03 13:11:16 +00:00
|
|
|
|
2013-02-21 08:35:47 +00:00
|
|
|
serviceLock.lock();
|
|
|
|
serviceLock.unlock();
|
|
|
|
|
2013-02-03 13:11:16 +00:00
|
|
|
return result;
|
|
|
|
|
2013-02-21 08:35:47 +00:00
|
|
|
}
|
2013-02-03 13:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace SE
|
|
|
|
|
|
|
|
#endif
|