30static void GetFuture(std::future<void>& future, uint32_t& fail_counter)
37 assert(
false &&
"Unexpected exception type");
75 std::atomic_uint32_t task_counter{0};
76 uint32_t fail_counter{0};
77 uint32_t expected_task_counter{0};
78 uint32_t expected_fail_tasks{0};
80 std::queue<std::future<void>>
futures;
81 for (uint32_t i = 0; i < num_tasks; ++i) {
85 std::future<void> fut;
87 expected_fail_tasks++;
90 expected_task_counter++;
95 if (wait_immediately) {
101 futures.emplace(std::move(fut));
107 auto fut = std::move(
futures.front());
113 assert(task_counter.load() == expected_task_counter);
114 assert(fail_counter == expected_fail_tasks);
#define Assert(val)
Identity function.
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Disable logging This offers a slight speedup and slightly smaller memory usage compared to leaving th...
T ConsumeIntegralInRange(T min, T max)
Fixed-size thread pool for running arbitrary tasks concurrently.
void Start(int num_workers) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Start worker threads.
size_t WorkersCount() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
util::Expected< Future< F >, SubmitError > Submit(F &&fn) noexcept EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Enqueues a new task for asynchronous execution.
size_t WorkQueueSize() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
BCLog::Logger & LogInstance()
std::atomic_uint32_t & m_counter
CounterTask(std::atomic_uint32_t &counter)
ExpectedException(const std::string &msg)
FUZZ_TARGET(threadpool,.init=setup_threadpool_test)
static void StartPoolIfNeeded()
static void setup_threadpool_test()
static void GetFuture(std::future< void > &future, uint32_t &fail_counter)
FuzzedDataProvider & fuzzed_data_provider