yet another workaround to a deadlock in the log th
read a really stupid workaround but why does notify_one not work
This commit is contained in:
parent
b9604c5729
commit
7527c7340f
|
@ -43,6 +43,7 @@ std::mutex logFileLock;
|
||||||
std::mutex logFileLockI;
|
std::mutex logFileLockI;
|
||||||
std::condition_variable logFileNotify;
|
std::condition_variable logFileNotify;
|
||||||
std::atomic<bool> logFileAvail(false);
|
std::atomic<bool> logFileAvail(false);
|
||||||
|
std::atomic<bool> iAmReallyDead(false);
|
||||||
|
|
||||||
std::atomic<unsigned short> logPosition;
|
std::atomic<unsigned short> logPosition;
|
||||||
|
|
||||||
|
@ -200,6 +201,7 @@ void _logFileThread() {
|
||||||
logFileNotify.wait(lock);
|
logFileNotify.wait(lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
iAmReallyDead=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startLogFile(const char* path) {
|
bool startLogFile(const char* path) {
|
||||||
|
@ -247,10 +249,16 @@ bool finishLogFile() {
|
||||||
if (!logFileAvail) return false;
|
if (!logFileAvail) return false;
|
||||||
|
|
||||||
logFileAvail=false;
|
logFileAvail=false;
|
||||||
|
iAmReallyDead=false;
|
||||||
|
|
||||||
// flush
|
// flush
|
||||||
logFileLockI.lock();
|
logFileLockI.lock();
|
||||||
logFileNotify.notify_one();
|
logFileNotify.notify_one();
|
||||||
|
while (!iAmReallyDead) {
|
||||||
|
std::this_thread::yield();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
}
|
||||||
|
// this join is guaranteed to work
|
||||||
logFileThread->join();
|
logFileThread->join();
|
||||||
logFileLockI.unlock();
|
logFileLockI.unlock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue