diff options
author | falkTX <falktx@falktx.com> | 2022-04-15 20:02:58 +0100 |
---|---|---|
committer | falkTX <falktx@falktx.com> | 2022-04-15 20:02:58 +0100 |
commit | 45042beac57c1a7ca35a91fcf15ad41c9b66daa4 (patch) | |
tree | 1a6e188e88f63a94a8730a4869bd0913d5b42dc5 /macosx/JackMachSemaphore.mm | |
parent | 5aa5861af0cd8557be7431c9677c5dcaa78ec18d (diff) | |
download | jack2-45042beac57c1a7ca35a91fcf15ad41c9b66daa4.tar.gz |
Make JackMachSemaphore more robust, dont use thread_terminate
Fixes #841
Diffstat (limited to 'macosx/JackMachSemaphore.mm')
-rw-r--r-- | macosx/JackMachSemaphore.mm | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/macosx/JackMachSemaphore.mm b/macosx/JackMachSemaphore.mm index 1905e04c..c28fe5ab 100644 --- a/macosx/JackMachSemaphore.mm +++ b/macosx/JackMachSemaphore.mm @@ -305,7 +305,7 @@ bool JackMachSemaphore::ConnectInput(const char* client_name, const char* server } else { fSemaphore = msg.hdr.msgh_remote_port; - jack_log("JackMachSemaphore::Connect: OK, name = %s ", fName); + jack_log("JackMachSemaphore::Connect: OK, name = %s", fName); return true; } } @@ -353,17 +353,22 @@ bool JackMachSemaphore::Disconnect() // Server side : destroy the JackGlobals void JackMachSemaphore::Destroy() { + const mach_port_t task = mach_task_self(); kern_return_t res; - mach_port_t task = mach_task_self(); if (fSemaphore == MACH_PORT_NULL) { jack_error("JackMachSemaphore::Destroy semaphore is MACH_PORT_NULL; already destroyed?"); return; } + if (fSemServer && fSemServer->Invalidate()) { + fServicePort = MACH_PORT_NULL; + fSemaphore = MACH_PORT_NULL; + } + if (fThreadSemServer) { - if (fThreadSemServer->Kill() < 0) { - jack_error("JackMachSemaphore::Destroy failed to kill semaphore server thread..."); + if (fThreadSemServer->Stop() < 0) { + jack_error("JackMachSemaphore::Destroy failed to stop semaphore server thread..."); // Oh dear. How sad. Never mind. } @@ -378,16 +383,20 @@ void JackMachSemaphore::Destroy() delete server; } - if ((res = mach_port_destroy(task, fServicePort)) != KERN_SUCCESS) { - jack_mach_error(res, "failed to destroy IPC port"); - } else { - fServicePort = MACH_PORT_NULL; + if (fServicePort != MACH_PORT_NULL) { + if ((res = mach_port_destroy(task, fServicePort)) != KERN_SUCCESS) { + jack_mach_error(res, "failed to destroy IPC port"); + } else { + fServicePort = MACH_PORT_NULL; + } } - if ((res = semaphore_destroy(mach_task_self(), fSemaphore)) != KERN_SUCCESS) { - jack_mach_error(res, "failed to destroy semaphore"); - } else { - fSemaphore = MACH_PORT_NULL; + if (fSemaphore != MACH_PORT_NULL) { + if ((res = semaphore_destroy(mach_task_self(), fSemaphore)) != KERN_SUCCESS) { + jack_mach_error(res, "failed to destroy semaphore"); + } else { + fSemaphore = MACH_PORT_NULL; + } } jack_log("JackMachSemaphore::Destroy: OK, name = %s", fName); |