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

Side by Side Diff: base/worker_pool_win.cc

Issue 39081: Split worker_pool.cc into worker_pool_linux.cc and worker_pool_win.cc (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/worker_pool_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 { 9 namespace {
13 10
14 DWORD CALLBACK WorkItemCallback(void* param) { 11 DWORD CALLBACK WorkItemCallback(void* param) {
15 Task* task = static_cast<Task*>(param); 12 Task* task = static_cast<Task*>(param);
16 task->Run(); 13 task->Run();
17 delete task; 14 delete task;
18 return 0; 15 return 0;
19 } 16 }
20 17
21 } // namespace 18 } // namespace
22 19
23 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, 20 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
24 Task* task, bool task_is_slow) { 21 Task* task, bool task_is_slow) {
25 task->SetBirthPlace(from_here); 22 task->SetBirthPlace(from_here);
26 23
27 ULONG flags = 0; 24 ULONG flags = 0;
28 if (task_is_slow) 25 if (task_is_slow)
29 flags |= WT_EXECUTELONGFUNCTION; 26 flags |= WT_EXECUTELONGFUNCTION;
30 27
31 if (!QueueUserWorkItem(WorkItemCallback, task, flags)) { 28 if (!QueueUserWorkItem(WorkItemCallback, task, flags)) {
32 DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError(); 29 DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError();
33 delete task; 30 delete task;
34 return false; 31 return false;
35 } 32 }
36 33
37 return true; 34 return true;
38 } 35 }
39
40 #elif defined(OS_LINUX)
41
42 namespace {
43
44 void* PThreadCallback(void* param) {
45 Task* task = static_cast<Task*>(param);
46 task->Run();
47 delete task;
48 return 0;
49 }
50
51 } // namespace
52
53 bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
54 Task* task, bool task_is_slow) {
55 task->SetBirthPlace(from_here);
56
57 pthread_t thread;
58 pthread_attr_t attr;
59
60 // POSIX does not have a worker thread pool implementation. For now we just
61 // create a thread for each task, and ignore |task_is_slow|.
62 // TODO(dsh): Implement thread reuse.
63 pthread_attr_init(&attr);
64 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
65
66 int err = pthread_create(&thread, &attr, PThreadCallback, task);
67 pthread_attr_destroy(&attr);
68 if (err) {
69 DLOG(ERROR) << "pthread_create failed: " << err;
70 delete task;
71 return false;
72 }
73
74 return true;
75 }
76
77 #endif // OS_LINUX
OLDNEW
« no previous file with comments | « base/worker_pool_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698