atomicity.h revision 169692
1251652Sgjb// Low-level functions for atomic operations: Generic version  -*- C++ -*-
2251652Sgjb
3251652Sgjb// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006
4251652Sgjb// Free Software Foundation, Inc.
5251652Sgjb//
6251652Sgjb// This file is part of the GNU ISO C++ Library.  This library is free
7251652Sgjb// software; you can redistribute it and/or modify it under the
8251652Sgjb// terms of the GNU General Public License as published by the
9251652Sgjb// Free Software Foundation; either version 2, or (at your option)
10262499Sgjb// any later version.
11251652Sgjb
12251652Sgjb// This library is distributed in the hope that it will be useful,
13254293Sgjb// but WITHOUT ANY WARRANTY; without even the implied warranty of
14254293Sgjb// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15254293Sgjb// GNU General Public License for more details.
16251652Sgjb
17252846Sgjb// You should have received a copy of the GNU General Public License along
18252846Sgjb// with this library; see the file COPYING.  If not, write to the Free
19252846Sgjb// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20262499Sgjb// USA.
21262499Sgjb
22262499Sgjb// As a special exception, you may use this file as part of a free software
23262499Sgjb// library without restriction.  Specifically, if other files instantiate
24262499Sgjb// templates or use macros or inline functions from this file, or you compile
25262499Sgjb// this file and link it with other files to produce an executable, this
26262499Sgjb// file does not by itself cause the resulting executable to be covered by
27251652Sgjb// the GNU General Public License.  This exception does not however
28251652Sgjb// invalidate any other reasons why the executable file might be covered by
29251652Sgjb// the GNU General Public License.
30251652Sgjb
31252846Sgjb/** @file ext/atomicity.h
32252846Sgjb *  This file is a GNU extension to the Standard C++ Library.
33251652Sgjb */
34251652Sgjb
35251652Sgjb#include <ext/atomicity.h>
36251652Sgjb#include <ext/concurrence.h>
37251652Sgjb
38251652Sgjbnamespace
39251652Sgjb{
40251652Sgjb  __gnu_cxx::__mutex atomic_mutex;
41251652Sgjb} // anonymous namespace
42251652Sgjb
43262513Sgjb_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
44251652Sgjb
45251652Sgjb  _Atomic_word
46251652Sgjb  __attribute__ ((__unused__))
47251652Sgjb  __exchange_and_add(volatile _Atomic_word* __mem, int __val)
48259079Sgjb  {
49264027Sgjb    __gnu_cxx::__scoped_lock sentry(atomic_mutex);
50262810Sgjb    _Atomic_word __result;
51262810Sgjb    __result = *__mem;
52262810Sgjb    *__mem += __val;
53262810Sgjb    return __result;
54262810Sgjb  }
55262810Sgjb
56262810Sgjb  void
57262810Sgjb  __attribute__ ((__unused__))
58262810Sgjb  __atomic_add(volatile _Atomic_word* __mem, int __val)
59264343Sgjb  { __exchange_and_add(__mem, __val); }
60264343Sgjb
61264343Sgjb_GLIBCXX_END_NAMESPACE
62264343Sgjb