OSDN Git Service

03065715463873c6e52a382af4a4937f5ee32fbf
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / profile / impl / profiler_state.h
1 // -*- C++ -*-
2 //
3 // Copyright (C) 2009 Free Software Foundation, Inc.
4 //
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
9 // version.
10
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.
15
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.
20
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
29 // Public License.
30
31 /** @file profile/impl/profiler_state.h
32  *  @brief Global profiler state.
33  */
34
35 // Written by Lixia Liu and Silvius Rus.
36
37 #ifndef PROFCXX_PROFILER_STATE_H__
38 #define PROFCXX_PROFILER_STATE_H__ 1
39
40 #ifdef __GXX_EXPERIMENTAL_CXX0X__
41 #include <cstdio>
42 #else
43 #include <stdio.h>
44 #endif
45
46 namespace __cxxprof_impl
47 {
48
49 /** @brief Profiling mode on/off state.  */
50 template <int _Unused=0>
51 class __state
52 {
53  public:
54
55   static __state<_Unused>* _S_diag_state;
56
57   __state() : _M_state(__INVALID) {}
58   ~__state() {}
59
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; }
65
66  private:
67   enum __state_type { __ON, __OFF, __INVALID };
68   __state_type _M_state;
69 };
70
71 template <int _Unused>
72 __state<_Unused>* __state<_Unused>::_S_diag_state = NULL;
73
74 inline bool __is_on()
75 {
76   return __state<0>::_S_diag_state && __state<0>::_S_diag_state->__is_on();
77 }
78
79 inline bool __is_off()
80 {
81   return __state<0>::_S_diag_state && __state<0>::_S_diag_state->__is_off();
82 }
83
84 inline bool __is_invalid()
85 {
86   return (!__state<0>::_S_diag_state 
87           || __state<0>::_S_diag_state->__is_invalid());
88 }
89
90 inline void __turn_on()
91 {
92   if (!__state<0>::_S_diag_state) { 
93     __state<0>::_S_diag_state = new __state<0>();
94   }
95   __state<0>::_S_diag_state->__turn_on();
96 }
97
98 inline void __turn_off()
99 {
100   if (!__state<0>::_S_diag_state) { 
101     __state<0>::_S_diag_state = new __state<0>();
102   }
103   __state<0>::_S_diag_state->__turn_off();
104 }
105
106 } // end namespace __cxxprof_impl
107 #endif /* PROFCXX_PROFILER_STATE_H__ */