| 136 | } |
| 137 | |
| 138 | Status RegisterHandlers(const std::vector<int>& signals) { |
| 139 | std::lock_guard<std::mutex> lock(mutex_); |
| 140 | if (!saved_handlers_.empty()) { |
| 141 | return Status::Invalid("Signal handlers already registered"); |
| 142 | } |
| 143 | if (!self_pipe_) { |
| 144 | // Make sure the self-pipe is initialized |
| 145 | // (NOTE: avoid std::atomic_is_lock_free() which may require libatomic) |
| 146 | #if ATOMIC_POINTER_LOCK_FREE != 2 |
| 147 | return Status::NotImplemented( |
| 148 | "Cannot setup signal StopSource because atomic pointers are not " |
| 149 | "lock-free on this platform"); |
| 150 | #else |
| 151 | ARROW_ASSIGN_OR_RAISE(self_pipe_, SelfPipe::Make(/*signal_safe=*/true)); |
| 152 | #endif |
| 153 | } |
| 154 | if (!signal_receiving_thread_) { |
| 155 | // Spawn thread for receiving signals |
| 156 | SpawnSignalReceivingThread(); |
| 157 | } |
| 158 | self_pipe_ptr_.store(self_pipe_.get()); |
| 159 | for (int signum : signals) { |
| 160 | ARROW_ASSIGN_OR_RAISE(auto handler, |
| 161 | SetSignalHandler(signum, SignalHandler{&HandleSignal})); |
| 162 | saved_handlers_.push_back({signum, handler}); |
| 163 | } |
| 164 | return Status::OK(); |
| 165 | } |
| 166 | |
| 167 | void UnregisterHandlers() { |
| 168 | std::lock_guard<std::mutex> lock(mutex_); |
no test coverage detected