18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-13 23:37:59 +01:00

fix(app): the log written to the end of the closing, each step of it with its time; the Discord thread idle outside the driver mode

The log service stopped with applicationQuitOrder, so whatever was logged while the simulator closed was lost; it now runs until StopLogService() and writes out what came before. The closing logs each of its steps with the time since it began, to tell where a closing that hangs stops. Outside the driver mode the Discord thread spun a core in its loop, it now sleeps a second between the checks.
This commit is contained in:
maj00r
2026-11-03 21:45:57 +01:00
parent 823807201c
commit b34238f33f
4 changed files with 30 additions and 3 deletions

View File

@@ -270,7 +270,11 @@ void eu07_application::DiscordRPCService()
} }
if (currentMode != mode::driver) if (currentMode != mode::driver)
{
// the editor and the other modes: nothing to tell, without spinning a core on it
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
continue; continue;
}
// Discord RPC updater // Discord RPC updater
if (simulation::is_ready) if (simulation::is_ready)
@@ -690,19 +694,29 @@ void eu07_application::release_python_lock()
void eu07_application::exit() void eu07_application::exit()
{ {
Global.applicationQuitOrder = true; Global.applicationQuitOrder = true;
// each step of the closing in the log, to tell from it where a closing that hangs stops
auto const closing{std::chrono::steady_clock::now()};
auto const step = [&](char const *What) {
WriteLog(std::string{"Closing: "} + What + " at " + std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - closing).count()) + " ms");
};
step("the modes");
for (auto &mode : m_modes) for (auto &mode : m_modes)
mode.reset(); mode.reset();
step("the renderer");
GfxRenderer->Shutdown(); GfxRenderer->Shutdown();
m_network.reset(); m_network.reset();
// SafeDelete( simulation::Train ); // SafeDelete( simulation::Train );
step("the scenery");
SafeDelete(simulation::Region); SafeDelete(simulation::Region);
step("the ui and the python workers");
ui_layer::shutdown(); ui_layer::shutdown();
// the python workers detach their GL context on the way out, so they have to be done before the windows they use are destroyed // the python workers detach their GL context on the way out, so they have to be done before the windows they use are destroyed
m_taskqueue.exit(); m_taskqueue.exit();
step("the windows");
for (auto *window : m_windows) for (auto *window : m_windows)
{ {
glfwDestroyWindow(window); glfwDestroyWindow(window);
@@ -713,6 +727,8 @@ void eu07_application::exit()
if (!Global.exec_on_exit.empty()) if (!Global.exec_on_exit.empty())
system(Global.exec_on_exit.c_str()); system(Global.exec_on_exit.c_str());
step("done");
StopLogService();
auto it = Global.threads.find("LogService"); auto it = Global.threads.find("LogService");
if (it != Global.threads.end()) if (it != Global.threads.end())
{ {

View File

@@ -290,9 +290,9 @@ int generate_nodebank_previews(int Argc, char *Argv[])
std::thread logservice(LogService); std::thread logservice(LogService);
auto const finish = [&](int const Result) { auto const finish = [&](int const Result) {
// give the log service time to write out what's left // the log service writes out what's left before it stops
std::this_thread::sleep_for(std::chrono::milliseconds(200));
Global.applicationQuitOrder = true; Global.applicationQuitOrder = true;
StopLogService();
logservice.join(); logservice.join();
return Result; return Result;
}; };

View File

@@ -73,12 +73,21 @@ std::deque<std::string> ErrorStack;
// lock for log stacks // lock for log stacks
std::mutex logMutex; std::mutex logMutex;
// the log is written through the closing of the simulator, to the end
std::atomic<bool> logStop{false};
void StopLogService()
{
logStop = true;
}
void LogService() void LogService()
{ {
while (!Global.applicationQuitOrder) // one more pass after the stop, so what came just before it gets written too
for (bool last{false}; false == last;)
{ {
last = logStop;
{ {
// --- Obsługa InfoStack --- // --- Obsługa InfoStack ---
while (!InfoStack.empty()) while (!InfoStack.empty())

View File

@@ -23,7 +23,9 @@ enum class logtype : unsigned int {
traction = 1 << 9, traction = 1 << 9,
powergrid = 1 << 10, powergrid = 1 << 10,
}; };
// writes the log until StopLogService(), and all of it that came before
void LogService(); void LogService();
void StopLogService();
void WriteLog( const char *str, logtype const Type = logtype::generic, bool isError = false ); void WriteLog( const char *str, logtype const Type = logtype::generic, bool isError = false );
void Error( const std::string &asMessage, bool box = false ); void Error( const std::string &asMessage, bool box = false );
void Error( const char* &asMessage, bool box = false ); void Error( const char* &asMessage, bool box = false );