OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 #ifndef V8_HEAP_PAGE_PARALLEL_JOB_ | 5 #ifndef V8_HEAP_PAGE_PARALLEL_JOB_ |
6 #define V8_HEAP_PAGE_PARALLEL_JOB_ | 6 #define V8_HEAP_PAGE_PARALLEL_JOB_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/cancelable-task.h" | 9 #include "src/cancelable-task.h" |
10 #include "src/utils.h" | 10 #include "src/utils.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 item = next; | 56 item = next; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) { | 60 void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) { |
61 Item* item = new Item(chunk, data, items_); | 61 Item* item = new Item(chunk, data, items_); |
62 items_ = item; | 62 items_ = item; |
63 ++num_items_; | 63 ++num_items_; |
64 } | 64 } |
65 | 65 |
66 int NumberOfPages() { return num_items_; } | 66 int NumberOfPages() const { return num_items_; } |
67 | 67 |
68 // Returns the number of tasks that were spawned when running the job. | 68 // Returns the number of tasks that were spawned when running the job. |
69 int NumberOfTasks() { return num_tasks_; } | 69 int NumberOfTasks() const { return num_tasks_; } |
70 | 70 |
71 // Runs the given number of tasks in parallel and processes the previously | 71 // Runs the given number of tasks in parallel and processes the previously |
72 // added pages. This function blocks until all tasks finish. | 72 // added pages. This function blocks until all tasks finish. |
73 // The callback takes the index of a task and returns data for that task. | 73 // The callback takes the index of a task and returns data for that task. |
74 template <typename Callback> | 74 template <typename Callback> |
75 void Run(int num_tasks, Callback per_task_data_callback) { | 75 void Run(int num_tasks, Callback per_task_data_callback) { |
76 if (num_items_ == 0) return; | 76 if (num_items_ == 0) return; |
77 DCHECK_GE(num_tasks, 1); | 77 DCHECK_GE(num_tasks, 1); |
78 uint32_t task_ids[kMaxNumberOfTasks]; | 78 uint32_t task_ids[kMaxNumberOfTasks]; |
79 const int max_num_tasks = Min( | 79 const int max_num_tasks = Min( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 int num_items_; | 186 int num_items_; |
187 int num_tasks_; | 187 int num_tasks_; |
188 base::Semaphore* pending_tasks_; | 188 base::Semaphore* pending_tasks_; |
189 DISALLOW_COPY_AND_ASSIGN(PageParallelJob); | 189 DISALLOW_COPY_AND_ASSIGN(PageParallelJob); |
190 }; | 190 }; |
191 | 191 |
192 } // namespace internal | 192 } // namespace internal |
193 } // namespace v8 | 193 } // namespace v8 |
194 | 194 |
195 #endif // V8_HEAP_PAGE_PARALLEL_JOB_ | 195 #endif // V8_HEAP_PAGE_PARALLEL_JOB_ |
OLD | NEW |