diff --git a/src/NGLMessage.cpp b/src/NGLMessage.cpp index 88d4d763..19e3c335 100644 --- a/src/NGLMessage.cpp +++ b/src/NGLMessage.cpp @@ -13,7 +13,7 @@ std::vector< Message > NGLMessage::s_messageQueue; std::promise< void > g_exitSignal; Colours NGLMessage::s_currentColour = Colours::NORMAL; std::ofstream NGLMessage::s_logFile; - +std::thread g_messageThread; NGLMessage::NGLMessage() { @@ -25,27 +25,29 @@ NGLMessage::NGLMessage() exit(EXIT_FAILURE); } s_futureExit = g_exitSignal.get_future(); - std::thread t([this]() - { - while(s_futureExit.wait_for(std::chrono::milliseconds(1)) == std::future_status::timeout) - { - std::scoped_lock lock(g_messageQueueLock); - if(! s_messageQueue.empty()) - { - auto msg=s_messageQueue.back(); - s_messageQueue.pop_back(); - consume(msg); - } - } }); - t.detach(); + g_messageThread=std::thread ([this]() + { + while(s_futureExit.wait_for(std::chrono::milliseconds(1)) == std::future_status::timeout) + { + std::scoped_lock lock(g_messageQueueLock); + if(! s_messageQueue.empty()) + { + auto msg=s_messageQueue.back(); + s_messageQueue.pop_back(); + consume(msg); + } + + } }); + g_messageThread.detach(); } - - NGLMessage::~NGLMessage() { - while(! s_messageQueue.empty() ) + while(!s_messageQueue.empty()) + { std::this_thread::sleep_for(std::chrono::microseconds(1)); + } + g_exitSignal.set_value(); s_logFile.close(); } @@ -148,7 +150,6 @@ std::string NGLMessage::getColourString(const Colours &_colour) const return output; } - void NGLMessage::addMessage(std::string_view _message, Colours _c, TimeFormat _timeFormat) { std::scoped_lock< std::mutex > lock(g_messageQueueLock); diff --git a/tests/main.cpp b/tests/main.cpp index b5085bdc..7307d402 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -87,7 +87,7 @@ int main(int argc, char **argv) if(useOpenGL == false) { std::cerr << "excluding tests\n"; - ::testing::GTEST_FLAG(filter) = "-ShaderLib.*:VAOPrimitives.*:NGLInit*:NGLMessage*"; + ::testing::GTEST_FLAG(filter) = "-ShaderLib.*:VAOPrimitives.*:NGLInit*"; } // testing::internal::CaptureStdout(); testing::internal::CaptureStderr();