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 15 matching lines...) Expand all Loading... |
26 // PerPageData page_data) | 26 // PerPageData page_data) |
27 // The function should return true iff processing succeeded. | 27 // The function should return true iff processing succeeded. |
28 // - static const bool NeedSequentialFinalization | 28 // - static const bool NeedSequentialFinalization |
29 // - static void FinalizePageSequentially(Heap* heap, | 29 // - static void FinalizePageSequentially(Heap* heap, |
30 // bool processing_succeeded, | 30 // bool processing_succeeded, |
31 // MemoryChunk* page, | 31 // MemoryChunk* page, |
32 // PerPageData page_data) | 32 // PerPageData page_data) |
33 template <typename JobTraits> | 33 template <typename JobTraits> |
34 class PageParallelJob { | 34 class PageParallelJob { |
35 public: | 35 public: |
36 PageParallelJob(Heap* heap, CancelableTaskManager* cancelable_task_manager) | 36 // PageParallelJob cannot dynamically create a semaphore because of a bug in |
| 37 // glibc. See http://crbug.com/609249 and |
| 38 // https://sourceware.org/bugzilla/show_bug.cgi?id=12674. |
| 39 // The caller must provide a semaphore with value 0 and ensure that |
| 40 // the lifetime of the semaphore is the same as the lifetime of the Isolate |
| 41 // It is guaranteed that the semaphore value will be 0 after Run() call. |
| 42 PageParallelJob(Heap* heap, CancelableTaskManager* cancelable_task_manager, |
| 43 base::Semaphore* semaphore) |
37 : heap_(heap), | 44 : heap_(heap), |
38 cancelable_task_manager_(cancelable_task_manager), | 45 cancelable_task_manager_(cancelable_task_manager), |
39 items_(nullptr), | 46 items_(nullptr), |
40 num_items_(0), | 47 num_items_(0), |
41 num_tasks_(0), | 48 num_tasks_(0), |
42 pending_tasks_(new base::Semaphore(0)) {} | 49 pending_tasks_(semaphore) {} |
43 | 50 |
44 ~PageParallelJob() { | 51 ~PageParallelJob() { |
45 Item* item = items_; | 52 Item* item = items_; |
46 while (item != nullptr) { | 53 while (item != nullptr) { |
47 Item* next = item->next; | 54 Item* next = item->next; |
48 delete item; | 55 delete item; |
49 item = next; | 56 item = next; |
50 } | 57 } |
51 delete pending_tasks_; | |
52 } | 58 } |
53 | 59 |
54 void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) { | 60 void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) { |
55 Item* item = new Item(chunk, data, items_); | 61 Item* item = new Item(chunk, data, items_); |
56 items_ = item; | 62 items_ = item; |
57 ++num_items_; | 63 ++num_items_; |
58 } | 64 } |
59 | 65 |
60 int NumberOfPages() { return num_items_; } | 66 int NumberOfPages() { return num_items_; } |
61 | 67 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 int num_items_; | 185 int num_items_; |
180 int num_tasks_; | 186 int num_tasks_; |
181 base::Semaphore* pending_tasks_; | 187 base::Semaphore* pending_tasks_; |
182 DISALLOW_COPY_AND_ASSIGN(PageParallelJob); | 188 DISALLOW_COPY_AND_ASSIGN(PageParallelJob); |
183 }; | 189 }; |
184 | 190 |
185 } // namespace internal | 191 } // namespace internal |
186 } // namespace v8 | 192 } // namespace v8 |
187 | 193 |
188 #endif // V8_HEAP_PAGE_PARALLEL_JOB_ | 194 #endif // V8_HEAP_PAGE_PARALLEL_JOB_ |
OLD | NEW |