From 8fd4ef990f00d9a28067ff56ae79bf2eec64419e Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sun, 28 Apr 2024 20:26:08 +1000 Subject: [PATCH] Update sync.d * Fix TaskPool compatibility with minimum DMD and LDC versions --- src/sync.d | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/sync.d b/src/sync.d index 5d3e1e97..cced0f73 100644 --- a/src/sync.d +++ b/src/sync.d @@ -7,6 +7,7 @@ import core.thread; import core.time; import std.algorithm; import std.array; +import std.compiler; import std.concurrency; import std.container.rbtree; import std.conv; @@ -304,14 +305,21 @@ class SyncEngine { // The destructor should only clean up resources owned directly by this instance ~this() { - processPool.finish(true); + shutdownProcessPool(); } // Initialise the Sync Engine class bool initialise() { // Control whether the worker threads are daemon threads. A daemon thread is automatically terminated when all non-daemon threads have terminated. - processPool.isDaemon(true); - + if (__VERSION__ < 2098) { + // LDC version less than 1.28.0 is being used + // DMD version less than 2.098.0 is being used + processPool.isDaemon(false); // Not a daemon thread + } else { + // Normal TaskPool threading + processPool.isDaemon(true); // daemon thread + } + // Create a new instance of the OneDrive API OneDriveApi oneDriveApiInstance; oneDriveApiInstance = new OneDriveApi(appConfig); @@ -385,9 +393,26 @@ class SyncEngine { // Shutdown the sync engine, wait for anything in processPool to complete void shutdown() { addLogEntry("SYNC-ENGINE: Waiting for all internal threads to complete", ["debug"]); - processPool.finish(true); + shutdownProcessPool(); } + void shutdownProcessPool() { + // TaskPool needs specific shutdown based on compiler version otherwise this causes a segfault + addLogEntry("COMPILER VERSION: " ~ to!string(__VERSION__), ["debug"]); + + // We must be using 2098 or greater + if (__VERSION__ < 2098) { + // Compromised TaskPool shutdown process + // LDC version less than 1.28.0 is being used + // DMD version less than 2.098.0 is being used + processPool.stop(); + processPool.finish(); + } else { + // Normal TaskPool shutdown process + processPool.finish(true); + } + } + // Get Default Drive Details for this Account void getDefaultDriveDetails() {