| 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/ThreadState.h" | 8 #include "platform/heap/ThreadState.h" |
| 9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
| 10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 void* m_object; | 36 void* m_object; |
| 37 VisitorCallback m_callback; | 37 VisitorCallback m_callback; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 CallbackStack(); | 40 CallbackStack(); |
| 41 ~CallbackStack(); | 41 ~CallbackStack(); |
| 42 | 42 |
| 43 void clear(); | 43 void clear(); |
| 44 void decommit(); |
| 44 | 45 |
| 45 Item* allocateEntry(); | 46 Item* allocateEntry(); |
| 46 Item* pop(); | 47 Item* pop(); |
| 47 | 48 |
| 48 bool isEmpty() const; | 49 bool isEmpty() const; |
| 49 | 50 |
| 50 void invokeEphemeronCallbacks(Visitor*); | 51 void invokeEphemeronCallbacks(Visitor*); |
| 51 | 52 |
| 52 #if ENABLE(ASSERT) | 53 #if ENABLE(ASSERT) |
| 53 bool hasCallbackForObject(const void*); | 54 bool hasCallbackForObject(const void*); |
| 54 #endif | 55 #endif |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 static const size_t blockSize = 8192; | 58 static const size_t blockSize = (1 << 13); |
| 58 | 59 |
| 59 class Block { | 60 class Block { |
| 60 USING_FAST_MALLOC(Block); | 61 USING_FAST_MALLOC(Block); |
| 61 public: | 62 public: |
| 62 explicit Block(Block* next) | 63 explicit Block(Block* next); |
| 63 : m_limit(&(m_buffer[blockSize])) | 64 ~Block(); |
| 64 , m_current(&(m_buffer[0])) | |
| 65 , m_next(next) | |
| 66 { | |
| 67 clearUnused(); | |
| 68 } | |
| 69 | 65 |
| 70 ~Block() | 66 void decommit(); |
| 71 { | |
| 72 clearUnused(); | |
| 73 } | |
| 74 | |
| 75 void clear(); | |
| 76 | 67 |
| 77 Block* next() const { return m_next; } | 68 Block* next() const { return m_next; } |
| 78 void setNext(Block* next) { m_next = next; } | 69 void setNext(Block* next) { m_next = next; } |
| 79 | 70 |
| 80 bool isEmptyBlock() const | 71 bool isEmptyBlock() const |
| 81 { | 72 { |
| 82 return m_current == &(m_buffer[0]); | 73 return m_current == &(m_buffer[0]); |
| 83 } | 74 } |
| 84 | 75 |
| 85 size_t size() const | |
| 86 { | |
| 87 return blockSize - (m_limit - m_current); | |
| 88 } | |
| 89 | |
| 90 Item* allocateEntry() | 76 Item* allocateEntry() |
| 91 { | 77 { |
| 92 if (LIKELY(m_current < m_limit)) | 78 if (LIKELY(m_current < m_limit)) |
| 93 return m_current++; | 79 return m_current++; |
| 94 return nullptr; | 80 return nullptr; |
| 95 } | 81 } |
| 96 | 82 |
| 97 Item* pop() | 83 Item* pop() |
| 98 { | 84 { |
| 99 if (UNLIKELY(isEmptyBlock())) | 85 if (UNLIKELY(isEmptyBlock())) |
| 100 return nullptr; | 86 return nullptr; |
| 101 return --m_current; | 87 return --m_current; |
| 102 } | 88 } |
| 103 | 89 |
| 104 void invokeEphemeronCallbacks(Visitor*); | 90 void invokeEphemeronCallbacks(Visitor*); |
| 105 #if ENABLE(ASSERT) | 91 #if ENABLE(ASSERT) |
| 106 bool hasCallbackForObject(const void*); | 92 bool hasCallbackForObject(const void*); |
| 107 #endif | 93 #endif |
| 108 | 94 |
| 109 private: | 95 private: |
| 110 void clearUnused(); | 96 Item* m_buffer; |
| 111 | |
| 112 Item m_buffer[blockSize]; | |
| 113 Item* m_limit; | 97 Item* m_limit; |
| 114 Item* m_current; | 98 Item* m_current; |
| 115 Block* m_next; | 99 Block* m_next; |
| 116 }; | 100 }; |
| 117 | 101 |
| 118 Item* popSlow(); | 102 Item* popSlow(); |
| 119 Item* allocateEntrySlow(); | 103 Item* allocateEntrySlow(); |
| 120 void invokeOldestCallbacks(Block*, Block*, Visitor*); | 104 void invokeOldestCallbacks(Block*, Block*, Visitor*); |
| 121 bool hasJustOneBlock() const; | 105 bool hasJustOneBlock() const; |
| 122 | 106 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 138 Item* item = m_first->pop(); | 122 Item* item = m_first->pop(); |
| 139 if (LIKELY(!!item)) | 123 if (LIKELY(!!item)) |
| 140 return item; | 124 return item; |
| 141 | 125 |
| 142 return popSlow(); | 126 return popSlow(); |
| 143 } | 127 } |
| 144 | 128 |
| 145 } // namespace blink | 129 } // namespace blink |
| 146 | 130 |
| 147 #endif // CallbackStack_h | 131 #endif // CallbackStack_h |
| OLD | NEW |