From 83400a0b52a996a95f1f2562b2b0ffef8f356927 Mon Sep 17 00:00:00 2001 From: Attila Uygun Date: Mon, 12 Jun 2023 14:52:44 +0200 Subject: [PATCH] Use string for callback location info --- src/base/closure.h | 11 +++++------ src/base/task_runner.cc | 6 ++---- src/base/task_runner.h | 6 +++--- src/base/thread_pool.cc | 6 ++---- src/base/thread_pool.h | 6 +++--- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/base/closure.h b/src/base/closure.h index c40c47b..3be1dc0 100644 --- a/src/base/closure.h +++ b/src/base/closure.h @@ -12,12 +12,11 @@ // Helper for logging location info, e.g. LOG << LOCATION(from) #define LOCATION(from) \ - std::get<0>(from) << "() [" << [](const char* path) -> std::string { \ - std::string file_name(path); \ - size_t last_slash_pos = file_name.find_last_of("\\/"); \ + std::get<0>(from) << "() [" << [](std::string path) -> std::string { \ + size_t last_slash_pos = path.find_last_of("\\/"); \ if (last_slash_pos != std::string::npos) \ - file_name = file_name.substr(last_slash_pos + 1); \ - return file_name; \ + path = path.substr(last_slash_pos + 1); \ + return path; \ }(std::get<1>(from)) << ":" \ << std::get<2>(from) << "]" @@ -36,7 +35,7 @@ using Closure = std::function; // Provides location info (function name, file name and line number) where of a // Closure was constructed. -using Location = std::tuple; +using Location = std::tuple; #else diff --git a/src/base/task_runner.cc b/src/base/task_runner.cc index ebde0e4..2c5ce1e 100644 --- a/src/base/task_runner.cc +++ b/src/base/task_runner.cc @@ -36,7 +36,7 @@ TaskRunner* TaskRunner::GetThreadLocalTaskRunner() { return thread_local_task_runner.get(); } -void TaskRunner::PostTask(const Location& from, Closure task) { +void TaskRunner::PostTask(Location from, Closure task) { DCHECK(task) << LOCATION(from); task_count_.fetch_add(1, std::memory_order_relaxed); @@ -44,9 +44,7 @@ void TaskRunner::PostTask(const Location& from, Closure task) { queue_.emplace_back(from, std::move(task)); } -void TaskRunner::PostTaskAndReply(const Location& from, - Closure task, - Closure reply) { +void TaskRunner::PostTaskAndReply(Location from, Closure task, Closure reply) { DCHECK(task) << LOCATION(from); DCHECK(reply) << LOCATION(from); DCHECK(thread_local_task_runner) << LOCATION(from); diff --git a/src/base/task_runner.h b/src/base/task_runner.h index 4abf943..49d2f05 100644 --- a/src/base/task_runner.h +++ b/src/base/task_runner.h @@ -42,12 +42,12 @@ class TaskRunner { TaskRunner() = default; ~TaskRunner() = default; - void PostTask(const Location& from, Closure task); + void PostTask(Location from, Closure task); - void PostTaskAndReply(const Location& from, Closure task, Closure reply); + void PostTaskAndReply(Location from, Closure task, Closure reply); template - void PostTaskAndReplyWithResult(const Location& from, + void PostTaskAndReplyWithResult(Location from, std::function task, std::function reply) { auto* result = new ReturnType; diff --git a/src/base/thread_pool.cc b/src/base/thread_pool.cc index db7de58..312e13f 100644 --- a/src/base/thread_pool.cc +++ b/src/base/thread_pool.cc @@ -40,16 +40,14 @@ void ThreadPool::Shutdown() { threads_.clear(); } -void ThreadPool::PostTask(const Location& from, Closure task) { +void ThreadPool::PostTask(Location from, Closure task) { DCHECK((!threads_.empty())); task_runner_.PostTask(from, std::move(task)); semaphore_.release(); } -void ThreadPool::PostTaskAndReply(const Location& from, - Closure task, - Closure reply) { +void ThreadPool::PostTaskAndReply(Location from, Closure task, Closure reply) { DCHECK((!threads_.empty())); task_runner_.PostTaskAndReply(from, std::move(task), std::move(reply)); diff --git a/src/base/thread_pool.h b/src/base/thread_pool.h index d747dd4..203d343 100644 --- a/src/base/thread_pool.h +++ b/src/base/thread_pool.h @@ -26,12 +26,12 @@ class ThreadPool { void Shutdown(); - void PostTask(const Location& from, Closure task); + void PostTask(Location from, Closure task); - void PostTaskAndReply(const Location& from, Closure task, Closure reply); + void PostTaskAndReply(Location from, Closure task, Closure reply); template - void PostTaskAndReplyWithResult(const Location& from, + void PostTaskAndReplyWithResult(Location from, std::function task, std::function reply) { task_runner_.PostTaskAndReplyWithResult(from, std::move(task),