diff --git a/src/log.d b/src/log.d index 7ff95e1cf..30af235c3 100644 --- a/src/log.d +++ b/src/log.d @@ -7,12 +7,16 @@ import std.file; import std.datetime; import std.concurrency; import std.typecons; +import core.sync.mutex; import core.sync.condition; import core.thread; import std.format; import std.string; import std.conv; +// What other modules that we have created do we need to import? +import util; + version(Notifications) { import dnotify; } @@ -54,8 +58,10 @@ class LogBuffer { } ~this() { - if (!isRunning) { - bufferLock.unlock(); + if (!isRunning) { + if (exitHandlerTriggered) { + bufferLock.unlock(); + } } } @@ -80,7 +86,10 @@ class LogBuffer { } // Flush any remaining logs - flushBuffer(); + flushBuffer(); + + // Sleep for a while to avoid busy-waiting + Thread.sleep(dur!"msecs"(100)); // Adjust the sleep duration as needed // Exit scopes scope(exit) { diff --git a/src/util.d b/src/util.d index 5da87b9da..dc915b96f 100644 --- a/src/util.d +++ b/src/util.d @@ -1287,9 +1287,11 @@ void setupExitScopeSignalHandler() { // Catch any SIGSEV generated by the exit scopes extern(C) nothrow @nogc @system void exitScopeSignalHandler(int signo) { if (signo == SIGSEGV) { - // Caught a SIGSEG but everything was shutdown cleanly ..... - //printf("Caught a SIGSEG but everything was shutdown cleanly .....\n"); - exit(0); + assumeNoGC ( () { + // Caught a SIGSEGV but everything was shutdown cleanly ..... + //printf("Caught a SIGSEGV but everything was shutdown cleanly .....\n"); + exit(0); + })(); } }