Chromium Code Reviews| Index: Source/platform/heap/Handle.cpp |
| diff --git a/Source/platform/heap/Handle.cpp b/Source/platform/heap/Handle.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d4134631dbf10f641e8575968c03b9b9f7fe335f |
| --- /dev/null |
| +++ b/Source/platform/heap/Handle.cpp |
| @@ -0,0 +1,100 @@ |
| +/* |
| + * Copyright (C) 2014 Google Inc. All rights reserved. |
|
Mads Ager (chromium)
2014/09/02 11:45:48
Let's use the short copyright header for new files
wibling-chromium
2014/09/02 11:54:25
Done.
|
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "platform/heap/Handle.h" |
| + |
| +namespace blink { |
| + |
| +bool WrapperPersistentRegion::removeIfNotLast(WrapperPersistentRegion** headPtr) |
| +{ |
| + ASSERT(!m_count); |
| + // We are the last region in the list if both the region's m_prev and |
| + // m_next are 0. |
| + if (m_prev == 0 && m_next == 0) |
| + return false; |
| + if (m_prev) { |
| + m_prev->m_next = m_next; |
| + } else { |
| + ASSERT(*headPtr == this); |
| + *headPtr = m_next; |
| + } |
| + if (m_next) |
| + m_next->m_prev = m_prev; |
| + m_prev = 0; |
| + m_next = 0; |
| + return true; |
| +} |
| + |
| +void WrapperPersistentRegion::insertHead(WrapperPersistentRegion** headPtr, WrapperPersistentRegion* newHead) |
| +{ |
| + ASSERT(headPtr); |
| + WrapperPersistentRegion* oldHead = *headPtr; |
| + if (oldHead) { |
| + ASSERT(!oldHead->m_prev); |
| + oldHead->m_prev = newHead; |
| + } |
| + newHead->m_prev = 0; |
| + newHead->m_next = oldHead; |
| + *headPtr = newHead; |
| +} |
| + |
| +WrapperPersistentRegion* WrapperPersistentRegion::removeHead(WrapperPersistentRegion** headPtr) |
| +{ |
| + // We only call this if there is at least one element in the list. |
| + ASSERT(headPtr && *headPtr); |
| + WrapperPersistentRegion* oldHead = *headPtr; |
| + ASSERT(!oldHead->m_prev); |
| + *headPtr = oldHead->m_next; |
| + oldHead->m_next = 0; |
| + ASSERT(!(*headPtr) || (*headPtr)->m_prev == oldHead); |
| + if (*headPtr) |
| + (*headPtr)->m_prev = 0; |
| + return oldHead; |
| +} |
| + |
| +void* WrapperPersistentRegion::outOfLineAllocate(ThreadState* state, WrapperPersistentRegion* head) |
| +{ |
| + void* persistent = 0; |
| + // The caller has already tried allocating in the passed-in region, start |
| + // from the next. |
| + for (WrapperPersistentRegion* current = head->m_next; current; current = current->m_next) { |
| + persistent = current->allocate(); |
| + if (persistent) |
| + return persistent; |
| + } |
| + ASSERT(!persistent); |
| + WrapperPersistentRegion* newRegion = state->addWrapperPersistentRegion(); |
| + persistent = newRegion->allocate(); |
| + ASSERT(persistent); |
| + return persistent; |
| +} |
| + |
| +} |