| OLD | NEW |
| 1 // Copyright 2014 The Native Client Authors. All rights reserved. | 1 // Copyright 2014 The Native Client Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <pthread.h> | 5 #include <pthread.h> |
| 6 #include <semaphore.h> | 6 #include <semaphore.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 // @EXEMPTION[include] | 11 #include "native_client/tests/benchmark/thread_pool.h" |
| 12 #include "./thread_pool.h" | |
| 13 | 12 |
| 14 namespace sdk_util { | 13 namespace sdk_util { |
| 15 | 14 |
| 16 // Initializes mutex, semaphores and a pool of threads. If 0 is passed for | 15 // Initializes mutex, semaphores and a pool of threads. If 0 is passed for |
| 17 // num_threads, all work will be performed on the dispatch thread. | 16 // num_threads, all work will be performed on the dispatch thread. |
| 18 ThreadPool::ThreadPool(int num_threads) | 17 ThreadPool::ThreadPool(int num_threads) |
| 19 : threads_(NULL), counter_(0), num_threads_(num_threads), exiting_(false), | 18 : threads_(NULL), counter_(0), num_threads_(num_threads), exiting_(false), |
| 20 user_data_(NULL), user_work_function_(NULL) { | 19 user_data_(NULL), user_work_function_(NULL) { |
| 21 if (num_threads_ > 0) { | 20 if (num_threads_ > 0) { |
| 22 int status; | 21 int status; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // one or more threads for each task. | 129 // one or more threads for each task. |
| 131 // Note: This function will block until all work has completed. | 130 // Note: This function will block until all work has completed. |
| 132 void ThreadPool::Dispatch(int num_tasks, WorkFunction work, void* data) { | 131 void ThreadPool::Dispatch(int num_tasks, WorkFunction work, void* data) { |
| 133 if (num_threads_ > 0) | 132 if (num_threads_ > 0) |
| 134 DispatchMany(num_tasks, work, data); | 133 DispatchMany(num_tasks, work, data); |
| 135 else | 134 else |
| 136 DispatchHere(num_tasks, work, data); | 135 DispatchHere(num_tasks, work, data); |
| 137 } | 136 } |
| 138 | 137 |
| 139 } // namespace sdk_util | 138 } // namespace sdk_util |
| OLD | NEW |