1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/detail/atomic_count.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,108 @@
1.4 +#ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
1.5 +#define BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
1.6 +
1.7 +// MS compatible compilers support #pragma once
1.8 +
1.9 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1.10 +# pragma once
1.11 +#endif
1.12 +
1.13 +//
1.14 +// boost/detail/atomic_count.hpp - thread/SMP safe reference counter
1.15 +//
1.16 +// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
1.17 +//
1.18 +// Distributed under the Boost Software License, Version 1.0. (See
1.19 +// accompanying file LICENSE_1_0.txt or copy at
1.20 +// http://www.boost.org/LICENSE_1_0.txt)
1.21 +//
1.22 +// typedef <implementation-defined> boost::detail::atomic_count;
1.23 +//
1.24 +// atomic_count a(n);
1.25 +//
1.26 +// (n is convertible to long)
1.27 +//
1.28 +// Effects: Constructs an atomic_count with an initial value of n
1.29 +//
1.30 +// a;
1.31 +//
1.32 +// Returns: (long) the current value of a
1.33 +//
1.34 +// ++a;
1.35 +//
1.36 +// Effects: Atomically increments the value of a
1.37 +// Returns: nothing
1.38 +//
1.39 +// --a;
1.40 +//
1.41 +// Effects: Atomically decrements the value of a
1.42 +// Returns: (long) zero if the new value of a is zero,
1.43 +// unspecified non-zero value otherwise (usually the new value)
1.44 +//
1.45 +// Important note: when --a returns zero, it must act as a
1.46 +// read memory barrier (RMB); i.e. the calling thread must
1.47 +// have a synchronized view of the memory
1.48 +//
1.49 +// On Intel IA-32 (x86) memory is always synchronized, so this
1.50 +// is not a problem.
1.51 +//
1.52 +// On many architectures the atomic instructions already act as
1.53 +// a memory barrier.
1.54 +//
1.55 +// This property is necessary for proper reference counting, since
1.56 +// a thread can update the contents of a shared object, then
1.57 +// release its reference, and another thread may immediately
1.58 +// release the last reference causing object destruction.
1.59 +//
1.60 +// The destructor needs to have a synchronized view of the
1.61 +// object to perform proper cleanup.
1.62 +//
1.63 +// Original example by Alexander Terekhov:
1.64 +//
1.65 +// Given:
1.66 +//
1.67 +// - a mutable shared object OBJ;
1.68 +// - two threads THREAD1 and THREAD2 each holding
1.69 +// a private smart_ptr object pointing to that OBJ.
1.70 +//
1.71 +// t1: THREAD1 updates OBJ (thread-safe via some synchronization)
1.72 +// and a few cycles later (after "unlock") destroys smart_ptr;
1.73 +//
1.74 +// t2: THREAD2 destroys smart_ptr WITHOUT doing any synchronization
1.75 +// with respect to shared mutable object OBJ; OBJ destructors
1.76 +// are called driven by smart_ptr interface...
1.77 +//
1.78 +
1.79 +#include <boost/config.hpp>
1.80 +
1.81 +#ifndef BOOST_HAS_THREADS
1.82 +
1.83 +namespace boost
1.84 +{
1.85 +
1.86 +namespace detail
1.87 +{
1.88 +
1.89 +typedef long atomic_count;
1.90 +
1.91 +}
1.92 +
1.93 +}
1.94 +
1.95 +#elif defined(BOOST_AC_USE_PTHREADS)
1.96 +# include <boost/detail/atomic_count_pthreads.hpp>
1.97 +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
1.98 +# include <boost/detail/atomic_count_win32.hpp>
1.99 +#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
1.100 +# include <boost/detail/atomic_count_gcc.hpp>
1.101 +#elif defined(BOOST_HAS_PTHREADS)
1.102 +# define BOOST_AC_USE_PTHREADS
1.103 +# include <boost/detail/atomic_count_pthreads.hpp>
1.104 +#else
1.105 +
1.106 +// Use #define BOOST_DISABLE_THREADS to avoid the error
1.107 +#error Unrecognized threading platform
1.108 +
1.109 +#endif
1.110 +
1.111 +#endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED