1 // Exception Handling support header for -*- C++ -*- 2 3 // Copyright (C) 2016-2018 Free Software Foundation, Inc. 4 // 5 // This file is part of GCC. 6 // 7 // GCC is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License as published by 9 // the Free Software Foundation; either version 3, or (at your option) 10 // any later version. 11 // 12 // GCC is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 // Under Section 7 of GPL version 3, you are granted additional 18 // permissions described in the GCC Runtime Library Exception, version 19 // 3.1, as published by the Free Software Foundation. 20 21 // You should have received a copy of the GNU General Public License and 22 // a copy of the GCC Runtime Library Exception along with this program; 23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24 // <http://www.gnu.org/licenses/>. 25 26 /** @file eh_atomics.h 27 * This is an internal header file, included by library source files. 28 * Do not attempt to use it directly. 29 */ 30 31 #ifndef _EH_ATOMICS_H 32 #define _EH_ATOMICS_H 1 33 34 #include <bits/c++config.h> 35 #include <bits/atomic_word.h> 36 #include <bits/atomic_lockfree_defines.h> 37 #if ATOMIC_INT_LOCK_FREE <= 1 38 # include <ext/atomicity.h> 39 #endif 40 41 #pragma GCC visibility push(default) 42 extern "C++" { 43 namespace __gnu_cxx 44 { 45 void 46 __eh_atomic_inc (_Atomic_word* __count) __attribute__((always_inline)); 47 48 bool 49 __eh_atomic_dec (_Atomic_word* __count) __attribute__((always_inline)); 50 51 // Increments the count. 52 inline void __eh_atomic_inc(_Atomic_word * __count)53 __eh_atomic_inc (_Atomic_word* __count) 54 { 55 #if ATOMIC_INT_LOCK_FREE > 1 56 __atomic_add_fetch (__count, 1, __ATOMIC_ACQ_REL); 57 #else 58 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE (__count); 59 __gnu_cxx::__atomic_add_dispatch (__count, 1); 60 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER (__count); 61 #endif 62 } 63 64 // Decrements the count and returns true if it reached zero. 65 inline bool __eh_atomic_dec(_Atomic_word * __count)66 __eh_atomic_dec (_Atomic_word* __count) 67 { 68 #if ATOMIC_INT_LOCK_FREE > 1 69 return __atomic_sub_fetch (__count, 1, __ATOMIC_ACQ_REL) == 0; 70 #else 71 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE (__count); 72 if (__gnu_cxx::__exchange_and_add_dispatch (__count, -1) == 1) 73 { 74 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER (__count); 75 return true; 76 } 77 return false; 78 #endif 79 } 80 } // namespace __gnu_cxx 81 } 82 #pragma GCC visibility pop 83 84 #endif // _EH_ATOMICS_H 85