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

Unified Diff: vm/timer.h

Issue 9228007: - Account for the possibility of timer objects being nested. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 8 years, 11 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 | « vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/timer.h
===================================================================
--- vm/timer.h (revision 3342)
+++ vm/timer.h (working copy)
@@ -15,13 +15,15 @@
class Timer : public ValueObject {
public:
Timer(bool enabled, const char* message)
- : start_(0), stop_(0), total_(0), enabled_(enabled), message_(message) {}
+ : start_(0), stop_(0), total_(0),
+ enabled_(enabled), running_(false), message_(message) {}
~Timer() {}
// Start timer.
void Start() {
if (enabled_) {
start_ = OS::GetCurrentTimeMicros();
+ running_ = true;
}
}
@@ -29,8 +31,10 @@
void Stop() {
if (enabled_) {
ASSERT(start_ != 0);
+ ASSERT(running());
stop_ = OS::GetCurrentTimeMicros();
total_ += ElapsedMicros();
+ running_ = false;
}
}
@@ -46,6 +50,7 @@
// Accessors.
bool enabled() const { return enabled_; }
+ bool running() const { return running_; }
const char* message() const { return message_; }
private:
@@ -63,6 +68,7 @@
start_ = 0;
stop_ = 0;
total_ = 0;
+ running_ = false;
}
}
@@ -70,6 +76,7 @@
int64_t stop_;
int64_t total_;
bool enabled_;
+ bool running_;
const char* message_;
DISALLOW_COPY_AND_ASSIGN(Timer);
@@ -135,19 +142,27 @@
// }
class TimerScope : public ValueObject {
public:
- TimerScope(bool flag, Timer* timer) : flag_(flag), timer_(timer) {
+ TimerScope(bool flag, Timer* timer)
+ : flag_(flag), nested_(false), timer_(timer) {
if (flag_) {
- timer_->Start();
+ if (!timer_->running()) {
+ timer_->Start();
+ } else {
+ nested_ = true;
+ }
}
}
~TimerScope() {
if (flag_) {
- timer_->Stop();
+ if (!nested_) {
+ timer_->Stop();
+ }
}
}
private:
bool flag_;
+ bool nested_;
Timer* timer_;
DISALLOW_COPY_AND_ASSIGN(TimerScope);
};
« no previous file with comments | « vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698