profiler_state.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // -*- C++ -*-
  2. //
  3. // Copyright (C) 2009-2018 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
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. // Under Section 7 of GPL version 3, you are granted additional
  16. // permissions described in the GCC Runtime Library Exception, version
  17. // 3.1, as published by the Free Software Foundation.
  18. // You should have received a copy of the GNU General Public License along
  19. // with this library; see the file COPYING3. If not see
  20. // <http://www.gnu.org/licenses/>.
  21. /** @file profile/impl/profiler_state.h
  22. * @brief Global profiler state.
  23. */
  24. // Written by Lixia Liu and Silvius Rus.
  25. #ifndef _GLIBCXX_PROFILE_PROFILER_STATE_H
  26. #define _GLIBCXX_PROFILE_PROFILER_STATE_H 1
  27. namespace __gnu_profile
  28. {
  29. enum __state_type { __ON, __OFF, __INVALID };
  30. _GLIBCXX_PROFILE_DEFINE_DATA(__state_type, __state, __INVALID);
  31. inline bool
  32. __turn(__state_type __s)
  33. {
  34. __state_type inv(__INVALID);
  35. return __atomic_compare_exchange_n(&_GLIBCXX_PROFILE_DATA(__state),
  36. &inv, __s, false, __ATOMIC_ACQ_REL,
  37. __ATOMIC_RELAXED);
  38. }
  39. inline bool
  40. __turn_on()
  41. { return __turn(__ON); }
  42. inline bool
  43. __turn_off()
  44. { return __turn(__OFF); }
  45. inline bool
  46. __is_on()
  47. { return _GLIBCXX_PROFILE_DATA(__state) == __ON; }
  48. inline bool
  49. __is_off()
  50. { return _GLIBCXX_PROFILE_DATA(__state) == __OFF; }
  51. inline bool
  52. __is_invalid()
  53. { return _GLIBCXX_PROFILE_DATA(__state) == __INVALID; }
  54. } // end namespace __gnu_profile
  55. #endif /* _GLIBCXX_PROFILE_PROFILER_STATE_H */