Allow temporary transfer of main logic thread ownership

Dependency to fix df-ai to work with the new CoreSuspender
develop
Pauli 2018-07-03 21:15:12 +03:00
parent 320e94a1eb
commit a550e112c3
2 changed files with 42 additions and 0 deletions

@ -108,6 +108,26 @@ struct MainThread {
};
}
CoreSuspendReleaseMain::CoreSuspendReleaseMain()
{
MainThread::suspend().unlock();
}
CoreSuspendReleaseMain::~CoreSuspendReleaseMain()
{
MainThread::suspend().lock();
}
CoreSuspendClaimMain::CoreSuspendClaimMain()
{
MainThread::suspend().lock();
}
CoreSuspendClaimMain::~CoreSuspendClaimMain()
{
MainThread::suspend().unlock();
}
struct Core::Private
{
std::thread iothread;

@ -300,6 +300,8 @@ namespace DFHack
friend class ServerConnection;
friend class CoreSuspender;
friend class CoreSuspenderBase;
friend struct CoreSuspendClaimMain;
friend struct CoreSuspendReleaseMain;
ServerMain *server;
};
@ -412,5 +414,25 @@ namespace DFHack
}
};
/*!
* Temporary release main thread ownership to allow alternative thread
* implement DF logic thread loop
*/
struct DFHACK_EXPORT CoreSuspendReleaseMain {
CoreSuspendReleaseMain();
~CoreSuspendReleaseMain();
};
/*!
* Temporary claim main thread ownership. This allows caller to call
* Core::Update from a different thread than original DF logic thread if
* logic thread has released main thread ownership with
* CoreSuspendReleaseMain
*/
struct DFHACK_EXPORT CoreSuspendClaimMain {
CoreSuspendClaimMain();
~CoreSuspendClaimMain();
};
using CoreSuspendClaimer = CoreSuspender;
}