epoc32/include/stdapis/boost/detail/atomic_count.hpp
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
#ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
williamr@2
     2
#define BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED
williamr@2
     3
williamr@2
     4
// MS compatible compilers support #pragma once
williamr@2
     5
williamr@2
     6
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
williamr@2
     7
# pragma once
williamr@2
     8
#endif
williamr@2
     9
williamr@2
    10
//
williamr@2
    11
//  boost/detail/atomic_count.hpp - thread/SMP safe reference counter
williamr@2
    12
//
williamr@2
    13
//  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
williamr@2
    14
//
williamr@2
    15
// Distributed under the Boost Software License, Version 1.0. (See
williamr@2
    16
// accompanying file LICENSE_1_0.txt or copy at
williamr@2
    17
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
    18
//
williamr@2
    19
//  typedef <implementation-defined> boost::detail::atomic_count;
williamr@2
    20
//
williamr@2
    21
//  atomic_count a(n);
williamr@2
    22
//
williamr@2
    23
//    (n is convertible to long)
williamr@2
    24
//
williamr@2
    25
//    Effects: Constructs an atomic_count with an initial value of n
williamr@2
    26
//
williamr@2
    27
//  a;
williamr@2
    28
//
williamr@2
    29
//    Returns: (long) the current value of a
williamr@2
    30
//
williamr@2
    31
//  ++a;
williamr@2
    32
//
williamr@2
    33
//    Effects: Atomically increments the value of a
williamr@2
    34
//    Returns: nothing
williamr@2
    35
//
williamr@2
    36
//  --a;
williamr@2
    37
//
williamr@2
    38
//    Effects: Atomically decrements the value of a
williamr@2
    39
//    Returns: (long) zero if the new value of a is zero,
williamr@2
    40
//      unspecified non-zero value otherwise (usually the new value)
williamr@2
    41
//
williamr@2
    42
//    Important note: when --a returns zero, it must act as a
williamr@2
    43
//      read memory barrier (RMB); i.e. the calling thread must
williamr@2
    44
//      have a synchronized view of the memory
williamr@2
    45
//
williamr@2
    46
//    On Intel IA-32 (x86) memory is always synchronized, so this
williamr@2
    47
//      is not a problem.
williamr@2
    48
//
williamr@2
    49
//    On many architectures the atomic instructions already act as
williamr@2
    50
//      a memory barrier.
williamr@2
    51
//
williamr@2
    52
//    This property is necessary for proper reference counting, since
williamr@2
    53
//      a thread can update the contents of a shared object, then
williamr@2
    54
//      release its reference, and another thread may immediately
williamr@2
    55
//      release the last reference causing object destruction.
williamr@2
    56
//
williamr@2
    57
//    The destructor needs to have a synchronized view of the
williamr@2
    58
//      object to perform proper cleanup.
williamr@2
    59
//
williamr@2
    60
//    Original example by Alexander Terekhov:
williamr@2
    61
//
williamr@2
    62
//    Given:
williamr@2
    63
//
williamr@2
    64
//    - a mutable shared object OBJ;
williamr@2
    65
//    - two threads THREAD1 and THREAD2 each holding 
williamr@2
    66
//      a private smart_ptr object pointing to that OBJ.
williamr@2
    67
//
williamr@2
    68
//    t1: THREAD1 updates OBJ (thread-safe via some synchronization)
williamr@2
    69
//      and a few cycles later (after "unlock") destroys smart_ptr;
williamr@2
    70
//
williamr@2
    71
//    t2: THREAD2 destroys smart_ptr WITHOUT doing any synchronization 
williamr@2
    72
//      with respect to shared mutable object OBJ; OBJ destructors
williamr@2
    73
//      are called driven by smart_ptr interface...
williamr@2
    74
//
williamr@2
    75
williamr@2
    76
#include <boost/config.hpp>
williamr@2
    77
williamr@2
    78
#ifndef BOOST_HAS_THREADS
williamr@2
    79
williamr@2
    80
namespace boost
williamr@2
    81
{
williamr@2
    82
williamr@2
    83
namespace detail
williamr@2
    84
{
williamr@2
    85
williamr@2
    86
typedef long atomic_count;
williamr@2
    87
williamr@2
    88
}
williamr@2
    89
williamr@2
    90
}
williamr@2
    91
williamr@2
    92
#elif defined(BOOST_AC_USE_PTHREADS)
williamr@2
    93
#  include <boost/detail/atomic_count_pthreads.hpp>
williamr@2
    94
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
williamr@2
    95
#  include <boost/detail/atomic_count_win32.hpp>
williamr@2
    96
#elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
williamr@2
    97
#  include <boost/detail/atomic_count_gcc.hpp>
williamr@2
    98
#elif defined(BOOST_HAS_PTHREADS)
williamr@2
    99
#  define BOOST_AC_USE_PTHREADS
williamr@2
   100
#  include <boost/detail/atomic_count_pthreads.hpp>
williamr@2
   101
#else
williamr@2
   102
williamr@2
   103
// Use #define BOOST_DISABLE_THREADS to avoid the error
williamr@2
   104
#error Unrecognized threading platform
williamr@2
   105
williamr@2
   106
#endif
williamr@2
   107
williamr@2
   108
#endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_HPP_INCLUDED