further fixes to thread stability

This commit is contained in:
Joakim Kilby
2015-07-01 14:16:18 +02:00
parent 762e70f14b
commit 7159dd8246
3 changed files with 22 additions and 15 deletions
@@ -131,6 +131,8 @@ namespace openspace{
void queMessage(std::vector<char> message);
void update(double dt);
enum MessageTypes{
Authentication=0,
Initialization,
@@ -215,6 +217,7 @@ namespace openspace{
std::atomic<bool> _isHost;
std::atomic<bool> _isConnected;
std::atomic<bool> _isListening;
std::atomic<bool> _performDisconnect;
std::vector<std::vector<char>> _sendBuffer;
std::mutex _sendBufferMutex;
};
+1
View File
@@ -623,6 +623,7 @@ void OpenSpaceEngine::preSynchronization() {
Time::ref().preSynchronization();
_interactionHandler->update(dt);
_parallelConnection->update(dt);
//_interactionHandler.lockControls();
_scriptEngine->preSynchronization();
+18 -15
View File
@@ -84,7 +84,8 @@ namespace openspace {
_receiveThread(nullptr),
_isHost(false),
_isConnected(false),
_isListening(false)
_isListening(false),
_performDisconnect(false)
{
}
@@ -439,10 +440,7 @@ namespace openspace {
if (result == SOCKET_ERROR){
//failed to send message
LERROR("Failed to send message.\nError: " << _ERRNO << " detected in connection, disconnecting.");
//@TODO a better solution for this - description:
//A thread cannot delete/join itself, in this case the listener thread would need to remove itself
//solution (for now) is to call the disconnect script via scriptengine. This is done from a separate thread so it works.
OsEng.scriptEngine()->queueScript("openspace.parallel.disconnect();");
_performDisconnect.store(true);
}
}
@@ -514,10 +512,7 @@ namespace openspace {
}
else{
LERROR("Error " << _ERRNO << " detected in connection, disconnecting.");
//@TODO a better solution for this - description:
//A thread cannot delete/join itself, in this case the listener thread would need to remove itself
//solution (for now) is to call the disconnect script via scriptengine. This is done from a separate thread so it works.
OsEng.scriptEngine()->queueScript("openspace.parallel.disconnect();");
_performDisconnect.store(true);
}
}
@@ -614,16 +609,18 @@ namespace openspace {
LERROR("Error " << _ERRNO << " detected in connection, disconnecting!");
}
//@TODO (JK) a better solution for this - description:
//A thread cannot delete/join itself, in this case the listener thread would need to remove itself
//solution (for now) is to call the disconnect script via scriptengine. This is done from a separate thread so it works.
OsEng.scriptEngine()->queueScript("openspace.parallel.disconnect();");
_performDisconnect.store(true);
break;
}
}
}
void ParallelConnection::update(double dt){
if(_performDisconnect.load()){
disconnect();
}
}
int ParallelConnection::receiveData(_SOCKET & socket, std::vector<char> &buffer, int length, int flags){
int result = 0;
@@ -713,6 +710,10 @@ namespace openspace {
void ParallelConnection::disconnect(){
if (_clientSocket != INVALID_SOCKET){
//we're disconnecting
_performDisconnect.store(false);
//must be run before trying to join communication threads, else the threads are stuck trying to receive data
closeSocket();
@@ -758,7 +759,9 @@ namespace openspace {
}
#if defined(__WIN32__)
WSACleanup();
//this line causes issues with SGCT since winsock dll file is unloaded upon call
//@TODO should this be here?
// WSACleanup();
#endif
}
}