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

Side by Side Diff: runtime/bin/thread_pool.h

Issue 9112013: Thread pool changes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 8 years, 11 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 | « runtime/bin/main.cc ('k') | runtime/bin/thread_pool.cc » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef BIN_THREAD_POOL_H_ 5 #ifndef BIN_THREAD_POOL_H_
6 #define BIN_THREAD_POOL_H_ 6 #define BIN_THREAD_POOL_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/globals.h" 9 #include "bin/globals.h"
10 10
11 // Declare the OS-specific types ahead of defining the generic classes. 11 // Declare the OS-specific types ahead of defining the generic classes.
12 #if defined(TARGET_OS_LINUX) 12 #if defined(TARGET_OS_LINUX)
13 #include "bin/thread_pool_linux.h" 13 #include "bin/thread_pool_linux.h"
14 #elif defined(TARGET_OS_MACOS) 14 #elif defined(TARGET_OS_MACOS)
15 #include "bin/thread_pool_macos.h" 15 #include "bin/thread_pool_macos.h"
16 #elif defined(TARGET_OS_WINDOWS) 16 #elif defined(TARGET_OS_WINDOWS)
17 #include "bin/thread_pool_win.h" 17 #include "bin/thread_pool_win.h"
18 #else 18 #else
19 #error Unknown target os. 19 #error Unknown target os.
20 #endif 20 #endif
21 21
22 22
23 typedef int Task; 23 typedef void* Task;
24 24
25 25
26 class TaskQueueEntry { 26 class TaskQueueEntry {
27 public: 27 public:
28 explicit TaskQueueEntry(Task task) : task_(task), next_(NULL) {} 28 explicit TaskQueueEntry(Task task) : task_(task), next_(NULL) {}
29 29
30 Task task() { return task_; } 30 Task task() { return task_; }
31 31
32 TaskQueueEntry* next() { return next_; } 32 TaskQueueEntry* next() { return next_; }
33 void set_next(TaskQueueEntry* value) { next_ = value; } 33 void set_next(TaskQueueEntry* value) { next_ = value; }
(...skipping 16 matching lines...) Expand all
50 50
51 private: 51 private:
52 TaskQueueEntry* head_; 52 TaskQueueEntry* head_;
53 TaskQueueEntry* tail_; 53 TaskQueueEntry* tail_;
54 TaskQueueData data_; 54 TaskQueueData data_;
55 55
56 DISALLOW_COPY_AND_ASSIGN(TaskQueue); 56 DISALLOW_COPY_AND_ASSIGN(TaskQueue);
57 }; 57 };
58 58
59 59
60 typedef void* (*ThreadPoolTaskHandler)(void* args);
Mads Ager (google) 2012/01/06 10:56:18 Does the style guide say anything about the placem
Søren Gjesse 2012/01/06 11:24:26 I moved it into class ThreadPool (and changed the
61
62
60 class ThreadPool { 63 class ThreadPool {
61 public: 64 public:
62 explicit ThreadPool(int initial_size = 4) : size_(initial_size) {} 65 ThreadPool(ThreadPoolTaskHandler task_handler, int initial_size = 4)
66 : size_(initial_size), task_handler_(task_handler) {}
63 67
64 void Start(); 68 void Start();
65 void Shutdown(); 69 void Shutdown();
66 70
67 void InsertTask(Task task); 71 void InsertTask(Task task);
68 72
69 private: 73 private:
70 Task WaitForTask(); 74 Task WaitForTask();
71 75
72 static void* Main(void* args); 76 static void* Main(void* args);
73 77
74 TaskQueue queue; 78 TaskQueue queue;
75 int size_; // Number of threads. 79 int size_; // Number of threads.
80 ThreadPoolTaskHandler task_handler_;
76 ThreadPoolData data_; 81 ThreadPoolData data_;
77 82
78 DISALLOW_COPY_AND_ASSIGN(ThreadPool); 83 DISALLOW_COPY_AND_ASSIGN(ThreadPool);
79 }; 84 };
80 85
81 #endif // BIN_THREAD_POOL_H_ 86 #endif // BIN_THREAD_POOL_H_
OLDNEW
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/bin/thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698