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. | |
10 #if defined(OS_WIN) | |
11 | |
12 namespace { | |
13 | |
14 DWORD CALLBACK WorkItemCallback(void* param) { | |
15 Task* task = static_cast<Task*>(param); | |
16 task->Run(); | |
17 delete task; | |
18 return 0; | |
19 } | |
20 | |
21 } // namespace | |
22 | |
23 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | |
24 Task* task, bool task_is_slow) { | |
25 task->SetBirthPlace(from_here); | |
26 | |
27 ULONG flags = 0; | |
28 if (task_is_slow) | |
29 flags |= WT_EXECUTELONGFUNCTION; | |
30 | |
31 if (!QueueUserWorkItem(WorkItemCallback, task, flags)) { | |
32 DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError(); | |
33 delete task; | |
34 return false; | |
35 } | |
36 | |
37 return true; | |
38 } | |
39 | |
40 #elif defined(OS_LINUX) | |
41 | |
42 namespace { | 9 namespace { |
43 | 10 |
44 void* PThreadCallback(void* param) { | 11 void* PThreadCallback(void* param) { |
45 Task* task = static_cast<Task*>(param); | 12 Task* task = static_cast<Task*>(param); |
46 task->Run(); | 13 task->Run(); |
47 delete task; | 14 delete task; |
48 return 0; | 15 return 0; |
49 } | 16 } |
50 | 17 |
51 } // namespace | 18 } // namespace |
(...skipping 14 matching lines...) Expand all Loading... |
66 int err = pthread_create(&thread, &attr, PThreadCallback, task); | 33 int err = pthread_create(&thread, &attr, PThreadCallback, task); |
67 pthread_attr_destroy(&attr); | 34 pthread_attr_destroy(&attr); |
68 if (err) { | 35 if (err) { |
69 DLOG(ERROR) << "pthread_create failed: " << err; | 36 DLOG(ERROR) << "pthread_create failed: " << err; |
70 delete task; | 37 delete task; |
71 return false; | 38 return false; |
72 } | 39 } |
73 | 40 |
74 return true; | 41 return true; |
75 } | 42 } |
76 | |
77 #endif // OS_LINUX | |
OLD | NEW |