pitrou commented on code in PR #13635:
URL: https://github.com/apache/arrow/pull/13635#discussion_r981254138
##########
r/src/safe-call-into-r.h:
##########
@@ -55,9 +58,51 @@ class MainRThread {
bool IsInitialized() { return initialized_; }
+ void Deinitialize() {
+ initialized_ = false;
+ DisableSignalStopSource();
+ }
+
// Check if the current thread is the main R thread
bool IsMainThread() { return initialized_ && std::this_thread::get_id() ==
thread_id_; }
+ arrow::StopToken GetStopToken() {
+ if (SignalStopSourceEnabled()) {
+ return stop_source_->token();
+ } else {
+ return arrow::StopToken::Unstoppable();
+ }
+ }
+
+ bool SignalStopSourceEnabled() { return stop_source_ != nullptr; }
+
+ void EnableSignalStopSource() {
+ // Try to set up the stop source. If another library linking to
+ // the same libarrow shared object has already done this, this call
+ // will fail (which is OK, we just don't get the ability to cancel)
+ if (!SignalStopSourceEnabled()) {
+ auto maybe_stop_source = arrow::SetSignalStopSource();
+ if (maybe_stop_source.ok()) {
+ stop_source_ = maybe_stop_source.ValueUnsafe();
+ } else {
+ cpp11::warning("Failed to enable user cancellation: %s",
+ maybe_stop_source.status().message().c_str());
+ }
+ }
+ }
+
+ void DisableSignalStopSource() {
+ if (SignalStopSourceEnabled()) {
Review Comment:
Should you test `stop_source_` instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]