diff options
author | Josh Blum | 2013-03-04 02:41:18 -0600 |
---|---|---|
committer | Josh Blum | 2013-03-04 02:41:18 -0600 |
commit | 885ad4bdc59f6bb97c2b472c06f5c63bd0391203 (patch) | |
tree | 75dcc67ecde6e260fd80463d6b49b7337701f8b6 /include | |
parent | e2268f682b77fdff1db5ddc6c410e226eb3dc1d5 (diff) | |
download | sandhi-885ad4bdc59f6bb97c2b472c06f5c63bd0391203.tar.gz sandhi-885ad4bdc59f6bb97c2b472c06f5c63bd0391203.tar.bz2 sandhi-885ad4bdc59f6bb97c2b472c06f5c63bd0391203.zip |
gras: move timer accumulate into public header
Diffstat (limited to 'include')
-rw-r--r-- | include/gras/chrono.hpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/gras/chrono.hpp b/include/gras/chrono.hpp index c976675..52b926b 100644 --- a/include/gras/chrono.hpp +++ b/include/gras/chrono.hpp @@ -19,6 +19,31 @@ namespace gras //! Get the number of ticks per second time_ticks_t time_tps(void); + + /*! + * Timer Accumulate creates a scoped timer object, + * which adds the time elapsed into the accumulator. + * Typically, the time elapsed is the absolute + * destructor time - absolute constructor time. + * However, the user may call done() to accumulate + * the time elapsed before the destructor is called. + */ + struct TimerAccumulate + { + //! Create a new timer object given the accumulator + TimerAccumulate(time_ticks_t &accum); + + //! Destructor accumulates the elapsed time + ~TimerAccumulate(void); + + //! Accumulate elapsed time before destructor + void done(void); + + time_ticks_t &accum; + time_ticks_t start; + bool is_done; + }; + } //--------------------------------------------------------------------// @@ -71,4 +96,26 @@ namespace gras #endif +namespace gras +{ + GRAS_FORCE_INLINE TimerAccumulate::TimerAccumulate(time_ticks_t &accum): + accum(accum), + start(time_now()), + is_done(false) + { + //NOP + } + + GRAS_FORCE_INLINE TimerAccumulate::~TimerAccumulate(void) + { + if (not is_done) this->done(); + } + + GRAS_FORCE_INLINE void TimerAccumulate::done(void) + { + accum += (time_now() - start); + is_done = true; + } +} + #endif /*INCLUDED_GRAS_CHRONO_HPP*/ |