libstdc++
safe_unordered_container.tcc
Go to the documentation of this file.
1 // Safe container implementation -*- C++ -*-
2 
3 // Copyright (C) 2011-2026 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 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file debug/safe_unordered_container.tcc
26  * This file is a GNU debug extension to the Standard C++ Library.
27  */
28 
29 #ifndef _GLIBCXX_DEBUG_SAFE_UNORDERED_CONTAINER_TCC
30 #define _GLIBCXX_DEBUG_SAFE_UNORDERED_CONTAINER_TCC 1
31 
32 namespace __gnu_debug
33 {
34  template<typename _Container>
35  template<typename _Predicate>
36  void
37  _Safe_unordered_container<_Container>::
38  _M_invalidate_if(_Predicate __pred, const __gnu_cxx::__scoped_lock&)
39  {
40  typedef typename _Container::iterator iterator;
41  typedef typename _Container::const_iterator const_iterator;
42 
43  for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
44  {
45  iterator* __victim = static_cast<iterator*>(__iter);
46  __iter = __iter->_M_next;
47  if (!__victim->_M_singular() && __pred(__victim->base()))
48  {
49  __victim->_M_invalidate();
50  }
51  }
52 
53  for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
54  {
55  const_iterator* __victim = static_cast<const_iterator*>(__iter2);
56  __iter2 = __iter2->_M_next;
57  if (!__victim->_M_singular() && __pred(__victim->base()))
58  {
59  __victim->_M_invalidate();
60  }
61  }
62  }
63 
64 
65  template<typename _Container>
66  template<typename _Predicate>
67  void
68  _Safe_unordered_container<_Container>::
69  _M_invalidate_local_if(_Predicate __pred, const __gnu_cxx::__scoped_lock&)
70  {
71  typedef typename _Container::local_iterator local_iterator;
72  typedef typename _Container::const_local_iterator const_local_iterator;
73 
74  for (_Safe_iterator_base* __iter = _M_local_iterators; __iter;)
75  {
76  local_iterator* __victim = static_cast<local_iterator*>(__iter);
77  __iter = __iter->_M_next;
78  if (!__victim->_M_singular() && __pred(__victim->base()))
79  {
80  __victim->_M_invalidate();
81  }
82  }
83 
84  for (_Safe_iterator_base* __iter2 = _M_const_local_iterators; __iter2;)
85  {
86  const_local_iterator* __victim =
87  static_cast<const_local_iterator*>(__iter2);
88  __iter2 = __iter2->_M_next;
89  if (!__victim->_M_singular() && __pred(__victim->base()))
90  {
91  __victim->_M_invalidate();
92  }
93  }
94  }
95 
96 } // namespace __gnu_debug
97 
98 #endif
GNU debug classes for public use.
Scoped lock idiom.
Definition: concurrence.h:234