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

Side by Side Diff: base/task_scheduler/task_tracker.cc

Issue 2857613002: Synchronize memory in TaskTracker::Flush(). (Closed)
Patch Set: update_comment_in_header_file Created 3 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/task_tracker.h" 5 #include "base/task_scheduler/task_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 PerformShutdown(); 208 PerformShutdown();
209 DCHECK(IsShutdownComplete()); 209 DCHECK(IsShutdownComplete());
210 210
211 // Unblock Flush() when shutdown completes. 211 // Unblock Flush() when shutdown completes.
212 AutoSchedulerLock auto_lock(flush_lock_); 212 AutoSchedulerLock auto_lock(flush_lock_);
213 flush_cv_->Signal(); 213 flush_cv_->Signal();
214 } 214 }
215 215
216 void TaskTracker::Flush() { 216 void TaskTracker::Flush() {
217 AutoSchedulerLock auto_lock(flush_lock_); 217 AutoSchedulerLock auto_lock(flush_lock_);
218 while (subtle::NoBarrier_Load(&num_pending_undelayed_tasks_) != 0 && 218 while (subtle::Acquire_Load(&num_pending_undelayed_tasks_) != 0 &&
219 !IsShutdownComplete()) { 219 !IsShutdownComplete()) {
220 flush_cv_->Wait(); 220 flush_cv_->Wait();
221 } 221 }
222 } 222 }
223 223
224 bool TaskTracker::WillPostTask(const Task* task) { 224 bool TaskTracker::WillPostTask(const Task* task) {
225 DCHECK(task); 225 DCHECK(task);
226 226
227 if (!BeforePostTask(task->traits.shutdown_behavior())) 227 if (!BeforePostTask(task->traits.shutdown_behavior()))
228 return false; 228 return false;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 477
478 // This method can only be called after shutdown has started. 478 // This method can only be called after shutdown has started.
479 DCHECK(state_->HasShutdownStarted()); 479 DCHECK(state_->HasShutdownStarted());
480 DCHECK(shutdown_event_); 480 DCHECK(shutdown_event_);
481 481
482 shutdown_event_->Signal(); 482 shutdown_event_->Signal();
483 } 483 }
484 484
485 void TaskTracker::DecrementNumPendingUndelayedTasks() { 485 void TaskTracker::DecrementNumPendingUndelayedTasks() {
486 const auto new_num_pending_undelayed_tasks = 486 const auto new_num_pending_undelayed_tasks =
487 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); 487 subtle::Barrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1);
488 DCHECK_GE(new_num_pending_undelayed_tasks, 0); 488 DCHECK_GE(new_num_pending_undelayed_tasks, 0);
489 if (new_num_pending_undelayed_tasks == 0) { 489 if (new_num_pending_undelayed_tasks == 0) {
490 AutoSchedulerLock auto_lock(flush_lock_); 490 AutoSchedulerLock auto_lock(flush_lock_);
491 flush_cv_->Signal(); 491 flush_cv_->Signal();
492 } 492 }
493 } 493 }
494 494
495 void TaskTracker::RecordTaskLatencyHistogram(Task* task) { 495 void TaskTracker::RecordTaskLatencyHistogram(Task* task) {
496 const TimeDelta task_latency = TimeTicks::Now() - task->sequenced_time; 496 const TimeDelta task_latency = TimeTicks::Now() - task->sequenced_time;
497 task_latency_histograms_[static_cast<int>(task->traits.priority())] 497 task_latency_histograms_[static_cast<int>(task->traits.priority())]
498 [task->traits.may_block() || 498 [task->traits.may_block() ||
499 task->traits.with_base_sync_primitives() 499 task->traits.with_base_sync_primitives()
500 ? 1 500 ? 1
501 : 0] 501 : 0]
502 ->Add(task_latency.InMicroseconds()); 502 ->Add(task_latency.InMicroseconds());
503 } 503 }
504 504
505 } // namespace internal 505 } // namespace internal
506 } // namespace base 506 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698