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

Unified Diff: runtime/vm/timeline.cc

Issue 1297443002: Improve timeline iterators and tests (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/timeline.h ('k') | runtime/vm/timeline_analysis.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/timeline.cc
diff --git a/runtime/vm/timeline.cc b/runtime/vm/timeline.cc
index d2cb26cef0fe24204917450c541f5c673491651c..a1fefeb8a68c61e1b534f4633a5c6eae0d737158 100644
--- a/runtime/vm/timeline.cc
+++ b/runtime/vm/timeline.cc
@@ -714,37 +714,44 @@ void TimelineEventBlock::Reset() {
TimelineEventBlockIterator::TimelineEventBlockIterator(
TimelineEventRecorder* recorder)
: current_(NULL),
- recorder_(recorder) {
- if (recorder_ == NULL) {
- return;
- }
- recorder->lock_.Lock();
+ recorder_(NULL) {
+ Reset(recorder);
}
TimelineEventBlockIterator::~TimelineEventBlockIterator() {
+ Reset(NULL);
+}
+
+
+void TimelineEventBlockIterator::Reset(TimelineEventRecorder* recorder) {
+ // Clear current.
+ current_ = NULL;
+ if (recorder_ != NULL) {
+ // Unlock old recorder.
+ recorder_->lock_.Unlock();
+ }
+ recorder_ = recorder;
if (recorder_ == NULL) {
return;
}
- recorder_->lock_.Unlock();
+ // Lock new recorder.
+ recorder_->lock_.Lock();
+ // Queue up first block.
+ current_ = recorder_->GetHeadBlock();
}
-void TimelineEventBlockIterator::Reset() {
- current_ = NULL;
+bool TimelineEventBlockIterator::HasNext() const {
+ return current_ != NULL;
}
-bool TimelineEventBlockIterator::Next() {
- if (recorder_ == NULL) {
- return false;
- }
- if (current_ == NULL) {
- current_ = recorder_->GetHeadBlock();
- } else {
- current_ = current_->next();
- }
- return current_ != NULL;
+TimelineEventBlock* TimelineEventBlockIterator::Next() {
+ ASSERT(current_ != NULL);
+ TimelineEventBlock* r = current_;
+ current_ = current_->next();
+ return r;
}
} // namespace dart
« no previous file with comments | « runtime/vm/timeline.h ('k') | runtime/vm/timeline_analysis.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698