![]() |
|
|||
File indexing completed on 2025-08-28 08:27:07
0001 // Licensed to the Apache Software Foundation (ASF) under one 0002 // or more contributor license agreements. See the NOTICE file 0003 // distributed with this work for additional information 0004 // regarding copyright ownership. The ASF licenses this file 0005 // to you under the Apache License, Version 2.0 (the 0006 // "License"); you may not use this file except in compliance 0007 // with the License. You may obtain a copy of the License at 0008 // 0009 // http://www.apache.org/licenses/LICENSE-2.0 0010 // 0011 // Unless required by applicable law or agreed to in writing, 0012 // software distributed under the License is distributed on an 0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 0014 // KIND, either express or implied. See the License for the 0015 // specific language governing permissions and limitations 0016 // under the License. 0017 0018 #pragma once 0019 0020 #include <functional> 0021 #include <memory> 0022 #include <string> 0023 #include <vector> 0024 0025 #include "arrow/status.h" 0026 #include "arrow/type_fwd.h" 0027 #include "arrow/util/macros.h" 0028 #include "arrow/util/visibility.h" 0029 0030 namespace arrow { 0031 0032 class StopToken; 0033 0034 struct StopSourceImpl; 0035 0036 /// EXPERIMENTAL 0037 class ARROW_EXPORT StopSource { 0038 public: 0039 StopSource(); 0040 ~StopSource(); 0041 0042 // Consumer API (the side that stops) 0043 void RequestStop(); 0044 void RequestStop(Status error); 0045 // Async-signal-safe. TODO Deprecate this? 0046 void RequestStopFromSignal(int signum); 0047 0048 StopToken token(); 0049 0050 // For internal use only 0051 void Reset(); 0052 0053 protected: 0054 std::shared_ptr<StopSourceImpl> impl_; 0055 }; 0056 0057 /// EXPERIMENTAL 0058 class ARROW_EXPORT StopToken { 0059 public: 0060 // Public for Cython 0061 StopToken() = default; 0062 0063 explicit StopToken(std::shared_ptr<StopSourceImpl> impl) : impl_(std::move(impl)) {} 0064 0065 // A trivial token that never propagates any stop request 0066 static StopToken Unstoppable() { return StopToken(); } 0067 0068 /// \brief Check if the stop source has been cancelled. 0069 /// 0070 /// Producers should call this method, whenever convenient, to check and 0071 /// see if they should stop producing early (i.e. have been cancelled). 0072 /// Failure to call this method often enough will lead to an unresponsive 0073 /// cancellation. 0074 /// 0075 /// This is part of the producer API (the side that gets asked to stop) 0076 /// This method is thread-safe 0077 /// 0078 /// \return An OK status if the stop source has not been cancelled or a 0079 /// cancel error if the source has been cancelled. 0080 Status Poll() const; 0081 bool IsStopRequested() const; 0082 0083 protected: 0084 std::shared_ptr<StopSourceImpl> impl_; 0085 }; 0086 0087 /// EXPERIMENTAL: Set a global StopSource that can receive signals 0088 /// 0089 /// The only allowed order of calls is the following: 0090 /// - SetSignalStopSource() 0091 /// - any number of pairs of (RegisterCancellingSignalHandler, 0092 /// UnregisterCancellingSignalHandler) calls 0093 /// - ResetSignalStopSource() 0094 /// 0095 /// Beware that these settings are process-wide. Typically, only one 0096 /// thread should call these APIs, even in a multithreaded setting. 0097 ARROW_EXPORT 0098 Result<StopSource*> SetSignalStopSource(); 0099 0100 /// EXPERIMENTAL: Reset the global signal-receiving StopSource 0101 /// 0102 /// This will invalidate the pointer returned by SetSignalStopSource. 0103 ARROW_EXPORT 0104 void ResetSignalStopSource(); 0105 0106 /// EXPERIMENTAL: Register signal handler triggering the signal-receiving StopSource 0107 /// 0108 /// Note that those handlers are automatically un-registered in a fork()ed process, 0109 /// therefore the child process will need to call RegisterCancellingSignalHandler() 0110 /// if desired. 0111 ARROW_EXPORT 0112 Status RegisterCancellingSignalHandler(const std::vector<int>& signals); 0113 0114 /// EXPERIMENTAL: Unregister signal handler set up by RegisterCancellingSignalHandler 0115 ARROW_EXPORT 0116 void UnregisterCancellingSignalHandler(); 0117 0118 } // namespace arrow
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |