Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Unified Diff: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h

Issue 2343643003: binding: Makes assertion of adjustAmountOfExternalAllocatedMemory more exact. (Closed)
Patch Set: Factor it out to checkIfAAOEAMIsConsistent. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
diff --git a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
index c53131a76f9d1c614ca121a1a367b58fd053c3d8..d7c9e1f647e36c3bf78b27bd11592afb44998d9c 100644
--- a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
+++ b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
@@ -37,13 +37,13 @@
namespace WTF {
-typedef void (*AdjustAmountOfExternalAllocatedMemoryFunction)(int64_t size);
-
class WTF_EXPORT ArrayBufferContents {
WTF_MAKE_NONCOPYABLE(ArrayBufferContents);
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
+ using AdjustAmountOfExternalAllocatedMemoryFunction = void (*)(int64_t diff);
+
enum InitializationPolicy { ZeroInitialize, DontInitialize };
enum SharingType {
@@ -55,7 +55,7 @@ class WTF_EXPORT ArrayBufferContents {
ArrayBufferContents(unsigned numElements,
unsigned elementByteSize,
SharingType isShared,
- ArrayBufferContents::InitializationPolicy);
+ InitializationPolicy);
// Use with care. data must be allocated with allocateMemory.
// ArrayBufferContents will take ownership of the data and free it (using
@@ -83,8 +83,9 @@ class WTF_EXPORT ArrayBufferContents {
static void freeMemory(void*, size_t);
static void initialize(
AdjustAmountOfExternalAllocatedMemoryFunction function) {
- ASSERT(isMainThread());
- ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction);
+ DCHECK(isMainThread());
+ DCHECK_EQ(s_adjustAmountOfExternalAllocatedMemoryFunction,
+ defaultAdjustAmountOfExternalAllocatedMemoryFunction);
s_adjustAmountOfExternalAllocatedMemoryFunction = function;
}
@@ -93,6 +94,10 @@ class WTF_EXPORT ArrayBufferContents {
InitializationPolicy,
int,
void*&);
+
+ static void defaultAdjustAmountOfExternalAllocatedMemoryFunction(
+ int64_t diff);
+
class DataHolder : public ThreadSafeRefCounted<DataHolder> {
WTF_MAKE_NONCOPYABLE(DataHolder);
@@ -113,14 +118,28 @@ class WTF_EXPORT ArrayBufferContents {
private:
void adjustAmountOfExternalAllocatedMemory(int64_t diff) {
- if (ArrayBufferContents::s_adjustAmountOfExternalAllocatedMemoryFunction)
- ArrayBufferContents::s_adjustAmountOfExternalAllocatedMemoryFunction(
- diff);
+ checkIfAdjustAmountOfExternalAllocatedMemoryIsConsistent();
+ s_adjustAmountOfExternalAllocatedMemoryFunction(diff);
}
void adjustAmountOfExternalAllocatedMemory(unsigned diff) {
adjustAmountOfExternalAllocatedMemory(static_cast<int64_t>(diff));
}
+ void checkIfAdjustAmountOfExternalAllocatedMemoryIsConsistent() {
+ DCHECK(s_adjustAmountOfExternalAllocatedMemoryFunction);
+
+#if ENABLE(ASSERT)
+ // Make sure that the function actually used is always the same.
+ // Shouldn't be updated during its use.
+ if (!s_lastUsedAdjustAmountOfExternalAllocatedMemoryFunction) {
+ s_lastUsedAdjustAmountOfExternalAllocatedMemoryFunction =
+ s_adjustAmountOfExternalAllocatedMemoryFunction;
+ }
+ DCHECK_EQ(s_adjustAmountOfExternalAllocatedMemoryFunction,
+ s_lastUsedAdjustAmountOfExternalAllocatedMemoryFunction);
+#endif
+ }
+
void* m_data;
unsigned m_sizeInBytes;
SharingType m_isShared;
@@ -129,6 +148,10 @@ class WTF_EXPORT ArrayBufferContents {
RefPtr<DataHolder> m_holder;
static AdjustAmountOfExternalAllocatedMemoryFunction
s_adjustAmountOfExternalAllocatedMemoryFunction;
+#if ENABLE(ASSERT)
+ static AdjustAmountOfExternalAllocatedMemoryFunction
+ s_lastUsedAdjustAmountOfExternalAllocatedMemoryFunction;
+#endif
};
} // namespace WTF

Powered by Google App Engine
This is Rietveld 408576698