From bf5d8f6efcbac03973613ccac831fc331db45af7 Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Wed, 3 Feb 2016 09:15:35 -0800 Subject: [PATCH] Change signature of atomic increment/decrement functions to return void. R=rmacnak@google.com Review URL: https://codereview.chromium.org/1658983004 . --- runtime/vm/atomic.h | 14 ++++++++++++-- runtime/vm/atomic_android.h | 10 ++++------ runtime/vm/atomic_linux.h | 10 ++++------ runtime/vm/atomic_macos.h | 10 ++++------ runtime/vm/atomic_test.cc | 10 ++++------ runtime/vm/atomic_win.h | 26 ++++++++++---------------- runtime/vm/pages.cc | 26 ++++++++++++-------------- 7 files changed, 50 insertions(+), 56 deletions(-) diff --git a/runtime/vm/atomic.h b/runtime/vm/atomic.h index 59a45ace74c..bd489d0de36 100644 --- a/runtime/vm/atomic.h +++ b/runtime/vm/atomic.h @@ -20,7 +20,12 @@ class AtomicOperations : public AllStatic { // NOTE: Not to be used for any atomic operations involving memory locations // that are accessed by generated code. static uintptr_t FetchAndIncrement(uintptr_t* p); - static uintptr_t FetchAndIncrementBy(intptr_t* p, intptr_t value); + + // Atomically increment the value at p by 'value'. + // + // NOTE: Not to be used for any atomic operations involving memory locations + // that are accessed by generated code. + static void IncrementBy(intptr_t* p, intptr_t value); // Atomically fetch the value at p and decrement the value at p. // Returns the original value at p. @@ -28,7 +33,12 @@ class AtomicOperations : public AllStatic { // NOTE: Not to be used for any atomic operations involving memory locations // that are accessed by generated code. static uintptr_t FetchAndDecrement(uintptr_t* p); - static uintptr_t FetchAndDecrementBy(intptr_t* p, intptr_t value); + + // Atomically decrement the value at p by 'value'. + // + // NOTE: Not to be used for any atomic operations involving memory locations + // that are accessed by generated code. + static void DecrementBy(intptr_t* p, intptr_t value); // Atomically compare *ptr to old_value, and if equal, store new_value. // Returns the original value at ptr. diff --git a/runtime/vm/atomic_android.h b/runtime/vm/atomic_android.h index 48f7f372fd0..c3727af868d 100644 --- a/runtime/vm/atomic_android.h +++ b/runtime/vm/atomic_android.h @@ -21,9 +21,8 @@ inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndIncrementBy(intptr_t* p, - intptr_t value) { - return __sync_fetch_and_add(p, value); +inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { + __sync_fetch_and_add(p, value); } @@ -32,9 +31,8 @@ inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndDecrementBy(intptr_t* p, - intptr_t value) { - return __sync_fetch_and_sub(p, value); +inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { + __sync_fetch_and_sub(p, value); } diff --git a/runtime/vm/atomic_linux.h b/runtime/vm/atomic_linux.h index 0103b532e90..15f03965f42 100644 --- a/runtime/vm/atomic_linux.h +++ b/runtime/vm/atomic_linux.h @@ -21,9 +21,8 @@ inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndIncrementBy(intptr_t* p, - intptr_t value) { - return __sync_fetch_and_add(p, value); +inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { + __sync_fetch_and_add(p, value); } @@ -32,9 +31,8 @@ inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndDecrementBy(intptr_t* p, - intptr_t value) { - return __sync_fetch_and_sub(p, value); +inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { + __sync_fetch_and_sub(p, value); } diff --git a/runtime/vm/atomic_macos.h b/runtime/vm/atomic_macos.h index 1cf951e838a..fd5af872c3f 100644 --- a/runtime/vm/atomic_macos.h +++ b/runtime/vm/atomic_macos.h @@ -21,9 +21,8 @@ inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndIncrementBy(intptr_t* p, - intptr_t value) { - return __sync_fetch_and_add(p, value); +inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { + __sync_fetch_and_add(p, value); } @@ -32,9 +31,8 @@ inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndDecrementBy(intptr_t* p, - intptr_t value) { - return __sync_fetch_and_sub(p, value); +inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { + __sync_fetch_and_sub(p, value); } diff --git a/runtime/vm/atomic_test.cc b/runtime/vm/atomic_test.cc index db9be229f76..6973d8b42a0 100644 --- a/runtime/vm/atomic_test.cc +++ b/runtime/vm/atomic_test.cc @@ -26,18 +26,16 @@ UNIT_TEST_CASE(FetchAndDecrement) { } -UNIT_TEST_CASE(FetchAndIncrementBy) { +UNIT_TEST_CASE(IncrementBy) { intptr_t v = 42; - EXPECT_EQ(static_cast(42), - AtomicOperations::FetchAndIncrementBy(&v, 100)); + AtomicOperations::IncrementBy(&v, 100); EXPECT_EQ(static_cast(142), v); } -UNIT_TEST_CASE(FetchAndDecrementBy) { +UNIT_TEST_CASE(DecrementBy) { intptr_t v = 42; - EXPECT_EQ(static_cast(42), - AtomicOperations::FetchAndDecrementBy(&v, 41)); + AtomicOperations::DecrementBy(&v, 41); EXPECT_EQ(static_cast(1), v); } diff --git a/runtime/vm/atomic_win.h b/runtime/vm/atomic_win.h index 2ade768e2f1..156303593f7 100644 --- a/runtime/vm/atomic_win.h +++ b/runtime/vm/atomic_win.h @@ -28,16 +28,13 @@ inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndIncrementBy(intptr_t* p, - intptr_t value) { +inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { #if defined(HOST_ARCH_X64) - return static_cast( - InterlockedExchangeAdd64(reinterpret_cast(p), - static_cast(value))); + InterlockedExchangeAdd64(reinterpret_cast(p), + static_cast(value)); #elif defined(HOST_ARCH_IA32) - return static_cast( - InterlockedExchangeAdd(reinterpret_cast(p), - static_cast(value))); + InterlockedExchangeAdd(reinterpret_cast(p), + static_cast(value)); #else #error Unsupported host architecture. #endif @@ -57,16 +54,13 @@ inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { } -inline uintptr_t AtomicOperations::FetchAndDecrementBy(intptr_t* p, - intptr_t value) { +inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { #if defined(HOST_ARCH_X64) - return static_cast( - InterlockedExchangeAdd64(reinterpret_cast(p), - static_cast(-value))); + InterlockedExchangeAdd64(reinterpret_cast(p), + static_cast(-value)); #elif defined(HOST_ARCH_IA32) - return static_cast( - InterlockedExchangeAdd(reinterpret_cast(p), - static_cast(-value))); + InterlockedExchangeAdd(reinterpret_cast(p), + static_cast(-value)); #else #error Unsupported host architecture. #endif diff --git a/runtime/vm/pages.cc b/runtime/vm/pages.cc index 6ea473a5c05..937d7bc1094 100644 --- a/runtime/vm/pages.cc +++ b/runtime/vm/pages.cc @@ -346,8 +346,8 @@ uword PageSpace::TryAllocateInFreshPage(intptr_t size, // Start of the newly allocated page is the allocated object. result = page->object_start(); // Note: usage_.capacity_in_words is increased by AllocatePage. - AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words), - (size >> kWordSizeLog2)); + AtomicOperations::IncrementBy(&(usage_.used_in_words), + (size >> kWordSizeLog2)); // Enqueue the remainder in the free list. uword free_start = result + size; intptr_t free_size = page->object_end() - free_start; @@ -384,8 +384,8 @@ uword PageSpace::TryAllocateInternal(intptr_t size, result = TryAllocateInFreshPage(size, type, growth_policy, is_locked); // usage_ is updated by the call above. } else { - AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words), - (size >> kWordSizeLog2)); + AtomicOperations::IncrementBy(&(usage_.used_in_words), + (size >> kWordSizeLog2)); } } else { // Large page allocation. @@ -404,8 +404,8 @@ uword PageSpace::TryAllocateInternal(intptr_t size, if (page != NULL) { result = page->object_start(); // Note: usage_.capacity_in_words is increased by AllocateLargePage. - AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words), - (size >> kWordSizeLog2)); + AtomicOperations::IncrementBy(&(usage_.used_in_words), + (size >> kWordSizeLog2)); } } } @@ -434,16 +434,14 @@ uword PageSpace::TryAllocateInternal(intptr_t size, void PageSpace::AllocateExternal(intptr_t size) { intptr_t size_in_words = size >> kWordSizeLog2; - AtomicOperations::FetchAndIncrementBy(&(usage_.external_in_words), - size_in_words); + AtomicOperations::IncrementBy(&(usage_.external_in_words), size_in_words); // TODO(koda): Control growth. } void PageSpace::FreeExternal(intptr_t size) { intptr_t size_in_words = size >> kWordSizeLog2; - AtomicOperations::FetchAndDecrementBy(&(usage_.external_in_words), - size_in_words); + AtomicOperations::DecrementBy(&(usage_.external_in_words), size_in_words); } @@ -1009,8 +1007,8 @@ uword PageSpace::TryAllocateDataBumpInternal(intptr_t size, ASSERT(remaining >= size); uword result = bump_top_; bump_top_ += size; - AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words), - (size >> kWordSizeLog2)); + AtomicOperations::IncrementBy(&(usage_.used_in_words), + (size >> kWordSizeLog2)); // Note: Remaining block is unwalkable until MakeIterable is called. #ifdef DEBUG if (bump_top_ < bump_end_) { @@ -1040,8 +1038,8 @@ uword PageSpace::TryAllocatePromoLocked(intptr_t size, FreeList* freelist = &freelist_[HeapPage::kData]; uword result = freelist->TryAllocateSmallLocked(size); if (result != 0) { - AtomicOperations::FetchAndIncrementBy(&(usage_.used_in_words), - (size >> kWordSizeLog2)); + AtomicOperations::IncrementBy(&(usage_.used_in_words), + (size >> kWordSizeLog2)); return result; } result = TryAllocateDataBumpLocked(size, growth_policy);