17#define THREAD_POOL_UNIT_TEST_CASE(name) \
18 static void name##helper(); \
19 UNIT_TEST_CASE(name) { \
25 OSThread* os_thread = OSThread::Current(); \
26 OSThread::SetCurrent(nullptr); \
81 const int kTaskCount = 100;
84 bool done[kTaskCount];
86 for (
int i = 0;
i < kTaskCount;
i++) {
90 for (
int i = 0;
i < kTaskCount;
i++) {
105 started_count_(started_count),
106 slept_count_(slept_count),
112 *started_count_ = *started_count_ + 1;
120 *slept_count_ = *slept_count_ + 1;
134 const int kTaskCount = 10;
137 int started_count = 0;
143 for (
int i = 0;
i < kTaskCount;
i++) {
144 thread_pool->
Run<
SleepTask>(&sync, &started_count, &slept_count, 2);
150 while (started_count < kTaskCount) {
157 thread_pool =
nullptr;
162 final_count = slept_count;
167 EXPECT_EQ(kTaskCount, final_count);
172 int saved_timeout = FLAG_worker_timeout_millis;
173 FLAG_worker_timeout_millis = 1;
197 const int kMaxWait = 5000;
206 FLAG_worker_timeout_millis = saved_timeout;
212 : pool_(
pool), sync_(sync), todo_(todo), total_(total), done_(
done) {}
216 int child_todo = todo_ / 2;
220 pool_->
Run<
SpawnTask>(pool_, sync_, todo_ - child_todo, total_, done_);
223 pool_->
Run<
SpawnTask>(pool_, sync_, child_todo, total_, done_);
229 if (*done_ >= total_) {
246 const int kTotalTasks = 500;
248 thread_pool.
Run<
SpawnTask>(&thread_pool, &sync, kTotalTasks, kTotalTasks,
252 while (
done < kTotalTasks) {
256 EXPECT_EQ(kTotalTasks,
done);
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
static void Sleep(int64_t millis)
SleepTask(Monitor *sync, int *started_count, int *slept_count, int millis)
SpawnTask(ThreadPool *pool, Monitor *sync, int todo, int total, int *done)
TestTask(Monitor *sync, bool *done)
uint64_t workers_started() const
uint64_t workers_stopped() const
bool Run(Args &&... args)
THREAD_POOL_UNIT_TEST_CASE(ThreadPool_Create)
DECLARE_FLAG(bool, show_invisible_frames)