summaryrefslogtreecommitdiff
path: root/lib/shmem.cpp
diff options
context:
space:
mode:
authorDave Hibberd <hibby@debian.org>2026-10-20 22:35:06 +0100
committerDave Hibberd <hibby@debian.org>2026-10-20 22:35:06 +0100
commit82ebb1ed1af30cee4dfbb1c628431d32885a00e0 (patch)
tree1a1f782d3e576b758be0bc61171574a7cd8f2376 /lib/shmem.cpp
parent061658210acb6425517733ea012dda803a7f72a1 (diff)
parent61d684922b0f1c8455cc60eb3d123df058c9e1f5 (diff)
Merge tag 'debian/3.3.0_beta2+dfsg-1' into hibbian/trixie-backports
tagging wsjtx 3.3.0~beta2+dfsg-1
Diffstat (limited to 'lib/shmem.cpp')
-rw-r--r--lib/shmem.cpp58
1 files changed, 45 insertions, 13 deletions
diff --git a/lib/shmem.cpp b/lib/shmem.cpp
index 7d1783d6..113babfc 100644
--- a/lib/shmem.cpp
+++ b/lib/shmem.cpp
@@ -1,18 +1,50 @@
-#include <QSharedMemory>
-#include <QLatin1String>
+#include "NativeSharedMemory.hpp"
+#include "DecoderWorkerLock.hpp"
+#include <memory>
+#include <cstdio>
+#include <exception>
-// Multiple instances: KK1D, 17 Jul 2013
-QSharedMemory shmem;
-
-struct jt9com;
+namespace
+{
+ // Release the mapping before the lifetime lock, after all Fortran cleanup.
+ std::unique_ptr<DecoderWorkerLock> worker_lock;
+ NativeSharedMemory shmem;
+}
-// C wrappers for a QSharedMemory class instance
extern "C"
{
- bool shmem_create (int nsize) {return shmem.create(nsize);}
- void shmem_setkey (char * const mykey) {shmem.setKey(QLatin1String{mykey});}
- bool shmem_attach () {return shmem.attach();}
- int shmem_size () {return static_cast<int> (shmem.size());}
- struct jt9com * shmem_address () {return reinterpret_cast<struct jt9com *>(shmem.data());}
- bool shmem_detach () {return shmem.detach();}
+ bool shmem_lock_worker (char const * path) noexcept
+ {
+ try
+ {
+ worker_lock.reset (new DecoderWorkerLock {path});
+ if (worker_lock->tryLock ()) return true;
+ std::fprintf (stderr, "Decoder worker lock: %s\n", worker_lock->errorString ().c_str ());
+ }
+ catch (...)
+ {
+ std::fputs ("Decoder worker lock: initialization failed\n", stderr);
+ }
+ return false;
+ }
+
+ bool shmem_attach (char const * name) noexcept
+ {
+ try
+ {
+ if (shmem.attach (name)) return true;
+ std::fprintf (stderr, "Decoder shared memory: %s\n", shmem.errorString ().c_str ());
+ }
+ catch (std::exception const& error)
+ {
+ std::fprintf (stderr, "Decoder shared memory: %s\n", error.what ());
+ }
+ catch (...)
+ {
+ std::fputs ("Decoder shared memory: unexpected attachment failure\n", stderr);
+ }
+ return false;
+ }
+ std::size_t shmem_size () noexcept {return shmem.size ();}
+ void * shmem_address () noexcept {return shmem.data ();}
}