|
9 | 9 | #include <executorch/extension/threadpool/threadpool.h> |
10 | 10 |
|
11 | 11 | #include <algorithm> |
12 | | -#include <atomic> |
13 | 12 | #include <memory> |
14 | 13 |
|
15 | 14 | #include <executorch/extension/threadpool/threadpool_guard.h> |
@@ -101,17 +100,20 @@ ThreadPool* get_threadpool() { |
101 | 100 | return nullptr; // NOLINT(facebook-hte-NullableReturn) |
102 | 101 | } |
103 | 102 |
|
104 | | - int num_threads = cpuinfo_get_processors_count(); |
105 | | - /* |
106 | | - * For llvm-tsan, holding limit for the number of locks for a single thread |
107 | | - * is 63 (because of comparison < 64 instead of <=). pthreadpool's worst |
108 | | - * case is the number of threads in a pool. So we want to limit the threadpool |
109 | | - * size to 64 when running with tsan. However, sometimes it is tricky to |
110 | | - * detect if we are running under tsan, for now capping the default |
111 | | - * threadcount to the tsan limit unconditionally. |
112 | | - */ |
113 | | - constexpr int tsan_thread_limit = 63; |
114 | | - num_threads = std::min(num_threads, tsan_thread_limit); |
| 103 | + static const int num_threads = ([]() { |
| 104 | + int result = cpuinfo_get_processors_count(); |
| 105 | + |
| 106 | + /* |
| 107 | + * For llvm-tsan, holding limit for the number of locks for a single thread |
| 108 | + * is 63 (because of comparison < 64 instead of <=). pthreadpool's worst |
| 109 | + * case is the number of threads in a pool. So we want to limit the |
| 110 | + * threadpool size to 64 when running with tsan. However, sometimes it is |
| 111 | + * tricky to detect if we are running under tsan, for now capping the |
| 112 | + * default threadcount to the tsan limit unconditionally. |
| 113 | + */ |
| 114 | + constexpr int tsan_thread_limit = 63; |
| 115 | + return std::min(result, tsan_thread_limit); |
| 116 | + })(); |
115 | 117 | static auto threadpool = std::make_unique<ThreadPool>(num_threads); |
116 | 118 |
|
117 | 119 | // Inheriting from old threadpool to get around segfault issue |
|
0 commit comments