| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/thread_pool.h" | 5 #include "bin/thread_pool.h" |
| 6 #include "bin/thread.h" | 6 #include "bin/thread.h" |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 10 | 10 |
| 11 | 11 |
| 12 UNIT_TEST_CASE(ThreadPoolStartStop) { | 12 UNIT_TEST_CASE(ThreadPoolStartStop) { |
| 13 ThreadPool thread_pool(NULL, 10); | 13 ThreadPool thread_pool(NULL, 10); |
| 14 thread_pool.Start(); | 14 thread_pool.Start(); |
| 15 thread_pool.Shutdown(); | 15 thread_pool.Shutdown(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 | 18 |
| 19 static dart::Monitor* monitor = NULL; | 19 static dart::Monitor* monitor = NULL; |
| 20 static uint32_t task_count = 0; | 20 static uint32_t task_count = 0; |
| 21 static uint32_t task_sum = 0; | 21 static uint32_t task_sum = 0; |
| 22 | 22 |
| 23 | 23 |
| 24 void TestTaskHandler(ThreadPool::Task args) { | 24 void TestTaskHandler(ThreadPool::Task args) { |
| 25 MonitorLocker ml(monitor); | 25 MonitorLocker ml(monitor); |
| 26 task_count++; | 26 task_count++; |
| 27 task_sum += reinterpret_cast<int>(args); | 27 task_sum += reinterpret_cast<intptr_t>(args); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 UNIT_TEST_CASE(ThreadPoolTest1) { | 31 UNIT_TEST_CASE(ThreadPoolTest1) { |
| 32 static const uint32_t kNumTestThreads = 10; | 32 static const uint32_t kNumTestThreads = 10; |
| 33 static const uint32_t kNumTestTasks = 1000; | 33 static const uint32_t kNumTestTasks = 1000; |
| 34 static const uint32_t kNumLoops = 100; | 34 static const uint32_t kNumLoops = 100; |
| 35 monitor = new dart::Monitor(); | 35 monitor = new dart::Monitor(); |
| 36 ThreadPool thread_pool(&TestTaskHandler, kNumTestThreads); | 36 ThreadPool thread_pool(&TestTaskHandler, kNumTestThreads); |
| 37 uint32_t pool_start_count = 0; | 37 uint32_t pool_start_count = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 thread_pool.Start(); | 79 thread_pool.Start(); |
| 80 thread_pool.Shutdown(ThreadPool::kDrain); | 80 thread_pool.Shutdown(ThreadPool::kDrain); |
| 81 | 81 |
| 82 // Check that all tasks where processed. | 82 // Check that all tasks where processed. |
| 83 EXPECT_EQ(kNumTestTasks, task_count); | 83 EXPECT_EQ(kNumTestTasks, task_count); |
| 84 EXPECT_EQ((1 + kNumTestTasks) * (kNumTestTasks / 2), task_sum); | 84 EXPECT_EQ((1 + kNumTestTasks) * (kNumTestTasks / 2), task_sum); |
| 85 | 85 |
| 86 delete monitor; | 86 delete monitor; |
| 87 monitor = NULL; | 87 monitor = NULL; |
| 88 } | 88 } |
| OLD | NEW |