Chromium Code Reviews| Index: runtime/vm/thread_test.cc |
| diff --git a/runtime/vm/thread_test.cc b/runtime/vm/thread_test.cc |
| index d03bfdf8707df8d652029f3630d11e80de77f5db..51eaa5ff2a320464cbdde7c6d259ba448ce8930e 100644 |
| --- a/runtime/vm/thread_test.cc |
| +++ b/runtime/vm/thread_test.cc |
| @@ -456,78 +456,84 @@ TEST_CASE(ThreadIterator_FindSelf) { |
| } |
| -class ThreadIteratorTestTask : public ThreadPool::Task { |
| - public: |
| - ThreadIteratorTestTask(Isolate* isolate, |
| - Monitor* monitor, |
| - Thread** task_thread) |
| - : isolate_(isolate), |
| - monitor_(monitor), |
| - task_thread_(task_thread) {} |
| +struct ThreadIteratorTestParams { |
| + Isolate* isolate; |
| + Thread* spawned_thread; |
| + ThreadJoinId spawned_thread_join_id; |
| + Monitor* monitor; |
| +}; |
| - virtual void Run() { |
| - Thread* thread = Thread::Current(); |
| - Thread::EnterIsolateAsHelper(isolate_); |
| - MonitorLocker ml(monitor_); |
| - { |
| - bool found_self = false; |
| - ThreadIterator it; |
| - while (it.HasNext()) { |
| - Thread* t = it.Next(); |
| - if (t == thread) { |
| - found_self = true; |
| - break; |
| - } |
| - } |
| - EXPECT(found_self); |
| - } |
| +void ThreadIteratorTestMain(uword parameter) { |
| + Thread::EnsureInit(); |
| + ThreadIteratorTestParams* params = |
| + reinterpret_cast<ThreadIteratorTestParams*>(parameter); |
| + Isolate* isolate = params->isolate; |
| + ASSERT(isolate != NULL); |
| - Thread::ExitIsolateAsHelper(); |
| - *task_thread_ = thread; |
| + Thread::EnterIsolateAsHelper(isolate); |
| + Thread* thread = Thread::Current(); |
| + ASSERT(thread != NULL); |
| + |
| + params->spawned_thread = thread; |
| + params->spawned_thread_join_id = OSThread::GetCurrentThreadJoinId(); |
|
siva
2015/10/13 21:38:57
ASSERT(params->spawned_thread_join_id != OSThread:
|
| + |
| + { |
| + MonitorLocker ml(params->monitor); |
| ml.Notify(); |
| } |
| - private: |
| - Isolate* isolate_; |
| - Monitor* monitor_; |
| - Thread** task_thread_; |
| -}; |
| + { |
| + bool found_self = false; |
| + ThreadIterator it; |
| + while (it.HasNext()) { |
| + Thread* t = it.Next(); |
| + if (t == thread) { |
| + found_self = true; |
| + break; |
| + } |
| + } |
| + EXPECT(found_self); |
| + } |
| + |
| + Thread::ExitIsolateAsHelper(); |
| +} |
| TEST_CASE(ThreadIterator_AddFindRemove) { |
| - Thread* task_thread = NULL; |
| Isolate* isolate = thread->isolate(); |
| - Monitor* monitor = new Monitor(); |
| - |
| - ThreadPool* thread_pool = new ThreadPool(); |
| + ThreadIteratorTestParams params; |
| + params.isolate = isolate; |
| + params.spawned_thread = NULL; |
| + params.spawned_thread_join_id = OSThread::kInvalidThreadJoinId; |
| + params.monitor = new Monitor(); |
| { |
| - MonitorLocker ml(monitor); |
| - EXPECT(task_thread == NULL); |
| - thread_pool->Run(new ThreadIteratorTestTask(isolate, |
| - monitor, |
| - &task_thread)); |
| - // Wait to be notified that the task is complete and we have a value in |
| - // task_thread. |
| - ml.Wait(); |
| - EXPECT(task_thread != NULL); |
| + MonitorLocker ml(params.monitor); |
| + EXPECT(params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId); |
| + EXPECT(params.spawned_thread == NULL); |
| + // Spawn thread and wait to receive the thread join id. |
| + OSThread::Start(ThreadIteratorTestMain, reinterpret_cast<uword>(¶ms)); |
| + while (params.spawned_thread_join_id == OSThread::kInvalidThreadJoinId) { |
| + ml.Wait(); |
| + } |
| + EXPECT(params.spawned_thread_join_id != OSThread::kInvalidThreadJoinId); |
| + EXPECT(params.spawned_thread != NULL); |
| + // Join thread. |
| + OSThread::Join(params.spawned_thread_join_id); |
| } |
| - // Shutdown thread pool so we know that the task thread has completed. |
| - delete thread_pool; |
| - |
| ThreadIterator it; |
| - bool found_task_thread = false; |
| + bool found_spawned_thread = false; |
| while (it.HasNext()) { |
| Thread* t = it.Next(); |
| - if (t == task_thread) { |
| - found_task_thread = true; |
| + if (t == params.spawned_thread) { |
| + found_spawned_thread = true; |
| break; |
| } |
| } |
| - EXPECT(!found_task_thread); |
| + EXPECT(!found_spawned_thread); |
| } |