| Index: Source/wtf/ArrayBufferContents.h
|
| diff --git a/Source/wtf/ArrayBufferContents.h b/Source/wtf/ArrayBufferContents.h
|
| index 4bd137f02ce984f0fe9c70f30e1564b269498f7a..b40ea0216019f2cc467bae0cce13d3d8ca3f91ec 100644
|
| --- a/Source/wtf/ArrayBufferContents.h
|
| +++ b/Source/wtf/ArrayBufferContents.h
|
| @@ -29,6 +29,8 @@
|
|
|
| #include "wtf/ArrayBufferDeallocationObserver.h"
|
| #include "wtf/Noncopyable.h"
|
| +#include "wtf/RefPtr.h"
|
| +#include "wtf/ThreadSafeRefCounted.h"
|
| #include "wtf/WTFExport.h"
|
|
|
| namespace WTF {
|
| @@ -41,35 +43,38 @@ public:
|
| DontInitialize
|
| };
|
|
|
| + enum SharingType {
|
| + NotShared,
|
| + Shared,
|
| + };
|
| +
|
| ArrayBufferContents();
|
| - ArrayBufferContents(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
|
| + ArrayBufferContents(unsigned numElements, unsigned elementByteSize, SharingType isShared, ArrayBufferContents::InitializationPolicy);
|
|
|
| // Use with care. data must be allocated with allocateMemory.
|
| // ArrayBufferContents will take ownership of the data and free it (using freeMemory)
|
| // upon destruction.
|
| // This constructor will not call observer->StartObserving(), so it is a responsibility
|
| // of the caller to make sure JS knows about external memory.
|
| - ArrayBufferContents(void* data, unsigned sizeInBytes, ArrayBufferDeallocationObserver*);
|
| + ArrayBufferContents(void* data, unsigned sizeInBytes, SharingType isShared, ArrayBufferDeallocationObserver*);
|
|
|
| ~ArrayBufferContents();
|
|
|
| void clear();
|
|
|
| - void* data() const { return m_data; }
|
| - unsigned sizeInBytes() const { return m_sizeInBytes; }
|
| + void* data() const { return m_holder ? m_holder->data() : nullptr; }
|
| + unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0; }
|
| + bool isShared() const { return m_holder ? m_holder->isShared() : false; }
|
|
|
| void setDeallocationObserver(ArrayBufferDeallocationObserver& observer)
|
| {
|
| - if (!m_deallocationObserver) {
|
| - m_deallocationObserver = &observer;
|
| - m_deallocationObserver->blinkAllocatedMemory(m_sizeInBytes);
|
| - }
|
| + ASSERT(m_holder);
|
| + m_holder->setDeallocationObserver(observer);
|
| }
|
| void setDeallocationObserverWithoutAllocationNotification(ArrayBufferDeallocationObserver& observer)
|
| {
|
| - if (!m_deallocationObserver) {
|
| - m_deallocationObserver = &observer;
|
| - }
|
| + ASSERT(m_holder);
|
| + m_holder->setDeallocationObserverWithoutAllocationNotification(observer);
|
| }
|
|
|
| void transfer(ArrayBufferContents& other);
|
| @@ -79,9 +84,30 @@ public:
|
| static void freeMemory(void*, size_t);
|
|
|
| private:
|
| - void* m_data;
|
| - unsigned m_sizeInBytes;
|
| - ArrayBufferDeallocationObserver* m_deallocationObserver;
|
| + class DataHolder : public ThreadSafeRefCounted<DataHolder> {
|
| + WTF_MAKE_NONCOPYABLE(DataHolder);
|
| + public:
|
| + DataHolder();
|
| + ~DataHolder();
|
| +
|
| + void allocateNew(unsigned sizeInBytes, SharingType isShared, InitializationPolicy, ArrayBufferDeallocationObserver*);
|
| + void adopt(void* data, unsigned sizeInBytes, SharingType isShared, ArrayBufferDeallocationObserver*);
|
| + void copyTo(DataHolder& other);
|
| +
|
| + void* data() const { return m_data; }
|
| + unsigned sizeInBytes() const { return m_sizeInBytes; }
|
| + bool isShared() const { return m_isShared == Shared; }
|
| + void setDeallocationObserver(ArrayBufferDeallocationObserver&);
|
| + void setDeallocationObserverWithoutAllocationNotification(ArrayBufferDeallocationObserver&);
|
| +
|
| + private:
|
| + void* m_data;
|
| + unsigned m_sizeInBytes;
|
| + SharingType m_isShared;
|
| + ArrayBufferDeallocationObserver* m_deallocationObserver;
|
| + };
|
| +
|
| + RefPtr<DataHolder> m_holder;
|
| };
|
|
|
| } // namespace WTF
|
|
|