Skip to content

Commit a69956c

Browse files
authored
Use runtime::FunctionRef in threadpool.h itself (#15265)
I previously added runtime::FunctionRef and used it in parallel_for to save code size, but didn't carry that through to the Threadpool wrapper. Profiling showed that we were doing heap allocations on each parallel_for invocation, so let's fix that.
1 parent b7063fd commit a69956c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

extension/threadpool/threadpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool ThreadPool::_unsafe_reset_threadpool(uint32_t new_thread_count) {
7676
}
7777

7878
void ThreadPool::run(
79-
const std::function<void(size_t)>& fn,
79+
runtime::FunctionRef<void(size_t)> fn,
8080
const size_t range) {
8181
// Run on same thread if NoThreadPoolGuard guard is enabled
8282
if (NoThreadPoolGuard::is_enabled()) {

extension/threadpool/threadpool.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <pthreadpool.h>
1616

17+
#include <executorch/runtime/core/function_ref.h>
18+
1719
/*
1820
* Threadpool Options:
1921
*
@@ -74,7 +76,7 @@ class ThreadPool final {
7476
* multiple threads with the scope of the guard When NoThreadPoolGuard is not
7577
* used all calls to run method are serialized.
7678
*/
77-
void run(const std::function<void(size_t)>& fn, size_t range);
79+
void run(runtime::FunctionRef<void(size_t)> fn, size_t range);
7880

7981
private:
8082
friend pthreadpool_t get_pthreadpool();

0 commit comments

Comments
 (0)