This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 3/5] timevar.h: Add an auto_timevar class
- From: David Malcolm <dmalcolm at redhat dot com>
- To: jit at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Mon, 13 Oct 2014 13:45:07 -0400
- Subject: [PATCH 3/5] timevar.h: Add an auto_timevar class
- Authentication-results: sourceware.org; auth=none
- References: <1413222308-25753-1-git-send-email-dmalcolm at redhat dot com>
This is used in a couple of places in jit/jit-playback.c to ensure
that we pop the timevar on every exit path from a function.
I could rewrite them if need be, but it does simplify things.
Written by Tom Tromey.
gcc/ChangeLog:
* timevar.h (class auto_timevar): New class.
---
gcc/timevar.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/gcc/timevar.h b/gcc/timevar.h
index 6703cc9..f018e39 100644
--- a/gcc/timevar.h
+++ b/gcc/timevar.h
@@ -110,6 +110,30 @@ timevar_pop (timevar_id_t tv)
timevar_pop_1 (tv);
}
+// This is a simple timevar wrapper class that pushes a timevar in its
+// constructor and pops the timevar in its destructor.
+class auto_timevar
+{
+ public:
+ auto_timevar (timevar_id_t tv)
+ : m_tv (tv)
+ {
+ timevar_push (m_tv);
+ }
+
+ ~auto_timevar ()
+ {
+ timevar_pop (m_tv);
+ }
+
+ private:
+
+ // Private to disallow copies.
+ auto_timevar (const auto_timevar &);
+
+ timevar_id_t m_tv;
+};
+
extern void print_time (const char *, long);
#endif /* ! GCC_TIMEVAR_H */
--
1.8.5.3