Commit bb3b74ea authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

Retire AtomicNumber.

Bug: chromium:842083
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I9a8d8327bfbab95cf9bdddb096804b65270cdfed
Reviewed-on: https://chromium-review.googlesource.com/1127944
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54388}
parent 60aa28ec
...@@ -15,46 +15,6 @@ namespace v8 { ...@@ -15,46 +15,6 @@ namespace v8 {
namespace base { namespace base {
// Deprecated. Use std::atomic<T> for new code. // Deprecated. Use std::atomic<T> for new code.
template <class T>
class AtomicNumber {
public:
AtomicNumber() : value_(0) {}
explicit AtomicNumber(T initial) : value_(initial) {}
// Returns the value after incrementing.
V8_INLINE T Increment(T increment) {
return static_cast<T>(base::Barrier_AtomicIncrement(
&value_, static_cast<base::AtomicWord>(increment)));
}
// Returns the value after decrementing.
V8_INLINE T Decrement(T decrement) {
return static_cast<T>(base::Barrier_AtomicIncrement(
&value_, -static_cast<base::AtomicWord>(decrement)));
}
V8_INLINE T Value() const {
return static_cast<T>(base::Acquire_Load(&value_));
}
V8_INLINE void SetValue(T new_value) {
base::Release_Store(&value_, static_cast<base::AtomicWord>(new_value));
}
V8_INLINE T operator=(T value) {
SetValue(value);
return value;
}
V8_INLINE T operator+=(T value) { return Increment(value); }
V8_INLINE T operator-=(T value) { return Decrement(value); }
private:
STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord));
base::AtomicWord value_;
};
// Flag using T atomically. Also accepts void* as T. // Flag using T atomically. Also accepts void* as T.
template <typename T> template <typename T>
class AtomicValue { class AtomicValue {
......
...@@ -96,7 +96,7 @@ class V8_EXPORT_PRIVATE Cancelable { ...@@ -96,7 +96,7 @@ class V8_EXPORT_PRIVATE Cancelable {
protected: protected:
bool TryRun() { return status_.TrySetValue(kWaiting, kRunning); } bool TryRun() { return status_.TrySetValue(kWaiting, kRunning); }
bool IsRunning() { return status_.Value() == kRunning; } bool IsRunning() { return status_.Value() == kRunning; }
intptr_t CancelAttempts() { return cancel_counter_.Value(); } intptr_t CancelAttempts() { return cancel_counter_; }
private: private:
// Identifies the state a cancelable task is in: // Identifies the state a cancelable task is in:
...@@ -116,7 +116,7 @@ class V8_EXPORT_PRIVATE Cancelable { ...@@ -116,7 +116,7 @@ class V8_EXPORT_PRIVATE Cancelable {
if (status_.TrySetValue(kWaiting, kCanceled)) { if (status_.TrySetValue(kWaiting, kCanceled)) {
return true; return true;
} }
cancel_counter_.Increment(1); cancel_counter_++;
return false; return false;
} }
...@@ -127,7 +127,7 @@ class V8_EXPORT_PRIVATE Cancelable { ...@@ -127,7 +127,7 @@ class V8_EXPORT_PRIVATE Cancelable {
// The counter is incremented for failing tries to cancel a task. This can be // The counter is incremented for failing tries to cancel a task. This can be
// used by the task itself as an indication how often external entities tried // used by the task itself as an indication how often external entities tried
// to abort it. // to abort it.
base::AtomicNumber<intptr_t> cancel_counter_; std::atomic<intptr_t> cancel_counter_;
friend class CancelableTaskManager; friend class CancelableTaskManager;
......
...@@ -2436,7 +2436,7 @@ class VerboseAccountingAllocator : public AccountingAllocator { ...@@ -2436,7 +2436,7 @@ class VerboseAccountingAllocator : public AccountingAllocator {
"\"name\": \"%s\", " "\"name\": \"%s\", "
"\"size\": %" PRIuS "\"size\": %" PRIuS
"," ","
"\"nesting\": %" PRIuS "}\n", "\"nesting\": %zu}\n",
type, reinterpret_cast<void*>(heap_->isolate()), type, reinterpret_cast<void*>(heap_->isolate()),
heap_->isolate()->time_millis_since_init(), heap_->isolate()->time_millis_since_init(),
reinterpret_cast<const void*>(zone), zone->name(), reinterpret_cast<const void*>(zone), zone->name(),
......
...@@ -58,7 +58,7 @@ TickSample* ProfilerEventsProcessor::StartTickSample() { ...@@ -58,7 +58,7 @@ TickSample* ProfilerEventsProcessor::StartTickSample() {
void* address = ticks_buffer_.StartEnqueue(); void* address = ticks_buffer_.StartEnqueue();
if (address == nullptr) return nullptr; if (address == nullptr) return nullptr;
TickSampleEventRecord* evt = TickSampleEventRecord* evt =
new (address) TickSampleEventRecord(last_code_event_id_.Value()); new (address) TickSampleEventRecord(last_code_event_id_);
return &evt->sample; return &evt->sample;
} }
......
...@@ -63,14 +63,14 @@ ProfilerEventsProcessor::~ProfilerEventsProcessor() { ...@@ -63,14 +63,14 @@ ProfilerEventsProcessor::~ProfilerEventsProcessor() {
} }
void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {
event.generic.order = last_code_event_id_.Increment(1); event.generic.order = ++last_code_event_id_;
events_buffer_.Enqueue(event); events_buffer_.Enqueue(event);
} }
void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from, void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from,
int fp_to_sp_delta) { int fp_to_sp_delta) {
TickSampleEventRecord record(last_code_event_id_.Value()); TickSampleEventRecord record(last_code_event_id_);
RegisterState regs; RegisterState regs;
Address fp = isolate->c_entry_fp(isolate->thread_local_top()); Address fp = isolate->c_entry_fp(isolate->thread_local_top());
regs.sp = reinterpret_cast<void*>(fp - fp_to_sp_delta); regs.sp = reinterpret_cast<void*>(fp - fp_to_sp_delta);
...@@ -82,7 +82,7 @@ void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from, ...@@ -82,7 +82,7 @@ void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from,
void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate, void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate,
bool update_stats) { bool update_stats) {
TickSampleEventRecord record(last_code_event_id_.Value()); TickSampleEventRecord record(last_code_event_id_);
RegisterState regs; RegisterState regs;
StackFrameIterator it(isolate); StackFrameIterator it(isolate);
if (!it.done()) { if (!it.done()) {
......
...@@ -183,7 +183,7 @@ class ProfilerEventsProcessor : public base::Thread { ...@@ -183,7 +183,7 @@ class ProfilerEventsProcessor : public base::Thread {
SamplingCircularQueue<TickSampleEventRecord, SamplingCircularQueue<TickSampleEventRecord,
kTickSampleQueueLength> ticks_buffer_; kTickSampleQueueLength> ticks_buffer_;
LockedQueue<TickSampleEventRecord> ticks_from_vm_buffer_; LockedQueue<TickSampleEventRecord> ticks_from_vm_buffer_;
base::AtomicNumber<unsigned> last_code_event_id_; std::atomic<unsigned> last_code_event_id_;
unsigned last_processed_code_event_id_; unsigned last_processed_code_event_id_;
}; };
......
...@@ -10,79 +10,6 @@ ...@@ -10,79 +10,6 @@
namespace v8 { namespace v8 {
namespace base { namespace base {
TEST(AtomicNumber, Constructor) {
// Test some common types.
AtomicNumber<int> zero_int;
AtomicNumber<size_t> zero_size_t;
AtomicNumber<intptr_t> zero_intptr_t;
EXPECT_EQ(0, zero_int.Value());
EXPECT_EQ(0u, zero_size_t.Value());
EXPECT_EQ(0, zero_intptr_t.Value());
}
TEST(AtomicNumber, Value) {
AtomicNumber<int> a(1);
EXPECT_EQ(1, a.Value());
AtomicNumber<int> b(-1);
EXPECT_EQ(-1, b.Value());
AtomicNumber<size_t> c(1);
EXPECT_EQ(1u, c.Value());
AtomicNumber<size_t> d(static_cast<size_t>(-1));
EXPECT_EQ(std::numeric_limits<size_t>::max(), d.Value());
}
TEST(AtomicNumber, SetValue) {
AtomicNumber<int> a(1);
a.SetValue(-1);
EXPECT_EQ(-1, a.Value());
}
TEST(AtomicNumber, Increment) {
AtomicNumber<int> a(std::numeric_limits<int>::max());
a.Increment(1);
EXPECT_EQ(std::numeric_limits<int>::min(), a.Value());
// Check that potential signed-ness of the underlying storage has no impact
// on unsigned types.
AtomicNumber<size_t> b(std::numeric_limits<intptr_t>::max());
b.Increment(1);
EXPECT_EQ(static_cast<size_t>(std::numeric_limits<intptr_t>::max()) + 1,
b.Value());
// Should work as decrement as well.
AtomicNumber<size_t> c(1);
c.Increment(-1);
EXPECT_EQ(0u, c.Value());
c.Increment(-1);
EXPECT_EQ(std::numeric_limits<size_t>::max(), c.Value());
}
TEST(AtomicNumber, Decrement) {
AtomicNumber<size_t> a(std::numeric_limits<size_t>::max());
a.Increment(1);
EXPECT_EQ(0u, a.Value());
a.Decrement(1);
EXPECT_EQ(std::numeric_limits<size_t>::max(), a.Value());
}
TEST(AtomicNumber, OperatorAdditionAssignment) {
AtomicNumber<size_t> a(0u);
AtomicNumber<size_t> b(std::numeric_limits<size_t>::max());
a += b.Value();
EXPECT_EQ(a.Value(), b.Value());
EXPECT_EQ(b.Value(), std::numeric_limits<size_t>::max());
}
TEST(AtomicNumber, OperatorSubtractionAssignment) {
AtomicNumber<size_t> a(std::numeric_limits<size_t>::max());
AtomicNumber<size_t> b(std::numeric_limits<size_t>::max());
a -= b.Value();
EXPECT_EQ(a.Value(), 0u);
EXPECT_EQ(b.Value(), std::numeric_limits<size_t>::max());
}
namespace { namespace {
enum TestFlag : base::AtomicWord { enum TestFlag : base::AtomicWord {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment