| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/worker_pool.h" | 5 #include "base/worker_pool.h" |
| 6 | 6 |
| 7 #include "base/task.h" | 7 #include "base/task.h" |
| 8 | 8 |
| 9 // TODO(dsh): Split this file into worker_pool_win.cc and worker_pool_posix.cc. | 9 // TODO(dsh): Split this file into worker_pool_win.cc and worker_pool_posix.cc. |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 task->Run(); | 46 task->Run(); |
| 47 delete task; | 47 delete task; |
| 48 return 0; | 48 return 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 53 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
| 54 Task* task, bool task_is_slow) { | 54 Task* task, bool task_is_slow) { |
| 55 task->SetBirthPlace(from_here); | 55 task->SetBirthPlace(from_here); |
| 56 |
| 56 pthread_t thread; | 57 pthread_t thread; |
| 57 pthread_attr_t attr; | 58 pthread_attr_t attr; |
| 58 | 59 |
| 59 // POSIX does not have a worker thread pool implementation. For now we just | 60 // POSIX does not have a worker thread pool implementation. For now we just |
| 60 // create a thread for each task, and ignore |task_is_slow|. | 61 // create a thread for each task, and ignore |task_is_slow|. |
| 61 // TODO(dsh): Implement thread reuse. | 62 // TODO(dsh): Implement thread reuse. |
| 62 pthread_attr_init(&attr); | 63 pthread_attr_init(&attr); |
| 63 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | 64 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 64 | 65 |
| 65 int err = pthread_create(&thread, &attr, PThreadCallback, task); | 66 int err = pthread_create(&thread, &attr, PThreadCallback, task); |
| 66 pthread_attr_destroy(&attr); | 67 pthread_attr_destroy(&attr); |
| 67 if (err) { | 68 if (err) { |
| 68 DLOG(ERROR) << "pthread_create failed: " << err; | 69 DLOG(ERROR) << "pthread_create failed: " << err; |
| 69 delete task; | 70 delete task; |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 | 73 |
| 73 return true; | 74 return true; |
| 74 } | 75 } |
| 75 | 76 |
| 76 #endif // OS_LINUX | 77 #endif // OS_LINUX |
| OLD | NEW |