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

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


The following commit(s) were added to refs/heads/main by this push:
     new 26b08a3246 GH-44811: [C++] minor optimize cancel and thread pool 
(#44812)
26b08a3246 is described below

commit 26b08a3246799d65937d9764784156a0d301ea42
Author: mwish <[email protected]>
AuthorDate: Wed Nov 27 18:29:13 2024 +0800

    GH-44811: [C++] minor optimize cancel and thread pool (#44812)
    
    
    
    ### Rationale for this change
    
    Minor code optimization for ThreadPool and cancel
    
    ### What changes are included in this PR?
    
    Minor code optimization for ThreadPool and cancel
    
    ### Are these changes tested?
    
    Covered by existing
    
    ### Are there any user-facing changes?
    
    no
    
    * GitHub Issue: #44811
    
    Authored-by: mwish <[email protected]>
    Signed-off-by: mwish <[email protected]>
---
 cpp/src/arrow/util/cancel.cc      | 2 +-
 cpp/src/arrow/util/cancel.h       | 2 +-
 cpp/src/arrow/util/thread_pool.cc | 5 ++++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/cpp/src/arrow/util/cancel.cc b/cpp/src/arrow/util/cancel.cc
index b3a0c1f92c..242852f46b 100644
--- a/cpp/src/arrow/util/cancel.cc
+++ b/cpp/src/arrow/util/cancel.cc
@@ -50,7 +50,7 @@ struct StopSourceImpl {
   Status cancel_error_;
 };
 
-StopSource::StopSource() : impl_(new StopSourceImpl) {}
+StopSource::StopSource() : impl_(std::make_shared<StopSourceImpl>()) {}
 
 StopSource::~StopSource() = default;
 
diff --git a/cpp/src/arrow/util/cancel.h b/cpp/src/arrow/util/cancel.h
index f0d704b2ce..863b2c4e8c 100644
--- a/cpp/src/arrow/util/cancel.h
+++ b/cpp/src/arrow/util/cancel.h
@@ -58,7 +58,7 @@ class ARROW_EXPORT StopSource {
 class ARROW_EXPORT StopToken {
  public:
   // Public for Cython
-  StopToken() {}
+  StopToken() = default;
 
   explicit StopToken(std::shared_ptr<StopSourceImpl> impl) : 
impl_(std::move(impl)) {}
 
diff --git a/cpp/src/arrow/util/thread_pool.cc 
b/cpp/src/arrow/util/thread_pool.cc
index d59d1f20de..8aa6d54889 100644
--- a/cpp/src/arrow/util/thread_pool.cc
+++ b/cpp/src/arrow/util/thread_pool.cc
@@ -460,7 +460,10 @@ static void WorkerLoop(std::shared_ptr<ThreadPool::State> 
state,
             std::move(task.stop_callback)(stop_token->Poll());
           }
         }
-        ARROW_UNUSED(std::move(task));  // release resources before waiting 
for lock
+        {
+          auto tmp_task = std::move(task);  // release resources before 
waiting for lock
+          ARROW_UNUSED(tmp_task);
+        }
         lock.lock();
       }
       if (ARROW_PREDICT_FALSE(--state->tasks_queued_or_running_ == 0)) {

Reply via email to