File indexing completed on 2024-04-06 12:13:08
0001 #ifndef FWCore_SharedMemory_WorkerMonitorThread_h
0002 #define FWCore_SharedMemory_WorkerMonitorThread_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <atomic>
0022 #include <csignal>
0023 #include <functional>
0024 #include <thread>
0025
0026
0027 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0028
0029
0030
0031 namespace edm::shared_memory {
0032 class WorkerMonitorThread {
0033 public:
0034 WorkerMonitorThread() {}
0035 ~WorkerMonitorThread() {
0036 if (not stopRequested_.load()) {
0037 stop();
0038 }
0039 }
0040 WorkerMonitorThread(const WorkerMonitorThread&) = delete;
0041 const WorkerMonitorThread& operator=(const WorkerMonitorThread&) = delete;
0042 WorkerMonitorThread(WorkerMonitorThread&&) = delete;
0043 const WorkerMonitorThread& operator=(WorkerMonitorThread&&) = delete;
0044
0045
0046
0047
0048 void setAction(std::function<void()> iFunc) {
0049 action_ = std::move(iFunc);
0050 actionSet_.store(true);
0051 }
0052
0053 void startThread();
0054
0055
0056 void setupSignalHandling();
0057
0058 void stop();
0059
0060 private:
0061 static void sig_handler(int sig, siginfo_t*, void*);
0062 void run();
0063
0064 std::atomic<bool> stopRequested_ = false;
0065 std::atomic<bool> helperReady_ = false;
0066 std::atomic<bool> actionSet_ = false;
0067 CMS_THREAD_GUARD(actionSet_) std::function<void()> action_;
0068
0069 static std::atomic<int> s_pipeReadEnd;
0070 static std::atomic<int> s_pipeWriteEnd;
0071 static std::atomic<bool> s_helperThreadDone;
0072
0073 std::thread helperThread_;
0074 };
0075 }
0076
0077 #endif