1 // Safe container implementation  -*- C++ -*-
 
    3 // Copyright (C) 2011-2014 Free Software Foundation, Inc.
 
    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)
 
   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.
 
   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.
 
   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/>.
 
   25 /** @file debug/safe_unordered_container.tcc
 
   26  *  This file is a GNU debug extension to the Standard C++ Library.
 
   29 #ifndef _GLIBCXX_DEBUG_SAFE_UNORDERED_CONTAINER_TCC
 
   30 #define _GLIBCXX_DEBUG_SAFE_UNORDERED_CONTAINER_TCC 1
 
   34   template<typename _Container>
 
   35     template<typename _Predicate>
 
   37       _Safe_unordered_container<_Container>::
 
   38       _M_invalidate_if(_Predicate __pred)
 
   40    typedef typename _Container::iterator iterator;
 
   41    typedef typename _Container::const_iterator const_iterator;
 
   43    __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
 
   44    for (_Safe_iterator_base* __iter = _M_iterators; __iter;)
 
   46        iterator* __victim = static_cast<iterator*>(__iter);
 
   47        __iter = __iter->_M_next;
 
   48        if (!__victim->_M_singular() && __pred(__victim->base()))
 
   50        __victim->_M_invalidate();
 
   54    for (_Safe_iterator_base* __iter2 = _M_const_iterators; __iter2;)
 
   56        const_iterator* __victim = static_cast<const_iterator*>(__iter2);
 
   57        __iter2 = __iter2->_M_next;
 
   58        if (!__victim->_M_singular() && __pred(__victim->base()))
 
   60        __victim->_M_invalidate();
 
   66   template<typename _Container>
 
   67     template<typename _Predicate>
 
   69       _Safe_unordered_container<_Container>::
 
   70       _M_invalidate_local_if(_Predicate __pred)
 
   72    typedef typename _Container::local_iterator local_iterator;
 
   73    typedef typename _Container::const_local_iterator const_local_iterator;
 
   75    __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex());
 
   76    for (_Safe_iterator_base* __iter = _M_local_iterators; __iter;)
 
   78        local_iterator* __victim = static_cast<local_iterator*>(__iter);
 
   79        __iter = __iter->_M_next;
 
   80        if (!__victim->_M_singular() && __pred(__victim->base()))
 
   82        __victim->_M_invalidate();
 
   86    for (_Safe_iterator_base* __iter2 = _M_const_local_iterators; __iter2;)
 
   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()))
 
   93        __victim->_M_invalidate();
 
   98 } // namespace __gnu_debug