]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/libsupc++/new_handler.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / new_handler.cc
CommitLineData
06bd10fb 1// Implementation file for the -*- C++ -*- dynamic memory management header.
e2c09482 2
aa118a03 3// Copyright (C) 1996-2014 Free Software Foundation, Inc.
06bd10fb 4//
cbecceb9 5// This file is part of GCC.
06bd10fb 6//
cbecceb9 7// GCC is free software; you can redistribute it and/or modify
06bd10fb 8// it under the terms of the GNU General Public License as published by
748086b7 9// the Free Software Foundation; either version 3, or (at your option)
06bd10fb
BK
10// any later version.
11//
cbecceb9 12// GCC is distributed in the hope that it will be useful,
06bd10fb
BK
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//
748086b7
JJ
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/>.
06bd10fb 25
06bd10fb 26#include "new"
7e20f4b0
JW
27#include <bits/atomic_lockfree_defines.h>
28
29#if ATOMIC_POINTER_LOCK_FREE < 2
30#include <ext/concurrence.h>
31namespace
32{
33 __gnu_cxx::__mutex mx;
34}
35#endif
06bd10fb
BK
36
37const std::nothrow_t std::nothrow = { };
38
39using std::new_handler;
dca77a8a
JW
40namespace
41{
42 new_handler __new_handler;
43}
06bd10fb
BK
44
45new_handler
984812cd 46std::set_new_handler (new_handler handler) throw()
06bd10fb 47{
dca77a8a 48 new_handler prev_handler;
7e20f4b0 49#if ATOMIC_POINTER_LOCK_FREE > 1
dca77a8a
JW
50 __atomic_exchange (&__new_handler, &handler, &prev_handler,
51 __ATOMIC_ACQ_REL);
7e20f4b0
JW
52#else
53 __gnu_cxx::__scoped_lock l(mx);
54 prev_handler = __new_handler;
55 __new_handler = handler;
56#endif
06bd10fb
BK
57 return prev_handler;
58}
dca77a8a
JW
59
60new_handler
61std::get_new_handler () noexcept
62{
63 new_handler handler;
7e20f4b0 64#if ATOMIC_POINTER_LOCK_FREE > 1
dca77a8a 65 __atomic_load (&__new_handler, &handler, __ATOMIC_ACQUIRE);
7e20f4b0
JW
66#else
67 __gnu_cxx::__scoped_lock l(mx);
68 handler = __new_handler;
69#endif
dca77a8a
JW
70 return handler;
71}