Changeset 700 for handle/trunk

Show
Ignore:
Timestamp:
08/07/08 09:58:11 (2 years ago)
Author:
tapted
Message:

Switch to using atomic counts

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • handle/trunk/handle.h

    r238 r700  
    2727#include <cxxabi.h> 
    2828#endif 
     29 
     30#define BOOST_NO_CONFIG 
     31#define BOOST_HAS_THREADS 
     32#include "atomic/boost/detail/atomic_count.hpp" 
    2933 
    3034using std::size_t; //everyone uses it.. 
     
    8286}; 
    8387 
     88using boost::detail::atomic_count; 
     89 
    8490/** 
    8591 * Your standard reference counting handle with some 
     
    9298    template <class C> friend class Handle; 
    9399    T* p;         ///< The pointer we are counting 
    94     size_t* refs; ///< Pointer to the number of references to \a p 
     100    atomic_count* refs; ///< Pointer to the number of references to \a p 
    95101 
    96102    /** 
     
    99105     * have to check for self-assignment. 
    100106     */ 
    101     void safeAssign(size_t* newRefs) throw() { 
    102         size_t* oldRefs(refs); 
    103         refs = &++*newRefs; 
     107    void safeAssign(atomic_count* newRefs) throw() { 
     108        atomic_count* oldRefs(refs); 
     109        ++*newRefs; 
     110        refs = newRefs; 
    104111        if (!--*oldRefs) { 
    105112            delp(); 
     
    114121     * Construct a <tt>new T()</tt> with \a T's default constructor. 
    115122     */ 
    116     Handle () throw(std::bad_alloc) : p(new T()) , refs(new size_t(1)) {} 
     123    Handle () throw(std::bad_alloc) : p(new T()) , refs(new atomic_count(1)) {} 
    117124 
    118125    /** 
     
    128135     * \param pp The pointer to attach 
    129136     */ 
    130     explicit Handle (T* pp) throw(std::bad_alloc) : p(pp), refs(new size_t(1)) {} 
     137    explicit Handle (T* pp) throw(std::bad_alloc) : p(pp), refs(new atomic_count(1)) {} 
    131138 
    132139    /** Return the number of references to the pointer */ 
     
    138145     * \param h the Handle to copy 
    139146     */ 
    140     Handle (const Handle<T>& h) throw() : p(h.p), refs(&++*h.refs) {} 
     147    Handle (const Handle<T>& h) throw() : p(h.p), refs(h.refs) { 
     148        ++*refs; 
     149    } 
    141150 
    142151    /**