OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CallbackStack_h | 5 #ifndef CallbackStack_h |
6 #define CallbackStack_h | 6 #define CallbackStack_h |
7 | 7 |
8 #include "platform/heap/BlinkGC.h" | 8 #include "platform/heap/BlinkGC.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 void commit(); | 45 void commit(); |
46 void decommit(); | 46 void decommit(); |
47 | 47 |
48 Item* allocateEntry(); | 48 Item* allocateEntry(); |
49 Item* pop(); | 49 Item* pop(); |
50 | 50 |
51 bool isEmpty() const; | 51 bool isEmpty() const; |
52 | 52 |
53 void invokeEphemeronCallbacks(Visitor*); | 53 void invokeEphemeronCallbacks(Visitor*); |
54 | 54 |
55 #if ENABLE(ASSERT) | 55 #if DCHECK_IS_ON() |
56 bool hasCallbackForObject(const void*); | 56 bool hasCallbackForObject(const void*); |
57 #endif | 57 #endif |
58 bool hasJustOneBlock() const; | 58 bool hasJustOneBlock() const; |
59 | 59 |
60 static const size_t kMinimalBlockSize; | 60 static const size_t kMinimalBlockSize; |
61 static const size_t kDefaultBlockSize = (1 << 13); | 61 static const size_t kDefaultBlockSize = (1 << 13); |
62 | 62 |
63 private: | 63 private: |
64 class Block { | 64 class Block { |
65 USING_FAST_MALLOC(Block); | 65 USING_FAST_MALLOC(Block); |
66 | 66 |
67 public: | 67 public: |
68 explicit Block(Block* next); | 68 explicit Block(Block* next); |
69 ~Block(); | 69 ~Block(); |
70 | 70 |
71 #if ENABLE(ASSERT) | 71 #if DCHECK_IS_ON() |
72 void clear(); | 72 void clear(); |
73 #endif | 73 #endif |
74 Block* next() const { return m_next; } | 74 Block* next() const { return m_next; } |
75 void setNext(Block* next) { m_next = next; } | 75 void setNext(Block* next) { m_next = next; } |
76 | 76 |
77 bool isEmptyBlock() const { return m_current == &(m_buffer[0]); } | 77 bool isEmptyBlock() const { return m_current == &(m_buffer[0]); } |
78 | 78 |
79 size_t blockSize() const { return m_blockSize; } | 79 size_t blockSize() const { return m_blockSize; } |
80 | 80 |
81 Item* allocateEntry() { | 81 Item* allocateEntry() { |
82 if (LIKELY(m_current < m_limit)) | 82 if (LIKELY(m_current < m_limit)) |
83 return m_current++; | 83 return m_current++; |
84 return nullptr; | 84 return nullptr; |
85 } | 85 } |
86 | 86 |
87 Item* pop() { | 87 Item* pop() { |
88 if (UNLIKELY(isEmptyBlock())) | 88 if (UNLIKELY(isEmptyBlock())) |
89 return nullptr; | 89 return nullptr; |
90 return --m_current; | 90 return --m_current; |
91 } | 91 } |
92 | 92 |
93 void invokeEphemeronCallbacks(Visitor*); | 93 void invokeEphemeronCallbacks(Visitor*); |
94 | 94 |
95 #if ENABLE(ASSERT) | 95 #if DCHECK_IS_ON() |
96 bool hasCallbackForObject(const void*); | 96 bool hasCallbackForObject(const void*); |
97 #endif | 97 #endif |
98 | 98 |
99 private: | 99 private: |
100 size_t m_blockSize; | 100 size_t m_blockSize; |
101 | 101 |
102 Item* m_buffer; | 102 Item* m_buffer; |
103 Item* m_limit; | 103 Item* m_limit; |
104 Item* m_current; | 104 Item* m_current; |
105 Block* m_next; | 105 Block* m_next; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 Item* item = m_first->pop(); | 151 Item* item = m_first->pop(); |
152 if (LIKELY(!!item)) | 152 if (LIKELY(!!item)) |
153 return item; | 153 return item; |
154 | 154 |
155 return popSlow(); | 155 return popSlow(); |
156 } | 156 } |
157 | 157 |
158 } // namespace blink | 158 } // namespace blink |
159 | 159 |
160 #endif // CallbackStack_h | 160 #endif // CallbackStack_h |
OLD | NEW |