3 // Copyright (C) 2009 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 /** @file profile/impl/profiler_state.h
32 * @brief Global profiler state.
35 // Written by Lixia Liu and Silvius Rus.
37 #ifndef PROFCXX_PROFILER_STATE_H__
38 #define PROFCXX_PROFILER_STATE_H__ 1
40 #ifdef __GXX_EXPERIMENTAL_CXX0X__
46 namespace __cxxprof_impl
49 /** @brief Profiling mode on/off state. */
50 template <int _Unused=0>
55 static __state<_Unused>* _S_diag_state;
57 __state() : _M_state(__INVALID) {}
60 bool __is_on() { return _M_state == __ON; }
61 bool __is_off() { return _M_state == __OFF; }
62 bool __is_invalid() { return _M_state == __INVALID; }
63 void __turn_on() { _M_state = __ON; }
64 void __turn_off() { _M_state = __OFF; }
67 enum __state_type { __ON, __OFF, __INVALID };
68 __state_type _M_state;
71 template <int _Unused>
72 __state<_Unused>* __state<_Unused>::_S_diag_state = NULL;
76 return __state<0>::_S_diag_state && __state<0>::_S_diag_state->__is_on();
79 inline bool __is_off()
81 return __state<0>::_S_diag_state && __state<0>::_S_diag_state->__is_off();
84 inline bool __is_invalid()
86 return (!__state<0>::_S_diag_state
87 || __state<0>::_S_diag_state->__is_invalid());
90 inline void __turn_on()
92 if (!__state<0>::_S_diag_state) {
93 __state<0>::_S_diag_state = new __state<0>();
95 __state<0>::_S_diag_state->__turn_on();
98 inline void __turn_off()
100 if (!__state<0>::_S_diag_state) {
101 __state<0>::_S_diag_state = new __state<0>();
103 __state<0>::_S_diag_state->__turn_off();
106 } // end namespace __cxxprof_impl
107 #endif /* PROFCXX_PROFILER_STATE_H__ */