Commit 8251c146 authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] Cleanup: Use std::atomic<T> instead of base::AtomicNumber<T> in sweeper.

Bug: chromium:842083
Change-Id: Ided2d8542e4501250208dde6146f00da77410f48
Reviewed-on: https://chromium-review.googlesource.com/1054234Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53121}
parent ff5bb7e5
...@@ -67,7 +67,7 @@ class Sweeper::SweeperTask final : public CancelableTask { ...@@ -67,7 +67,7 @@ class Sweeper::SweeperTask final : public CancelableTask {
public: public:
SweeperTask(Isolate* isolate, Sweeper* sweeper, SweeperTask(Isolate* isolate, Sweeper* sweeper,
base::Semaphore* pending_sweeper_tasks, base::Semaphore* pending_sweeper_tasks,
base::AtomicNumber<intptr_t>* num_sweeping_tasks, std::atomic<intptr_t>* num_sweeping_tasks,
AllocationSpace space_to_start) AllocationSpace space_to_start)
: CancelableTask(isolate), : CancelableTask(isolate),
sweeper_(sweeper), sweeper_(sweeper),
...@@ -93,13 +93,13 @@ class Sweeper::SweeperTask final : public CancelableTask { ...@@ -93,13 +93,13 @@ class Sweeper::SweeperTask final : public CancelableTask {
DCHECK(IsValidSweepingSpace(space_id)); DCHECK(IsValidSweepingSpace(space_id));
sweeper_->SweepSpaceFromTask(space_id); sweeper_->SweepSpaceFromTask(space_id);
} }
num_sweeping_tasks_->Decrement(1); (*num_sweeping_tasks_)--;
pending_sweeper_tasks_->Signal(); pending_sweeper_tasks_->Signal();
} }
Sweeper* const sweeper_; Sweeper* const sweeper_;
base::Semaphore* const pending_sweeper_tasks_; base::Semaphore* const pending_sweeper_tasks_;
base::AtomicNumber<intptr_t>* const num_sweeping_tasks_; std::atomic<intptr_t>* const num_sweeping_tasks_;
AllocationSpace space_to_start_; AllocationSpace space_to_start_;
GCTracer* const tracer_; GCTracer* const tracer_;
...@@ -151,12 +151,12 @@ void Sweeper::StartSweeping() { ...@@ -151,12 +151,12 @@ void Sweeper::StartSweeping() {
void Sweeper::StartSweeperTasks() { void Sweeper::StartSweeperTasks() {
DCHECK_EQ(0, num_tasks_); DCHECK_EQ(0, num_tasks_);
DCHECK_EQ(0, num_sweeping_tasks_.Value()); DCHECK_EQ(0, num_sweeping_tasks_);
if (FLAG_concurrent_sweeping && sweeping_in_progress_ && if (FLAG_concurrent_sweeping && sweeping_in_progress_ &&
!heap_->delay_sweeper_tasks_for_testing_) { !heap_->delay_sweeper_tasks_for_testing_) {
ForAllSweepingSpaces([this](AllocationSpace space) { ForAllSweepingSpaces([this](AllocationSpace space) {
DCHECK(IsValidSweepingSpace(space)); DCHECK(IsValidSweepingSpace(space));
num_sweeping_tasks_.Increment(1); num_sweeping_tasks_++;
auto task = base::make_unique<SweeperTask>( auto task = base::make_unique<SweeperTask>(
heap_->isolate(), this, &pending_sweeper_tasks_semaphore_, heap_->isolate(), this, &pending_sweeper_tasks_semaphore_,
&num_sweeping_tasks_, space); &num_sweeping_tasks_, space);
...@@ -200,11 +200,11 @@ void Sweeper::AbortAndWaitForTasks() { ...@@ -200,11 +200,11 @@ void Sweeper::AbortAndWaitForTasks() {
pending_sweeper_tasks_semaphore_.Wait(); pending_sweeper_tasks_semaphore_.Wait();
} else { } else {
// Aborted case. // Aborted case.
num_sweeping_tasks_.Decrement(1); num_sweeping_tasks_--;
} }
} }
num_tasks_ = 0; num_tasks_ = 0;
DCHECK_EQ(0, num_sweeping_tasks_.Value()); DCHECK_EQ(0, num_sweeping_tasks_);
} }
void Sweeper::EnsureCompleted() { void Sweeper::EnsureCompleted() {
...@@ -225,9 +225,7 @@ void Sweeper::EnsureCompleted() { ...@@ -225,9 +225,7 @@ void Sweeper::EnsureCompleted() {
sweeping_in_progress_ = false; sweeping_in_progress_ = false;
} }
bool Sweeper::AreSweeperTasksRunning() { bool Sweeper::AreSweeperTasksRunning() { return num_sweeping_tasks_ != 0; }
return num_sweeping_tasks_.Value() != 0;
}
int Sweeper::RawSweep(Page* p, FreeListRebuildingMode free_list_mode, int Sweeper::RawSweep(Page* p, FreeListRebuildingMode free_list_mode,
FreeSpaceTreatmentMode free_space_mode) { FreeSpaceTreatmentMode free_space_mode) {
......
...@@ -186,7 +186,7 @@ class Sweeper { ...@@ -186,7 +186,7 @@ class Sweeper {
bool sweeping_in_progress_; bool sweeping_in_progress_;
// Counter is actively maintained by the concurrent tasks to avoid querying // Counter is actively maintained by the concurrent tasks to avoid querying
// the semaphore for maintaining a task counter on the main thread. // the semaphore for maintaining a task counter on the main thread.
base::AtomicNumber<intptr_t> num_sweeping_tasks_; std::atomic<intptr_t> num_sweeping_tasks_;
// Used by PauseOrCompleteScope to signal early bailout to tasks. // Used by PauseOrCompleteScope to signal early bailout to tasks.
base::AtomicValue<bool> stop_sweeper_tasks_; base::AtomicValue<bool> stop_sweeper_tasks_;
......
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