OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium 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 // Simple thread pool class | 5 // Simple thread pool class |
6 | 6 |
7 #ifndef EXAMPLES_DEMO_VORONOI_THREADPOOL_H_ | 7 #ifndef LIBRARIES_SDK_UTIL_THREAD_POOL_H_ |
8 #define EXAMPLES_DEMO_VORONOI_THREADPOOL_H_ | 8 #define LIBRARIES_SDK_UTIL_THREAD_POOL_H_ |
9 | 9 |
10 #include <pthread.h> | 10 #include <pthread.h> |
11 #include <semaphore.h> | 11 #include <semaphore.h> |
12 | 12 |
13 // typdef helper for work function | 13 // typdef helper for work function |
14 typedef void (*WorkFunction)(int task_index, void* data); | 14 typedef void (*WorkFunction)(int task_index, void* data); |
15 | 15 |
16 // ThreadPool is a class to manage num_threads and assign | 16 // ThreadPool is a class to manage num_threads and assign |
17 // them num_tasks of work at a time. Each call | 17 // them num_tasks of work at a time. Each call |
18 // to Dispatch(..) will block until all tasks complete. | 18 // to Dispatch(..) will block until all tasks complete. |
(...skipping 15 matching lines...) Expand all Loading... |
34 void PostExitAndJoinAll(); | 34 void PostExitAndJoinAll(); |
35 pthread_t* threads_; | 35 pthread_t* threads_; |
36 int counter_; | 36 int counter_; |
37 const int num_threads_; | 37 const int num_threads_; |
38 bool exiting_; | 38 bool exiting_; |
39 void* user_data_; | 39 void* user_data_; |
40 WorkFunction user_work_function_; | 40 WorkFunction user_work_function_; |
41 sem_t work_sem_; | 41 sem_t work_sem_; |
42 sem_t done_sem_; | 42 sem_t done_sem_; |
43 }; | 43 }; |
44 #endif // EXAMPLES_DEMO_VORONOI_THREADPOOL_H_ | 44 #endif // LIBRARIES_SDK_UTIL_THREAD_POOL_H_ |
45 | 45 |
OLD | NEW |