Skip to content

Commit

Permalink
minor optimize cancel and thread pool
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Nov 22, 2024
1 parent ae497bf commit 2bbe726
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/cancel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct StopSourceImpl {
Status cancel_error_;
};

StopSource::StopSource() : impl_(new StopSourceImpl) {}
StopSource::StopSource() : impl_(std::make_shared<StopSourceImpl>()) {}

StopSource::~StopSource() = default;

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/cancel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}

Expand Down
7 changes: 5 additions & 2 deletions cpp/src/arrow/util/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -671,10 +674,10 @@ Result<std::shared_ptr<ThreadPool>> ThreadPool::Make(int threads) {

Result<std::shared_ptr<ThreadPool>> ThreadPool::MakeEternal(int threads) {
ARROW_ASSIGN_OR_RAISE(auto pool, Make(threads));
# ifdef _WIN32
// On Windows, the ThreadPool destructor may be called after non-main threads
// have been killed by the OS, and hang in a condition variable.
// On Unix, we want to avoid leak reports by Valgrind.
# ifdef _WIN32
pool->shutdown_on_destroy_ = false;
# endif
return pool;
Expand Down

0 comments on commit 2bbe726

Please sign in to comment.