fixing bugs
This commit is contained in:
parent
3c974a33de
commit
013b1dc344
@ -7,6 +7,14 @@
|
||||
namespace SE
|
||||
{
|
||||
|
||||
namespace ST
|
||||
{
|
||||
extern boost::condition_variable FunctionFinishedCondition;
|
||||
|
||||
extern boost::mutex FunctionMutex;
|
||||
}
|
||||
|
||||
|
||||
template<typename RETURNTYPE>
|
||||
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f)
|
||||
{
|
||||
@ -18,21 +26,30 @@ namespace SE
|
||||
{
|
||||
RETURNTYPE result;
|
||||
|
||||
boost::mutex serviceLock;
|
||||
bool functionCalled = false;
|
||||
|
||||
boost::function<void()> func =
|
||||
[&result, &f, &serviceLock] ()
|
||||
[&] ()
|
||||
{
|
||||
result = f();
|
||||
serviceLock.unlock();
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(FunctionMutex);
|
||||
functionCalled = true;
|
||||
}
|
||||
FunctionFinishedCondition.notify_one();
|
||||
};
|
||||
|
||||
serviceLock.lock();
|
||||
|
||||
|
||||
ST::MainThreadIoService.post(func);
|
||||
|
||||
serviceLock.lock();
|
||||
serviceLock.unlock();
|
||||
boost::mutex::scoped_lock lock(FunctionMutex);
|
||||
|
||||
while (!functionCalled)
|
||||
{
|
||||
FunctionFinishedCondition.wait(lock);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
|
@ -8,7 +8,13 @@ namespace SE
|
||||
boost::asio::io_service MainThreadIoService;
|
||||
|
||||
boost::thread::id MainThreadId;
|
||||
|
||||
boost::condition_variable FunctionFinishedCondition;
|
||||
|
||||
boost::mutex FunctionMutex;
|
||||
}
|
||||
|
||||
|
||||
#ifndef UTILS_ENGINE
|
||||
void AssertIfInMainThread()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user