Change signature of atomic increment/decrement functions to return void.

R=rmacnak@google.com

Review URL: https://codereview.chromium.org/1658983004 .
This commit is contained in:
Siva Annamalai
2016-02-03 09:15:35 -08:00
parent 3057754843
commit bf5d8f6efc
7 changed files with 50 additions and 56 deletions
+12 -2
View File
@@ -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.
+4 -6
View File
@@ -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);
}
+4 -6
View File
@@ -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);
}
+4 -6
View File
@@ -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);
}
+4 -6
View File
@@ -26,18 +26,16 @@ UNIT_TEST_CASE(FetchAndDecrement) {
}
UNIT_TEST_CASE(FetchAndIncrementBy) {
UNIT_TEST_CASE(IncrementBy) {
intptr_t v = 42;
EXPECT_EQ(static_cast<uintptr_t>(42),
AtomicOperations::FetchAndIncrementBy(&v, 100));
AtomicOperations::IncrementBy(&v, 100);
EXPECT_EQ(static_cast<intptr_t>(142), v);
}
UNIT_TEST_CASE(FetchAndDecrementBy) {
UNIT_TEST_CASE(DecrementBy) {
intptr_t v = 42;
EXPECT_EQ(static_cast<uintptr_t>(42),
AtomicOperations::FetchAndDecrementBy(&v, 41));
AtomicOperations::DecrementBy(&v, 41);
EXPECT_EQ(static_cast<intptr_t>(1), v);
}
+10 -16
View File
@@ -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<uintptr_t>(
InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
static_cast<LONGLONG>(value)));
InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
static_cast<LONGLONG>(value));
#elif defined(HOST_ARCH_IA32)
return static_cast<uintptr_t>(
InterlockedExchangeAdd(reinterpret_cast<LONG*>(p),
static_cast<LONG>(value)));
InterlockedExchangeAdd(reinterpret_cast<LONG*>(p),
static_cast<LONG>(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<uintptr_t>(
InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
static_cast<LONGLONG>(-value)));
InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
static_cast<LONGLONG>(-value));
#elif defined(HOST_ARCH_IA32)
return static_cast<uintptr_t>(
InterlockedExchangeAdd(reinterpret_cast<LONG*>(p),
static_cast<LONG>(-value)));
InterlockedExchangeAdd(reinterpret_cast<LONG*>(p),
static_cast<LONG>(-value));
#else
#error Unsupported host architecture.
#endif
+12 -14
View File
@@ -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);