Skip to content

Commit

Permalink
Add threadpool helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatia committed Nov 29, 2024
1 parent 93f16c0 commit 277272b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tiledb/common/thread_pool/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ Status ThreadPool::wait_all(std::vector<ThreadPoolTask*>& tasks) {
return Status::Ok();
}

Status ThreadPool::wait_all(std::vector<Task>& tasks) {
std::vector<ThreadPoolTask*> task_ptrs;
for (auto& t : tasks) {
task_ptrs.emplace_back(&t);
}

return wait_all(task_ptrs);
}

Status ThreadPool::wait_all(std::vector<SharedTask>& tasks) {
std::vector<ThreadPoolTask*> task_ptrs;
for (auto& t : tasks) {
task_ptrs.emplace_back(&t);
}

return wait_all(task_ptrs);
}

// Return a vector of Status. If any task returns an error value or throws an
// exception, we save an error code in the corresponding location in the Status
// vector. All tasks are waited on before return. Multiple error statuses may
Expand Down Expand Up @@ -206,6 +224,25 @@ std::vector<Status> ThreadPool::wait_all_status(
return statuses;
}

std::vector<Status> ThreadPool::wait_all_status(std::vector<Task>& tasks) {
std::vector<ThreadPoolTask*> task_ptrs;
for (auto& t : tasks) {
task_ptrs.emplace_back(&t);
}

return wait_all_status(task_ptrs);
}

std::vector<Status> ThreadPool::wait_all_status(
std::vector<SharedTask>& tasks) {
std::vector<ThreadPoolTask*> task_ptrs;
for (auto& t : tasks) {
task_ptrs.emplace_back(&t);
}

return wait_all_status(task_ptrs);
}

Status ThreadPool::wait(ThreadPoolTask* task) {
while (true) {
if (!task->valid()) {
Expand Down
8 changes: 8 additions & 0 deletions tiledb/common/thread_pool/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ class ThreadPool {
*/
std::vector<Status> wait_all_status(std::vector<ThreadPoolTask*>& tasks);

/* Helper functions for lists that consists purely of Tasks */
Status wait_all(std::vector<Task>& tasks);
std::vector<Status> wait_all_status(std::vector<Task>& tasks);

/* Helper functions for lists that consists purely of SharedTasks */
Status wait_all(std::vector<SharedTask>& tasks);
std::vector<Status> wait_all_status(std::vector<SharedTask>& tasks);

/**
* Wait on a single tasks to complete. This function is safe to call
* recursively and may execute pending tasks on the calling thread while
Expand Down

0 comments on commit 277272b

Please sign in to comment.