| 1245 | explicit SelfPipeImpl(bool signal_safe) : signal_safe_(signal_safe) {} |
| 1246 | |
| 1247 | Status Init() { |
| 1248 | ARROW_ASSIGN_OR_RAISE(pipe_, CreatePipe()); |
| 1249 | if (signal_safe_) { |
| 1250 | if (!please_shutdown_.is_lock_free()) { |
| 1251 | return Status::IOError("Cannot use non-lock-free atomic in a signal handler"); |
| 1252 | } |
| 1253 | // We cannot afford blocking writes in a signal handler |
| 1254 | RETURN_NOT_OK(SetPipeFileDescriptorNonBlocking(pipe_.wfd.fd())); |
| 1255 | } |
| 1256 | |
| 1257 | atfork_handler_ = std::make_shared<AtForkHandler>( |
| 1258 | /*before=*/ |
| 1259 | [weak_self = std::weak_ptr<SelfPipeImpl>(shared_from_this())] { |
| 1260 | auto self = weak_self.lock(); |
| 1261 | if (self) { |
| 1262 | self->BeforeFork(); |
| 1263 | } |
| 1264 | return self; |
| 1265 | }, |
| 1266 | /*parent_after=*/ |
| 1267 | [](std::any token) { |
| 1268 | auto self = std::any_cast<std::shared_ptr<SelfPipeImpl>>(std::move(token)); |
| 1269 | self->ParentAfterFork(); |
| 1270 | }, |
| 1271 | /*child_after=*/ |
| 1272 | [](std::any token) { |
| 1273 | auto self = std::any_cast<std::shared_ptr<SelfPipeImpl>>(std::move(token)); |
| 1274 | self->ChildAfterFork(); |
| 1275 | }); |
| 1276 | RegisterAtFork(atfork_handler_); |
| 1277 | |
| 1278 | return Status::OK(); |
| 1279 | } |
| 1280 | |
| 1281 | Result<uint64_t> Wait() override { |
| 1282 | if (pipe_.rfd.closed()) { |
no test coverage detected