| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef ArrayBufferContents_h | 27 #ifndef ArrayBufferContents_h |
| 28 #define ArrayBufferContents_h | 28 #define ArrayBufferContents_h |
| 29 | 29 |
| 30 #include "wtf/Allocator.h" | 30 #include "wtf/Allocator.h" |
| 31 #include "wtf/Assertions.h" | 31 #include "wtf/Assertions.h" |
| 32 #include "wtf/MainThread.h" |
| 32 #include "wtf/Noncopyable.h" | 33 #include "wtf/Noncopyable.h" |
| 33 #include "wtf/RefPtr.h" | 34 #include "wtf/RefPtr.h" |
| 34 #include "wtf/ThreadSafeRefCounted.h" | 35 #include "wtf/ThreadSafeRefCounted.h" |
| 35 #include "wtf/WTF.h" | 36 #include "wtf/WTF.h" |
| 36 #include "wtf/WTFExport.h" | 37 #include "wtf/WTFExport.h" |
| 37 | 38 |
| 38 namespace WTF { | 39 namespace WTF { |
| 39 | 40 |
| 41 typedef void(*AdjustAmountOfExternalAllocatedMemoryFunction)(int size); |
| 42 |
| 40 class WTF_EXPORT ArrayBufferContents { | 43 class WTF_EXPORT ArrayBufferContents { |
| 41 WTF_MAKE_NONCOPYABLE(ArrayBufferContents); | 44 WTF_MAKE_NONCOPYABLE(ArrayBufferContents); |
| 42 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 45 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 43 public: | 46 public: |
| 44 enum InitializationPolicy { | 47 enum InitializationPolicy { |
| 45 ZeroInitialize, | 48 ZeroInitialize, |
| 46 DontInitialize | 49 DontInitialize |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 enum SharingType { | 52 enum SharingType { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 69 unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0
; } | 72 unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0
; } |
| 70 bool isShared() const { return m_holder ? m_holder->isShared() : false; } | 73 bool isShared() const { return m_holder ? m_holder->isShared() : false; } |
| 71 | 74 |
| 72 void transfer(ArrayBufferContents& other); | 75 void transfer(ArrayBufferContents& other); |
| 73 void shareWith(ArrayBufferContents& other); | 76 void shareWith(ArrayBufferContents& other); |
| 74 void copyTo(ArrayBufferContents& other); | 77 void copyTo(ArrayBufferContents& other); |
| 75 | 78 |
| 76 static void allocateMemory(size_t, InitializationPolicy, void*&); | 79 static void allocateMemory(size_t, InitializationPolicy, void*&); |
| 77 static void allocateMemoryOrNull(size_t, InitializationPolicy, void*&); | 80 static void allocateMemoryOrNull(size_t, InitializationPolicy, void*&); |
| 78 static void freeMemory(void*, size_t); | 81 static void freeMemory(void*, size_t); |
| 79 static void setAdjustAmoutOfExternalAllocatedMemoryFunction(AdjustAmountOfEx
ternalAllocatedMemoryFunction function) | 82 static void initialize(AdjustAmountOfExternalAllocatedMemoryFunction functio
n) |
| 80 { | 83 { |
| 84 ASSERT(isMainThread()); |
| 81 ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction); | 85 ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction); |
| 82 s_adjustAmountOfExternalAllocatedMemoryFunction = function; | 86 s_adjustAmountOfExternalAllocatedMemoryFunction = function; |
| 83 } | 87 } |
| 84 | 88 |
| 85 private: | 89 private: |
| 86 static void allocateMemoryWithFlags(size_t, InitializationPolicy, int, void*
&); | 90 static void allocateMemoryWithFlags(size_t, InitializationPolicy, int, void*
&); |
| 87 class DataHolder : public ThreadSafeRefCounted<DataHolder> { | 91 class DataHolder : public ThreadSafeRefCounted<DataHolder> { |
| 88 WTF_MAKE_NONCOPYABLE(DataHolder); | 92 WTF_MAKE_NONCOPYABLE(DataHolder); |
| 89 public: | 93 public: |
| 90 DataHolder(); | 94 DataHolder(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 SharingType m_isShared; | 108 SharingType m_isShared; |
| 105 }; | 109 }; |
| 106 | 110 |
| 107 RefPtr<DataHolder> m_holder; | 111 RefPtr<DataHolder> m_holder; |
| 108 static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExterna
lAllocatedMemoryFunction; | 112 static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExterna
lAllocatedMemoryFunction; |
| 109 }; | 113 }; |
| 110 | 114 |
| 111 } // namespace WTF | 115 } // namespace WTF |
| 112 | 116 |
| 113 #endif // ArrayBufferContents_h | 117 #endif // ArrayBufferContents_h |
| OLD | NEW |