libstdc++
profiler_state.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Copyright (C) 2009, 2010, 2012 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License along
00021 // with this library; see the file COPYING3.  If not see
00022 // <http://www.gnu.org/licenses/>.
00023 
00024 /** @file profile/impl/profiler_state.h
00025  *  @brief Global profiler state.
00026  */
00027 
00028 // Written by Lixia Liu and Silvius Rus.
00029 
00030 #ifndef _GLIBCXX_PROFILE_PROFILER_STATE_H
00031 #define _GLIBCXX_PROFILE_PROFILER_STATE_H 1
00032 
00033 namespace __gnu_profile
00034 {
00035   enum __state_type { __ON, __OFF, __INVALID };
00036 
00037   _GLIBCXX_PROFILE_DEFINE_DATA(__state_type, __state, __INVALID);
00038 
00039   inline bool
00040   __turn(__state_type __s)
00041   { 
00042     __state_type inv(__INVALID);
00043     return __atomic_compare_exchange_n(&_GLIBCXX_PROFILE_DATA(__state),
00044                        &inv, __s, false, __ATOMIC_ACQ_REL, 
00045                        __ATOMIC_RELAXED);
00046   }
00047 
00048   inline bool
00049   __turn_on()
00050   { return __turn(__ON); }
00051 
00052   inline bool
00053   __turn_off()
00054   { return __turn(__OFF); }
00055 
00056   inline bool
00057   __is_on()
00058   { return _GLIBCXX_PROFILE_DATA(__state) == __ON; }
00059 
00060   inline bool
00061   __is_off()
00062   { return _GLIBCXX_PROFILE_DATA(__state) == __OFF; }
00063 
00064   inline bool
00065   __is_invalid()
00066   { return _GLIBCXX_PROFILE_DATA(__state) == __INVALID; }
00067 
00068 } // end namespace __gnu_profile
00069 #endif /* _GLIBCXX_PROFILE_PROFILER_STATE_H */