Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: native_client_sdk/src/libraries/sdk_util/thread_pool.h

Issue 16325024: Move thread_pool.h into utils so it can be shared by more than one example. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/sdk_util/thread_pool.h
===================================================================
--- native_client_sdk/src/libraries/sdk_util/thread_pool.h (revision 0)
+++ native_client_sdk/src/libraries/sdk_util/thread_pool.h (revision 0)
@@ -0,0 +1,45 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Simple thread pool class
+
+#ifndef LIBRARIES_SDK_UTIL_THREAD_POOL_H_
+#define LIBRARIES_SDK_UTIL_THREAD_POOL_H_
+
+#include <pthread.h>
+#include <semaphore.h>
+
+// typdef helper for work function
+typedef void (*WorkFunction)(int task_index, void* data);
+
+// ThreadPool is a class to manage num_threads and assign
+// them num_tasks of work at a time. Each call
+// to Dispatch(..) will block until all tasks complete.
+// If 0 is passed in for num_threads, all tasks will be
+// issued on the dispatch thread.
+
+class ThreadPool {
+ public:
+ void Dispatch(int num_tasks, WorkFunction work, void* data);
+ explicit ThreadPool(int num_threads);
+ ~ThreadPool();
+ private:
+ int DecCounter();
+ void Setup(int counter, WorkFunction work, void* data);
+ void DispatchMany(int num_tasks, WorkFunction work, void* data);
+ void DispatchHere(int num_tasks, WorkFunction work, void* data);
+ void WorkLoop();
+ static void* WorkerThreadEntry(void* data);
+ void PostExitAndJoinAll();
+ pthread_t* threads_;
+ int counter_;
+ const int num_threads_;
+ bool exiting_;
+ void* user_data_;
+ WorkFunction user_work_function_;
+ sem_t work_sem_;
+ sem_t done_sem_;
+};
+#endif // LIBRARIES_SDK_UTIL_THREAD_POOL_H_
+
Property changes on: native_client_sdk/src/libraries/sdk_util/thread_pool.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « native_client_sdk/src/libraries/sdk_util/ref_object.h ('k') | native_client_sdk/src/libraries/sdk_util/thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698