From 4e9f9b7e0e4272d3210d80b1bcf972c0097d0c0e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Jun 2025 16:38:19 +0200 Subject: [PATCH] Revert "add "for_each" to srb2 threadpool" This reverts commit 604bc400211ba3f298cbfef8195cd5cb1f68b595. --- src/core/thread_pool.h | 55 ------------------------------------------ 1 file changed, 55 deletions(-) diff --git a/src/core/thread_pool.h b/src/core/thread_pool.h index 535e77a9f..75961614e 100644 --- a/src/core/thread_pool.h +++ b/src/core/thread_pool.h @@ -80,7 +80,6 @@ public: /// Enqueue but don't notify template void schedule(T&& thunk); - template void for_each(F&& task); /// Notify threads after several schedules void notify(); void notify_sema(const Sema& sema); @@ -144,60 +143,6 @@ void ThreadPool::schedule(T&& thunk) } } -template -void ThreadPool::for_each(F&& thunk) -{ - static_assert(sizeof(std::decay_t) <= sizeof(std::declval().raw)); - - if (immediate_mode_) - { - thunk(); - return; - } - - Sema sync_sema; - begin_sema(); - - auto counter = std::make_shared>(threads_.size()); - - for (size_t i = 0; i < threads_.size(); i++) { - std::shared_ptr q = work_queues_[i]; - Task task; - - struct TaskData { - std::decay_t func; - std::shared_ptr> counter; - Sema sema; - ThreadPool* pool; - }; - static_assert(sizeof(TaskData) <= sizeof(task.raw)); - - new (task.raw.data()) TaskData{ - std::forward(thunk), - counter, - sync_sema, - this - }; - - task.thunk = [](void* ptr) { - auto* data = static_cast(ptr); - data->func(); - if (--(*data->counter) == 0) { - data->pool->notify_sema(data->sema); - } - }; - - task.deleter = [](void* ptr) { - static_cast(ptr)->~TaskData(); - }; - - task.pseudosema = cur_sema_; - q->push(std::move(task)); - } - - wait_sema(sync_sema); -} - } // namespace srb2 extern "C" {