]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/debug/safe_unordered_sequence.tcc
safe_unordered_base.h, [...]: New, support for unordered sequence safe local iterators.
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / safe_unordered_sequence.tcc
1 // Safe sequence implementation -*- C++ -*-
2
3 // Copyright (C) 2011 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_sequence.tcc
26 * This file is a GNU debug extension to the Standard C++ Library.
27 */
28
29 #ifndef _GLIBCXX_DEBUG_SAFE_UNORDERED_SEQUENCE_TCC
30 #define _GLIBCXX_DEBUG_SAFE_UNORDERED_SEQUENCE_TCC 1
31
32 namespace __gnu_debug
33 {
34 template<typename _Sequence>
35 template<typename _Predicate>
36 void
37 _Safe_unordered_sequence<_Sequence>::
38 _M_invalidate_if(_Predicate __pred)
39 {
40 typedef typename _Sequence::iterator iterator;
41 typedef typename _Sequence::const_iterator const_iterator;
42
43 __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
44 for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
45 {
46 iterator* __victim = static_cast<iterator*>(__iter);
47 __iter = __iter->_M_next;
48 if (!__victim->_M_singular() && __pred(__victim->base()))
49 {
50 __victim->_M_invalidate();
51 }
52 }
53
54 for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
55 {
56 const_iterator* __victim = static_cast<const_iterator*>(__iter2);
57 __iter2 = __iter2->_M_next;
58 if (!__victim->_M_singular() && __pred(__victim->base()))
59 {
60 __victim->_M_invalidate();
61 }
62 }
63 }
64
65
66 template<typename _Sequence>
67 template<typename _Predicate>
68 void
69 _Safe_unordered_sequence<_Sequence>::
70 _M_invalidate_local_if(_Predicate __pred)
71 {
72 typedef typename _Sequence::local_iterator local_iterator;
73 typedef typename _Sequence::const_local_iterator const_local_iterator;
74
75 __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
76 for (_Safe_iterator_base* __iter = _M_local_iterators; __iter;)
77 {
78 local_iterator* __victim = static_cast<local_iterator*>(__iter);
79 __iter = __iter->_M_next;
80 if (!__victim->_M_singular() && __pred(__victim->base()))
81 {
82 __victim->_M_invalidate();
83 }
84 }
85
86 for (_Safe_iterator_base* __iter2 = _M_const_local_iterators; __iter2;)
87 {
88 const_local_iterator* __victim =
89 static_cast<const_local_iterator*>(__iter2);
90 __iter2 = __iter2->_M_next;
91 if (!__victim->_M_singular() && __pred(__victim->base()))
92 {
93 __victim->_M_invalidate();
94 }
95 }
96 }
97
98 } // namespace __gnu_debug
99
100 #endif