OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/heap/PagePool.h" | 5 #include "platform/heap/PagePool.h" |
6 | 6 |
7 #include "platform/heap/Heap.h" | 7 #include "platform/heap/Heap.h" |
8 #include "platform/heap/PageMemory.h" | 8 #include "platform/heap/PageMemory.h" |
9 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 delete entry; | 26 delete entry; |
27 } | 27 } |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 void PagePool::add(int index, PageMemory* memory) { | 31 void PagePool::add(int index, PageMemory* memory) { |
32 // When adding a page to the pool we decommit it to ensure it is unused | 32 // When adding a page to the pool we decommit it to ensure it is unused |
33 // while in the pool. This also allows the physical memory, backing the | 33 // while in the pool. This also allows the physical memory, backing the |
34 // page, to be given back to the OS. | 34 // page, to be given back to the OS. |
35 memory->decommit(); | 35 memory->decommit(); |
36 MutexLocker locker(m_mutex[index]); | |
37 PoolEntry* entry = new PoolEntry(memory, m_pool[index]); | 36 PoolEntry* entry = new PoolEntry(memory, m_pool[index]); |
38 m_pool[index] = entry; | 37 m_pool[index] = entry; |
39 } | 38 } |
40 | 39 |
41 PageMemory* PagePool::take(int index) { | 40 PageMemory* PagePool::take(int index) { |
42 MutexLocker locker(m_mutex[index]); | |
43 while (PoolEntry* entry = m_pool[index]) { | 41 while (PoolEntry* entry = m_pool[index]) { |
44 m_pool[index] = entry->next; | 42 m_pool[index] = entry->next; |
45 PageMemory* memory = entry->data; | 43 PageMemory* memory = entry->data; |
46 ASSERT(memory); | 44 ASSERT(memory); |
47 delete entry; | 45 delete entry; |
48 if (memory->commit()) | 46 if (memory->commit()) |
49 return memory; | 47 return memory; |
50 | 48 |
51 // We got some memory, but failed to commit it, try again. | 49 // We got some memory, but failed to commit it, try again. |
52 delete memory; | 50 delete memory; |
53 } | 51 } |
54 return nullptr; | 52 return nullptr; |
55 } | 53 } |
56 | 54 |
57 } // namespace blink | 55 } // namespace blink |
OLD | NEW |