11debfc3dSmrg // Implementation file for the -*- C++ -*- dynamic memory management header.
21debfc3dSmrg
3*8feb0f0bSmrg // Copyright (C) 1996-2020 Free Software Foundation, Inc.
41debfc3dSmrg //
51debfc3dSmrg // This file is part of GCC.
61debfc3dSmrg //
71debfc3dSmrg // GCC is free software; you can redistribute it and/or modify
81debfc3dSmrg // it under the terms of the GNU General Public License as published by
91debfc3dSmrg // the Free Software Foundation; either version 3, or (at your option)
101debfc3dSmrg // any later version.
111debfc3dSmrg //
121debfc3dSmrg // GCC is distributed in the hope that it will be useful,
131debfc3dSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
141debfc3dSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
151debfc3dSmrg // GNU General Public License for more details.
161debfc3dSmrg //
171debfc3dSmrg // Under Section 7 of GPL version 3, you are granted additional
181debfc3dSmrg // permissions described in the GCC Runtime Library Exception, version
191debfc3dSmrg // 3.1, as published by the Free Software Foundation.
201debfc3dSmrg
211debfc3dSmrg // You should have received a copy of the GNU General Public License and
221debfc3dSmrg // a copy of the GCC Runtime Library Exception along with this program;
231debfc3dSmrg // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
241debfc3dSmrg // <http://www.gnu.org/licenses/>.
251debfc3dSmrg
261debfc3dSmrg #include "new"
271debfc3dSmrg #include <bits/atomic_lockfree_defines.h>
281debfc3dSmrg
291debfc3dSmrg #if ATOMIC_POINTER_LOCK_FREE < 2
301debfc3dSmrg #include <ext/concurrence.h>
311debfc3dSmrg namespace
321debfc3dSmrg {
331debfc3dSmrg __gnu_cxx::__mutex mx;
341debfc3dSmrg }
351debfc3dSmrg #endif
361debfc3dSmrg
371debfc3dSmrg const std::nothrow_t std::nothrow = std::nothrow_t{ };
381debfc3dSmrg
391debfc3dSmrg using std::new_handler;
401debfc3dSmrg namespace
411debfc3dSmrg {
421debfc3dSmrg new_handler __new_handler;
431debfc3dSmrg }
441debfc3dSmrg
451debfc3dSmrg new_handler
set_new_handler(new_handler handler)461debfc3dSmrg std::set_new_handler (new_handler handler) throw()
471debfc3dSmrg {
481debfc3dSmrg new_handler prev_handler;
491debfc3dSmrg #if ATOMIC_POINTER_LOCK_FREE > 1
501debfc3dSmrg __atomic_exchange (&__new_handler, &handler, &prev_handler,
511debfc3dSmrg __ATOMIC_ACQ_REL);
521debfc3dSmrg #else
531debfc3dSmrg __gnu_cxx::__scoped_lock l(mx);
541debfc3dSmrg prev_handler = __new_handler;
551debfc3dSmrg __new_handler = handler;
561debfc3dSmrg #endif
571debfc3dSmrg return prev_handler;
581debfc3dSmrg }
591debfc3dSmrg
601debfc3dSmrg new_handler
get_new_handler()611debfc3dSmrg std::get_new_handler () noexcept
621debfc3dSmrg {
631debfc3dSmrg new_handler handler;
641debfc3dSmrg #if ATOMIC_POINTER_LOCK_FREE > 1
651debfc3dSmrg __atomic_load (&__new_handler, &handler, __ATOMIC_ACQUIRE);
661debfc3dSmrg #else
671debfc3dSmrg __gnu_cxx::__scoped_lock l(mx);
681debfc3dSmrg handler = __new_handler;
691debfc3dSmrg #endif
701debfc3dSmrg return handler;
711debfc3dSmrg }
72