diff options
author | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-27 21:07:24 +0000 |
---|---|---|
committer | dsh@google.com <dsh@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-27 21:07:24 +0000 |
commit | 0c3e3ed3f85afe7483ed476d2b185d7b21c31a84 (patch) | |
tree | 31269374aa45ec5de0a92a5ad1a22d1528bd60d8 /base/worker_pool.cc | |
parent | e1a64ca263731e00a8629e97f9bbc8027cafdb5b (diff) | |
download | chromium_src-0c3e3ed3f85afe7483ed476d2b185d7b21c31a84.zip chromium_src-0c3e3ed3f85afe7483ed476d2b185d7b21c31a84.tar.gz chromium_src-0c3e3ed3f85afe7483ed476d2b185d7b21c31a84.tar.bz2 |
Add unit tests for WorkerPool and add a working but poor implementation for Linux.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1466 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/worker_pool.cc')
-rw-r--r-- | base/worker_pool.cc | 40 |
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 |