This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 5b29dd0658 ARROW-17844: [C++] Remove atomic shared_ptr compatibility 
functions (#14239)
5b29dd0658 is described below

commit 5b29dd065842ff4f2f5f83b148f9b5f58db5bbbf
Author: Antoine Pitrou <[email protected]>
AuthorDate: Mon Sep 26 19:20:24 2022 +0200

    ARROW-17844: [C++] Remove atomic shared_ptr compatibility functions (#14239)
    
    Authored-by: Antoine Pitrou <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/arrow/array/array_nested.cc    |  10 +--
 cpp/src/arrow/filesystem/s3fs.cc       |   6 +-
 cpp/src/arrow/record_batch.cc          |   5 +-
 cpp/src/arrow/util/atomic_shared_ptr.h | 111 ---------------------------------
 cpp/src/arrow/util/cancel.cc           |  11 ++--
 5 files changed, 14 insertions(+), 129 deletions(-)

diff --git a/cpp/src/arrow/array/array_nested.cc 
b/cpp/src/arrow/array/array_nested.cc
index 70d3a554d1..628259f0f6 100644
--- a/cpp/src/arrow/array/array_nested.cc
+++ b/cpp/src/arrow/array/array_nested.cc
@@ -17,6 +17,7 @@
 
 #include "arrow/array/array_nested.h"
 
+#include <atomic>
 #include <cstddef>
 #include <cstdint>
 #include <memory>
@@ -33,7 +34,6 @@
 #include "arrow/type.h"
 #include "arrow/type_fwd.h"
 #include "arrow/type_traits.h"
-#include "arrow/util/atomic_shared_ptr.h"
 #include "arrow/util/bit_util.h"
 #include "arrow/util/bitmap_generate.h"
 #include "arrow/util/bitmap_ops.h"
@@ -583,7 +583,7 @@ const ArrayVector& StructArray::fields() const {
 }
 
 const std::shared_ptr<Array>& StructArray::field(int i) const {
-  std::shared_ptr<Array> result = internal::atomic_load(&boxed_fields_[i]);
+  std::shared_ptr<Array> result = std::atomic_load(&boxed_fields_[i]);
   if (!result) {
     std::shared_ptr<ArrayData> field_data;
     if (data_->offset != 0 || data_->child_data[i]->length != data_->length) {
@@ -592,7 +592,7 @@ const std::shared_ptr<Array>& StructArray::field(int i) 
const {
       field_data = data_->child_data[i];
     }
     std::shared_ptr<Array> result = MakeArray(field_data);
-    internal::atomic_store(&boxed_fields_[i], result);
+    std::atomic_store(&boxed_fields_[i], result);
     return boxed_fields_[i];
   }
   return boxed_fields_[i];
@@ -847,7 +847,7 @@ std::shared_ptr<Array> UnionArray::field(int i) const {
       static_cast<decltype(boxed_fields_)::size_type>(i) >= 
boxed_fields_.size()) {
     return nullptr;
   }
-  std::shared_ptr<Array> result = internal::atomic_load(&boxed_fields_[i]);
+  std::shared_ptr<Array> result = std::atomic_load(&boxed_fields_[i]);
   if (!result) {
     std::shared_ptr<ArrayData> child_data = data_->child_data[i]->Copy();
     if (mode() == UnionMode::SPARSE) {
@@ -859,7 +859,7 @@ std::shared_ptr<Array> UnionArray::field(int i) const {
       }
     }
     result = MakeArray(child_data);
-    internal::atomic_store(&boxed_fields_[i], result);
+    std::atomic_store(&boxed_fields_[i], result);
   }
   return result;
 }
diff --git a/cpp/src/arrow/filesystem/s3fs.cc b/cpp/src/arrow/filesystem/s3fs.cc
index e75f277034..e0eb460545 100644
--- a/cpp/src/arrow/filesystem/s3fs.cc
+++ b/cpp/src/arrow/filesystem/s3fs.cc
@@ -85,7 +85,6 @@
 #include "arrow/result.h"
 #include "arrow/status.h"
 #include "arrow/util/async_generator.h"
-#include "arrow/util/atomic_shared_ptr.h"
 #include "arrow/util/checked_cast.h"
 #include "arrow/util/future.h"
 #include "arrow/util/io_util.h"
@@ -858,7 +857,7 @@ class RegionResolver {
 
   static Result<std::shared_ptr<RegionResolver>> DefaultInstance() {
     static std::shared_ptr<RegionResolver> instance;
-    auto resolver = arrow::internal::atomic_load(&instance);
+    auto resolver = std::atomic_load(&instance);
     if (resolver) {
       return resolver;
     }
@@ -869,8 +868,7 @@ class RegionResolver {
     // Make sure to always return the same instance even if several threads
     // call DefaultInstance at once.
     std::shared_ptr<RegionResolver> existing;
-    if (arrow::internal::atomic_compare_exchange_strong(&instance, &existing,
-                                                        *maybe_resolver)) {
+    if (std::atomic_compare_exchange_strong(&instance, &existing, 
*maybe_resolver)) {
       return *maybe_resolver;
     } else {
       return existing;
diff --git a/cpp/src/arrow/record_batch.cc b/cpp/src/arrow/record_batch.cc
index 9001a57798..9b93949d39 100644
--- a/cpp/src/arrow/record_batch.cc
+++ b/cpp/src/arrow/record_batch.cc
@@ -30,7 +30,6 @@
 #include "arrow/status.h"
 #include "arrow/table.h"
 #include "arrow/type.h"
-#include "arrow/util/atomic_shared_ptr.h"
 #include "arrow/util/iterator.h"
 #include "arrow/util/logging.h"
 #include "arrow/util/vector.h"
@@ -78,10 +77,10 @@ class SimpleRecordBatch : public RecordBatch {
   }
 
   std::shared_ptr<Array> column(int i) const override {
-    std::shared_ptr<Array> result = internal::atomic_load(&boxed_columns_[i]);
+    std::shared_ptr<Array> result = std::atomic_load(&boxed_columns_[i]);
     if (!result) {
       result = MakeArray(columns_[i]);
-      internal::atomic_store(&boxed_columns_[i], result);
+      std::atomic_store(&boxed_columns_[i], result);
     }
     return result;
   }
diff --git a/cpp/src/arrow/util/atomic_shared_ptr.h 
b/cpp/src/arrow/util/atomic_shared_ptr.h
deleted file mode 100644
index d93ad921db..0000000000
--- a/cpp/src/arrow/util/atomic_shared_ptr.h
+++ /dev/null
@@ -1,111 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-#pragma once
-
-#include <atomic>
-#include <memory>
-#include <utility>
-
-#include "arrow/type_traits.h"
-
-namespace arrow {
-namespace internal {
-
-// Atomic shared_ptr operations only appeared in libstdc++ since GCC 5,
-// emulate them with unsafe ops if unavailable.
-// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57250
-
-template <typename T, typename = void>
-struct is_atomic_load_shared_ptr_available : std::false_type {};
-
-template <typename T>
-struct is_atomic_load_shared_ptr_available<
-    T, void_t<decltype(std::atomic_load(std::declval<const 
std::shared_ptr<T>*>()))>>
-    : std::true_type {};
-
-template <typename T>
-using enable_if_atomic_load_shared_ptr_available =
-    enable_if_t<is_atomic_load_shared_ptr_available<T>::value, T>;
-
-template <typename T>
-using enable_if_atomic_load_shared_ptr_unavailable =
-    enable_if_t<!is_atomic_load_shared_ptr_available<T>::value, T>;
-
-template <class T>
-enable_if_atomic_load_shared_ptr_available<std::shared_ptr<T>> atomic_load(
-    const std::shared_ptr<T>* p) {
-  return std::atomic_load(p);
-}
-
-template <class T>
-enable_if_atomic_load_shared_ptr_unavailable<std::shared_ptr<T>> atomic_load(
-    const std::shared_ptr<T>* p) {
-  return *p;
-}
-
-template <typename T, typename = void>
-struct is_atomic_store_shared_ptr_available : std::false_type {};
-
-template <typename T>
-struct is_atomic_store_shared_ptr_available<
-    T, void_t<decltype(std::atomic_store(std::declval<std::shared_ptr<T>*>(),
-                                         std::declval<std::shared_ptr<T>>()))>>
-    : std::true_type {};
-
-template <typename T>
-using enable_if_atomic_store_shared_ptr_available =
-    enable_if_t<is_atomic_store_shared_ptr_available<T>::value, T>;
-
-template <typename T>
-using enable_if_atomic_store_shared_ptr_unavailable =
-    enable_if_t<!is_atomic_store_shared_ptr_available<T>::value, T>;
-
-template <class T>
-void 
atomic_store(enable_if_atomic_store_shared_ptr_available<std::shared_ptr<T>*> p,
-                  std::shared_ptr<T> r) {
-  std::atomic_store(p, std::move(r));
-}
-
-template <class T>
-void 
atomic_store(enable_if_atomic_store_shared_ptr_unavailable<std::shared_ptr<T>*> 
p,
-                  std::shared_ptr<T> r) {
-  *p = r;
-}
-
-template <class T>
-bool atomic_compare_exchange_strong(
-    enable_if_atomic_store_shared_ptr_available<std::shared_ptr<T>*> p,
-    std::shared_ptr<T>* expected, std::shared_ptr<T> desired) {
-  return std::atomic_compare_exchange_strong(p, expected, std::move(desired));
-}
-
-template <class T>
-bool atomic_compare_exchange_strong(
-    enable_if_atomic_store_shared_ptr_unavailable<std::shared_ptr<T>*> p,
-    std::shared_ptr<T>* expected, std::shared_ptr<T> desired) {
-  if (*p == *expected) {
-    *p = std::move(desired);
-    return true;
-  } else {
-    *expected = *p;
-    return false;
-  }
-}
-
-}  // namespace internal
-}  // namespace arrow
diff --git a/cpp/src/arrow/util/cancel.cc b/cpp/src/arrow/util/cancel.cc
index 874b2c2c88..5fe4ae3e30 100644
--- a/cpp/src/arrow/util/cancel.cc
+++ b/cpp/src/arrow/util/cancel.cc
@@ -23,7 +23,6 @@
 #include <utility>
 
 #include "arrow/result.h"
-#include "arrow/util/atomic_shared_ptr.h"
 #include "arrow/util/io_util.h"
 #include "arrow/util/logging.h"
 #include "arrow/util/visibility.h"
@@ -138,10 +137,10 @@ struct SignalStopState {
     // Before creating a new StopSource, delete any lingering reference to
     // the previous one in the trash can.  See DoHandleSignal() for details.
     EmptyTrashCan();
-    internal::atomic_store(&stop_source_, std::make_shared<StopSource>());
+    std::atomic_store(&stop_source_, std::make_shared<StopSource>());
   }
 
-  void Disable() { internal::atomic_store(&stop_source_, NullSource()); }
+  void Disable() { std::atomic_store(&stop_source_, NullSource()); }
 
   static SignalStopState* instance() { return &instance_; }
 
@@ -149,13 +148,13 @@ struct SignalStopState {
   // For readability
   std::shared_ptr<StopSource> NullSource() { return nullptr; }
 
-  void EmptyTrashCan() { internal::atomic_store(&trash_can_, NullSource()); }
+  void EmptyTrashCan() { std::atomic_store(&trash_can_, NullSource()); }
 
   static void HandleSignal(int signum) { instance_.DoHandleSignal(signum); }
 
   void DoHandleSignal(int signum) {
     // async-signal-safe code only
-    auto source = internal::atomic_load(&stop_source_);
+    auto source = std::atomic_load(&stop_source_);
     if (source) {
       source->RequestStopFromSignal(signum);
       // Disable() may have been called in the meantime, but we can't
@@ -177,7 +176,7 @@ struct SignalStopState {
       // This case should be sufficiently unlikely, but we cannot entirely
       // rule it out.  The problem might be solved properly with a lock-free
       // linked list of StopSources.
-      internal::atomic_store(&trash_can_, std::move(source));
+      std::atomic_store(&trash_can_, std::move(source));
     }
     ReinstateSignalHandler(signum, &HandleSignal);
   }

Reply via email to