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

Unified Diff: third_party/WebKit/Source/wtf/PartitionAlloc.h

Issue 1463683002: Switch wtf/SpinLock to std::atomic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: asan iwyu Created 5 years 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/PartitionAlloc.h
diff --git a/third_party/WebKit/Source/wtf/PartitionAlloc.h b/third_party/WebKit/Source/wtf/PartitionAlloc.h
index 1dba60909682ef2c1f909a73711c935398236f57..2f2d82158f772d7b3c948ec822f8eed05d08a492 100644
--- a/third_party/WebKit/Source/wtf/PartitionAlloc.h
+++ b/third_party/WebKit/Source/wtf/PartitionAlloc.h
@@ -309,7 +309,7 @@ struct WTF_EXPORT PartitionRootBase {
int16_t globalEmptyPageRingIndex;
uintptr_t invertedSelf;
- static int gInitializedLock;
+ static SpinLock gInitializedLock;
static bool gInitialized;
// gSeedPage is used as a sentinel to indicate that there is no page
// in the active page list. We can use nullptr, but in that case we need
@@ -330,7 +330,7 @@ struct PartitionRoot : public PartitionRootBase {
// Never instantiate a PartitionRootGeneric directly, instead use PartitionAllocatorGeneric.
struct PartitionRootGeneric : public PartitionRootBase {
- int lock;
+ SpinLock lock;
// Some pre-computed constants.
size_t orderIndexShifts[kBitsPerSizet + 1];
size_t orderSubIndexMasks[kBitsPerSizet + 1];
@@ -752,16 +752,18 @@ ALWAYS_INLINE void* partitionAllocGenericFlags(PartitionRootGeneric* root, int f
size_t requestedSize = size;
size = partitionCookieSizeAdjustAdd(size);
PartitionBucket* bucket = partitionGenericSizeToBucket(root, size);
- spinLockLock(&root->lock);
- // TODO(bashi): Remove following RELEAE_ASSERT()s once we find the cause of
- // http://crbug.com/514141
+ void* ret = nullptr;
+ {
+ SpinLock::Guard guard(root->lock);
+ // TODO(bashi): Remove following RELEAE_ASSERT()s once we find the cause of
+ // http://crbug.com/514141
#if OS(ANDROID)
- RELEASE_ASSERT(bucket >= &root->buckets[0] || bucket == &PartitionRootGeneric::gPagedBucket);
- RELEASE_ASSERT(bucket <= &root->buckets[kGenericNumBuckets - 1] || bucket == &PartitionRootGeneric::gPagedBucket);
- RELEASE_ASSERT(root->initialized);
+ RELEASE_ASSERT(bucket >= &root->buckets[0] || bucket == &PartitionRootGeneric::gPagedBucket);
+ RELEASE_ASSERT(bucket <= &root->buckets[kGenericNumBuckets - 1] || bucket == &PartitionRootGeneric::gPagedBucket);
+ RELEASE_ASSERT(root->initialized);
#endif
- void* ret = partitionBucketAlloc(root, flags, size, bucket);
- spinLockUnlock(&root->lock);
+ ret = partitionBucketAlloc(root, flags, size, bucket);
+ }
PartitionAllocHooks::allocationHookIfEnabled(ret, requestedSize, typeName);
return ret;
#endif
@@ -786,9 +788,10 @@ ALWAYS_INLINE void partitionFreeGeneric(PartitionRootGeneric* root, void* ptr)
ptr = partitionCookieFreePointerAdjust(ptr);
ASSERT(partitionPointerIsValid(ptr));
PartitionPage* page = partitionPointerToPage(ptr);
- spinLockLock(&root->lock);
- partitionFreeWithPage(ptr, page);
- spinLockUnlock(&root->lock);
+ {
+ SpinLock::Guard guard(root->lock);
+ partitionFreeWithPage(ptr, page);
+ }
#endif
}

Powered by Google App Engine
This is Rietveld 408576698