diff options
author | Tom Tromey <tom@tromey.com> | 2022-03-30 20:19:54 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-04-12 09:31:15 -0600 |
commit | 0981fe1017a8111aa6544ff52bcbbc80eec6b3c0 (patch) | |
tree | 094cc0549f9ec7c55276027466718155597c7682 /gdbsupport/parallel-for.h | |
parent | 8e6b35366073a1a71df805061ecf016cc915a9f9 (diff) | |
download | binutils-0981fe1017a8111aa6544ff52bcbbc80eec6b3c0.zip binutils-0981fe1017a8111aa6544ff52bcbbc80eec6b3c0.tar.gz binutils-0981fe1017a8111aa6544ff52bcbbc80eec6b3c0.tar.bz2 |
Allow thread-pool.h to work without threads
thread-pool.h requires CXX_STD_THREAD in order to even be included.
However, there's no deep reason for this, and during review we found
that one patch in the new DWARF indexer series unconditionally
requires the thread pool.
Because the thread pool already allows a task to be run in the calling
thread (for example if it is configured to have no threads in the
pool), it seemed straightforward to make this code ok to use when host
threads aren't available at all.
This patch implements this idea. I built it on a thread-less host
(mingw, before my recent configure patch) and verified that the result
builds.
After the thread-pool change, parallel-for.h no longer needs any
CXX_STD_THREAD checks at all, so this patch removes these as well.
Diffstat (limited to 'gdbsupport/parallel-for.h')
-rw-r--r-- | gdbsupport/parallel-for.h | 7 |
1 files changed, 0 insertions, 7 deletions
diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index ca03094..915814e 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -21,10 +21,7 @@ #define GDBSUPPORT_PARALLEL_FOR_H #include <algorithm> -#if CXX_STD_THREAD -#include <thread> #include "gdbsupport/thread-pool.h" -#endif namespace gdb { @@ -41,7 +38,6 @@ template<class RandomIt, class RangeFunction> void parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback) { -#if CXX_STD_THREAD /* So we can use a local array below. */ const size_t local_max = 16; size_t n_threads = std::min (thread_pool::g_thread_pool->thread_count (), @@ -70,15 +66,12 @@ parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback) first = end; } } -#endif /* CXX_STD_THREAD */ /* Process all the remaining elements in the main thread. */ callback (first, last); -#if CXX_STD_THREAD for (int i = 0; i < n_actual_threads; ++i) futures[i].wait (); -#endif /* CXX_STD_THREAD */ } } |