summaryrefslogtreecommitdiffstats
path: root/base/worker_pool.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/worker_pool.cc')
-rw-r--r--base/worker_pool.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/base/worker_pool.cc b/base/worker_pool.cc
index fb64c85..b2c8c2b 100644
--- a/base/worker_pool.cc
+++ b/base/worker_pool.cc
@@ -6,6 +6,9 @@
#include "base/task.h"
+// TODO(dsh): Split this file into worker_pool_win.cc and worker_pool_posix.cc.
+#if defined(OS_WIN)
+
namespace {
DWORD CALLBACK WorkItemCallback(void* param) {
@@ -34,3 +37,40 @@ bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
return true;
}
+#elif defined(OS_LINUX)
+
+namespace {
+
+void* PThreadCallback(void* param) {
+ Task* task = static_cast<Task*>(param);
+ task->Run();
+ delete task;
+ return 0;
+}
+
+} // namespace
+
+bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
+ Task* task, bool task_is_slow) {
+ task->SetBirthPlace(from_here);
+ pthread_t thread;
+ pthread_attr_t attr;
+
+ // POSIX does not have a worker thread pool implementation. For now we just
+ // create a thread for each task, and ignore |task_is_slow|.
+ // TODO(dsh): Implement thread reuse.
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ int err = pthread_create(&thread, &attr, PThreadCallback, task);
+ pthread_attr_destroy(&attr);
+ if (err) {
+ DLOG(ERROR) << "pthread_create failed: " << err;
+ delete task;
+ return false;
+ }
+
+ return true;
+}
+
+#endif // OS_LINUX