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

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


The following commit(s) were added to refs/heads/master by this push:
     new 82069515eb5 [Chore](compile) add atomic_shared_ptr under libcpp 
(#55860)
82069515eb5 is described below

commit 82069515eb58778fc1a2667d9af3bab69545843a
Author: Pxl <[email protected]>
AuthorDate: Thu Sep 11 18:41:58 2025 +0800

    [Chore](compile) add atomic_shared_ptr under libcpp (#55860)
    
    1. add atomic_shared_ptr under libcpp
    2. fix some mac compile fail
---
 be/src/common/atomic_shared_ptr.h            | 62 ++++++++++++++++++++++++++++
 be/src/common/daemon.cpp                     |  2 +-
 be/src/io/cache/block_file_cache_factory.cpp | 11 ++++-
 be/src/olap/tablet.h                         |  5 ++-
 be/src/pipeline/pipeline_tracing.cpp         |  4 +-
 be/src/pipeline/pipeline_tracing.h           |  3 +-
 be/src/util/debug_points.cpp                 |  9 ++--
 be/src/util/debug_points.h                   |  3 +-
 be/src/util/disk_info_mac.cpp                |  2 +-
 be/src/util/mem_info.h                       |  2 +-
 10 files changed, 85 insertions(+), 18 deletions(-)

diff --git a/be/src/common/atomic_shared_ptr.h 
b/be/src/common/atomic_shared_ptr.h
new file mode 100644
index 00000000000..54872dc7e3a
--- /dev/null
+++ b/be/src/common/atomic_shared_ptr.h
@@ -0,0 +1,62 @@
+// 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>
+
+namespace doris {
+#ifndef USE_LIBCPP
+template <typename T>
+using atomic_shared_ptr = std::atomic<std::shared_ptr<T>>;
+#else
+// libcpp do not support atomic<std::shared_ptr<T>>
+// so we implement a simple version of atomic_shared_ptr here
+template <typename T>
+class atomic_shared_ptr {
+public:
+    atomic_shared_ptr() noexcept : _ptr(nullptr) {}
+    atomic_shared_ptr(std::shared_ptr<T> desired) noexcept : _ptr(desired) {}
+    atomic_shared_ptr(const atomic_shared_ptr&) = delete;
+    atomic_shared_ptr& operator=(const atomic_shared_ptr&) = delete;
+
+    void store(std::shared_ptr<T> desired,
+               std::memory_order order = std::memory_order_seq_cst) noexcept {
+        std::atomic_store_explicit(&_ptr, desired, order);
+    }
+
+    std::shared_ptr<T> load(std::memory_order order = 
std::memory_order_seq_cst) const noexcept {
+        return std::atomic_load_explicit(&_ptr, order);
+    }
+
+    bool compare_exchange_strong(std::shared_ptr<T>& expected, 
std::shared_ptr<T> desired,
+                                 std::memory_order success = 
std::memory_order_seq_cst,
+                                 std::memory_order failure = 
std::memory_order_seq_cst) noexcept {
+        return std::atomic_compare_exchange_strong_explicit(&_ptr, &expected, 
desired, success,
+                                                            failure);
+    }
+
+    void exchange(std::shared_ptr<T> desired,
+                  std::memory_order order = std::memory_order_seq_cst) 
noexcept {
+        std::atomic_exchange_explicit(&_ptr, desired, order);
+    }
+
+private:
+    mutable std::shared_ptr<T> _ptr;
+};
+#endif
+} // namespace doris
\ No newline at end of file
diff --git a/be/src/common/daemon.cpp b/be/src/common/daemon.cpp
index a5f01ed1975..a17380c245f 100644
--- a/be/src/common/daemon.cpp
+++ b/be/src/common/daemon.cpp
@@ -166,7 +166,7 @@ void Daemon::tcmalloc_gc_thread() {
             }
         }
 
-        int release_rate_index = memory_pressure / 10;
+        int release_rate_index = int(memory_pressure) / 10;
         double release_rate = 1.0;
         if (release_rate_index >= sizeof(release_rates) / 
sizeof(release_rates[0])) {
             release_rate = 2000.0;
diff --git a/be/src/io/cache/block_file_cache_factory.cpp 
b/be/src/io/cache/block_file_cache_factory.cpp
index 1d29196c240..4112902aa2b 100644
--- a/be/src/io/cache/block_file_cache_factory.cpp
+++ b/be/src/io/cache/block_file_cache_factory.cpp
@@ -158,13 +158,20 @@ FileCacheFactory::get_query_context_holders(const 
TUniqueId& query_id) {
 
 std::string FileCacheFactory::clear_file_caches(bool sync) {
     std::vector<std::string> results(_caches.size());
-
+#ifndef USE_LIBCPP
     std::for_each(std::execution::par, _caches.begin(), _caches.end(), 
[&](const auto& cache) {
         size_t index = &cache - &_caches[0];
         results[index] =
                 sync ? cache->clear_file_cache_directly() : 
cache->clear_file_cache_async();
     });
-
+#else
+    // libcpp do not support std::execution::par
+    std::for_each(_caches.begin(), _caches.end(), [&](const auto& cache) {
+        size_t index = &cache - &_caches[0];
+        results[index] =
+                sync ? cache->clear_file_cache_directly() : 
cache->clear_file_cache_async();
+    });
+#endif
     std::stringstream ss;
     for (const auto& result : results) {
         ss << result << "\n";
diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h
index 7e4fd0e237e..be09bb64320 100644
--- a/be/src/olap/tablet.h
+++ b/be/src/olap/tablet.h
@@ -34,6 +34,7 @@
 #include <utility>
 #include <vector>
 
+#include "common/atomic_shared_ptr.h"
 #include "common/config.h"
 #include "common/status.h"
 #include "olap/base_tablet.h"
@@ -356,7 +357,7 @@ public:
     std::tuple<int64_t, int64_t> get_visible_version_and_time() const;
 
     void set_visible_version(const std::shared_ptr<const VersionWithTime>& 
visible_version) {
-        std::atomic_store_explicit(&_visible_version, visible_version, 
std::memory_order_relaxed);
+        _visible_version.store(visible_version);
     }
 
     bool should_fetch_from_peer();
@@ -644,7 +645,7 @@ private:
     int64_t _io_error_times = 0;
 
     // partition's visible version. it sync from fe, but not real-time.
-    std::atomic<std::shared_ptr<const VersionWithTime>> _visible_version;
+    atomic_shared_ptr<const VersionWithTime> _visible_version;
 
     std::atomic_bool _is_full_compaction_running = false;
 
diff --git a/be/src/pipeline/pipeline_tracing.cpp 
b/be/src/pipeline/pipeline_tracing.cpp
index c526e0d77c7..b58649beb2f 100644
--- a/be/src/pipeline/pipeline_tracing.cpp
+++ b/be/src/pipeline/pipeline_tracing.cpp
@@ -59,9 +59,7 @@ void 
PipelineTracerContext::_update(std::function<void(QueryTracesMap&)>&& handl
     while (true) {
         auto new_map = std::make_shared<QueryTracesMap>(*map_ptr);
         handler(*new_map);
-        if (std::atomic_compare_exchange_strong_explicit(&_data, &map_ptr, 
new_map,
-                                                         
std::memory_order_relaxed,
-                                                         
std::memory_order_relaxed)) {
+        if (_data.compare_exchange_strong(map_ptr, new_map)) {
             break;
         }
     }
diff --git a/be/src/pipeline/pipeline_tracing.h 
b/be/src/pipeline/pipeline_tracing.h
index 0230e4f0092..fdcefc59a1e 100644
--- a/be/src/pipeline/pipeline_tracing.h
+++ b/be/src/pipeline/pipeline_tracing.h
@@ -25,6 +25,7 @@
 #include <cstdint>
 #include <filesystem>
 
+#include "common/atomic_shared_ptr.h"
 #include "common/config.h"
 #include "util/hash_util.hpp" // IWYU pragma: keep
 #include "util/thrift_util.h"
@@ -85,7 +86,7 @@ private:
 
     std::filesystem::path _log_dir = fmt::format("{}/pipe_tracing", 
getenv("LOG_DIR"));
 
-    std::atomic<std::shared_ptr<QueryTracesMap>> _data;
+    atomic_shared_ptr<QueryTracesMap> _data;
     std::mutex _tg_lock; //TODO: use an lockfree DS
     phmap::flat_hash_map<TUniqueId, uint64_t>
             _id_to_workload_group; // save query's workload group number
diff --git a/be/src/util/debug_points.cpp b/be/src/util/debug_points.cpp
index 2ed4d91706a..d8e2816db5c 100644
--- a/be/src/util/debug_points.cpp
+++ b/be/src/util/debug_points.cpp
@@ -80,18 +80,15 @@ void 
DebugPoints::update(std::function<void(DebugPointMap&)>&& handler) {
     while (true) {
         auto new_points = std::make_shared<DebugPointMap>(*old_points);
         handler(*new_points);
-        if (std::atomic_compare_exchange_strong_explicit(
-                    &_debug_points, &old_points,
-                    std::static_pointer_cast<const DebugPointMap>(new_points),
-                    std::memory_order_relaxed, std::memory_order_relaxed)) {
+        if (_debug_points.compare_exchange_strong(
+                    old_points, std::static_pointer_cast<const 
DebugPointMap>(new_points))) {
             break;
         }
     }
 }
 
 void DebugPoints::clear() {
-    std::atomic_store_explicit(&_debug_points, std::make_shared<const 
DebugPointMap>(),
-                               std::memory_order_relaxed);
+    _debug_points.store(std::make_shared<const DebugPointMap>());
     LOG(INFO) << "clear debug points";
 }
 
diff --git a/be/src/util/debug_points.h b/be/src/util/debug_points.h
index a58ab93e71c..162dfc34263 100644
--- a/be/src/util/debug_points.h
+++ b/be/src/util/debug_points.h
@@ -27,6 +27,7 @@
 #include <thread>
 #include <type_traits>
 
+#include "common/atomic_shared_ptr.h"
 #include "common/compiler_util.h"
 #include "common/config.h"
 #include "fmt/format.h"
@@ -189,7 +190,7 @@ private:
     void update(std::function<void(DebugPointMap&)>&& handler);
 
 private:
-    std::atomic<std::shared_ptr<const DebugPointMap>> _debug_points;
+    atomic_shared_ptr<const DebugPointMap> _debug_points;
 };
 
 } // namespace doris
diff --git a/be/src/util/disk_info_mac.cpp b/be/src/util/disk_info_mac.cpp
index 7ee6426b6db..ef35a01cec9 100644
--- a/be/src/util/disk_info_mac.cpp
+++ b/be/src/util/disk_info_mac.cpp
@@ -74,7 +74,7 @@ void DiskInfo::get_device_names() {
             auto it = major_to_disk_id.find(major(dev));
             int disk_id;
             if (it == major_to_disk_id.end()) {
-                disk_id = _s_disks.size();
+                disk_id = int(_s_disks.size());
                 major_to_disk_id[major(dev)] = disk_id;
 
                 std::string name = "disk" + std::to_string(disk_id);
diff --git a/be/src/util/mem_info.h b/be/src/util/mem_info.h
index cc72c3ed401..4f0ddd2f57b 100644
--- a/be/src/util/mem_info.h
+++ b/be/src/util/mem_info.h
@@ -54,7 +54,7 @@ public:
 #if !defined(__APPLE__) || !defined(_POSIX_C_SOURCE)
         return getpagesize();
 #else
-        return vm_page_size;
+        return int(vm_page_size);
 #endif
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to