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

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

Issue 9141005: Change the thread interface in runtime/platform and use it starting all threads (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r3537 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
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 "platform/globals.h" 9 #include "platform/globals.h"
10 #include "platform/thread.h" 10 #include "platform/thread.h"
11 11
12 // Declare the OS-specific types ahead of defining the generic classes.
13 #if defined(TARGET_OS_LINUX)
14 #include "bin/thread_pool_linux.h"
15 #elif defined(TARGET_OS_MACOS)
16 #include "bin/thread_pool_macos.h"
17 #elif defined(TARGET_OS_WINDOWS)
18 #include "bin/thread_pool_win.h"
19 #else
20 #error Unknown target os.
21 #endif
22
23
24 typedef void* Task; 12 typedef void* Task;
25 13
26 14
27 class TaskQueueEntry { 15 class TaskQueueEntry {
28 public: 16 public:
29 explicit TaskQueueEntry(Task task) : task_(task), next_(NULL) {} 17 explicit TaskQueueEntry(Task task) : task_(task), next_(NULL) {}
30 18
31 Task task() { return task_; } 19 Task task() { return task_; }
32 20
33 TaskQueueEntry* next() { return next_; } 21 TaskQueueEntry* next() { return next_; }
(...skipping 16 matching lines...) Expand all
50 TaskQueueEntry* Remove(); 38 TaskQueueEntry* Remove();
51 void Shutdown(); 39 void Shutdown();
52 40
53 private: 41 private:
54 bool terminate_; 42 bool terminate_;
55 TaskQueueEntry* head_; 43 TaskQueueEntry* head_;
56 TaskQueueEntry* tail_; 44 TaskQueueEntry* tail_;
57 dart::Monitor monitor_; 45 dart::Monitor monitor_;
58 46
59 DISALLOW_COPY_AND_ASSIGN(TaskQueue); 47 DISALLOW_COPY_AND_ASSIGN(TaskQueue);
60 }; 48 };
siva 2012/01/27 18:53:17 There was a comment by Ivan earlier about hiding t
Søren Gjesse 2012/01/30 14:42:57 I moved thread_pool cleanup to separate CL, https:
siva 2012/02/02 05:53:07 Ok, thanks for clarifying that.
61 49
62 50
63 class ThreadPool { 51 class ThreadPool {
64 public: 52 public:
65 typedef void* (*TaskHandler)(void* args); 53 typedef void* (*TaskHandler)(void* args);
66 54
67 ThreadPool(TaskHandler task_handler, int initial_size = 4) 55 ThreadPool(TaskHandler task_handler, int initial_size = 4)
68 : terminate_(false), 56 : terminate_(false),
69 size_(initial_size), 57 size_(initial_size),
70 task_handler_(task_handler) {} 58 task_handler_(task_handler) {}
71 59
72 void Start(); 60 void Start();
73 void Shutdown(); 61 void Shutdown();
74 62
75 void InsertTask(Task task); 63 void InsertTask(Task task);
76 64
65 void ThreadTerminated();
66
77 private: 67 private:
78 Task WaitForTask(); 68 Task WaitForTask();
79 69
80 static void* Main(void* args); 70 static void Main(uword args);
81 71
82 TaskQueue queue_; 72 TaskQueue queue_;
83 // TODO(sgjesse): Move the monitor in TaskQueue to ThreadPool and 73 // TODO(sgjesse): Move the monitor in TaskQueue to ThreadPool and
84 // obtain it for updating terminate_. 74 // obtain it for updating terminate_.
75 dart::Monitor monitor_;
85 bool terminate_; 76 bool terminate_;
86 int size_; // Number of threads. 77 int size_; // Number of threads.
87 TaskHandler task_handler_; 78 TaskHandler task_handler_;
88 ThreadPoolData data_;
89 79
90 DISALLOW_COPY_AND_ASSIGN(ThreadPool); 80 DISALLOW_COPY_AND_ASSIGN(ThreadPool);
91 }; 81 };
92 82
93 #endif // BIN_THREAD_POOL_H_ 83 #endif // BIN_THREAD_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698