Singleton.h   Singleton.h 
skipping to change at line 18 skipping to change at line 18
// purpose is hereby granted without fee, provided that the above copyr ight // purpose is hereby granted without fee, provided that the above copyr ight
// notice appear in all copies and that both that copyright notice and this // notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation. // permission notice appear in supporting documentation.
// The author or Addison-Wesley Longman make no representations about the // The author or Addison-Wesley Longman make no representations about the
// suitability of this software for any purpose. It is provided "as is" // suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty. // without express or implied warranty.
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
#ifndef LOKI_SINGLETON_INC_ #ifndef LOKI_SINGLETON_INC_
#define LOKI_SINGLETON_INC_ #define LOKI_SINGLETON_INC_
// $Id: Singleton.h,v 1.1 2007/12/10 11:58:51 ben Exp $ // $Id: Singleton.h,v 1.2 2010/09/18 21:36:23 ben Exp $
#include "LokiExport.h" #include "LokiExport.h"
#include "Threads.h" #include "Threads.h"
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <cassert> #include <cassert>
#include <cstdlib> #include <cstdlib>
#include <new> #include <new>
#include <vector> #include <vector>
#include <list> #include <list>
skipping to change at line 78 skipping to change at line 78
// Helper data // Helper data
// std::list because of the inserts // std::list because of the inserts
typedef std::list<LifetimeTracker*> TrackerArray; typedef std::list<LifetimeTracker*> TrackerArray;
extern LOKI_EXPORT TrackerArray* pTrackerArray; extern LOKI_EXPORT TrackerArray* pTrackerArray;
#else #else
// Helper data // Helper data
typedef LifetimeTracker** TrackerArray; typedef LifetimeTracker** TrackerArray;
extern TrackerArray pTrackerArray; extern TrackerArray pTrackerArray;
extern unsigned int elements; extern unsigned int elements;
#endif #endif
extern unsigned int insideAtExit;
/////////////////////////////////////////////////////////////////// ///////////// /////////////////////////////////////////////////////////////////// /////////////
// class LifetimeTracker // class LifetimeTracker
// Helper class for SetLongevity // Helper class for SetLongevity
/////////////////////////////////////////////////////////////////// ///////////// /////////////////////////////////////////////////////////////////// /////////////
class LifetimeTracker class LifetimeTracker
{ {
public: public:
LifetimeTracker(unsigned int x) : longevity_(x) LifetimeTracker(unsigned int x) : longevity_(x)
 End of changes. 2 change blocks. 
1 lines changed or deleted 2 lines changed or added


 SmartPtr.h   SmartPtr.h 
skipping to change at line 18 skipping to change at line 18
// purpose is hereby granted without fee, provided that the above copyr ight // purpose is hereby granted without fee, provided that the above copyr ight
// notice appear in all copies and that both that copyright notice and this // notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation. // permission notice appear in supporting documentation.
// The author or Addison-Wesley Longman make no representations about the // The author or Addison-Wesley Longman make no representations about the
// suitability of this software for any purpose. It is provided "as is" // suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty. // without express or implied warranty.
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
#ifndef LOKI_SMARTPTR_INC_ #ifndef LOKI_SMARTPTR_INC_
#define LOKI_SMARTPTR_INC_ #define LOKI_SMARTPTR_INC_
// $Id: SmartPtr.h,v 1.1 2007/12/10 11:58:51 ben Exp $ // $Id: SmartPtr.h,v 1.2 2010/09/18 21:36:23 ben Exp $
/// \defgroup SmartPointerGroup Smart pointers /// \defgroup SmartPointerGroup Smart pointers
/// Policy based implementation of a smart pointer /// Policy based implementation of a smart pointer
/// \defgroup SmartPointerOwnershipGroup Ownership policies /// \defgroup SmartPointerOwnershipGroup Ownership policies
/// \ingroup SmartPointerGroup /// \ingroup SmartPointerGroup
/// \defgroup SmartPointerStorageGroup Storage policies /// \defgroup SmartPointerStorageGroup Storage policies
/// \ingroup SmartPointerGroup /// \ingroup SmartPointerGroup
/// \defgroup SmartPointerConversionGroup Conversion policies /// \defgroup SmartPointerConversionGroup Conversion policies
/// \ingroup SmartPointerGroup /// \ingroup SmartPointerGroup
/// \defgroup SmartPointerCheckingGroup Checking policies /// \defgroup SmartPointerCheckingGroup Checking policies
skipping to change at line 431 skipping to change at line 431
/// \ingroup SmartPointerOwnershipGroup /// \ingroup SmartPointerOwnershipGroup
/// Implementation of the OwnershipPolicy used by SmartPtr /// Implementation of the OwnershipPolicy used by SmartPtr
/// Provides a classic external reference counting implementation /// Provides a classic external reference counting implementation
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
template <class P> template <class P>
class RefCounted class RefCounted
{ {
public: public:
RefCounted() RefCounted()
#if (LOKI_MAX_SMALL_OBJECT_SIZE != 0) && (LOKI_DEFAULT_CHUNK_SIZE != 0) && (LOKI_DEFAULT_OBJECT_ALIGNMENT != 0)
: pCount_(static_cast<uintptr_t*>( : pCount_(static_cast<uintptr_t*>(
SmallObject<>::operator new(sizeof(uintptr_t)))) SmallObject<>::operator new(sizeof(uintptr_t))))
{ #else
: pCount_(static_cast<uintptr_t*>(new uintptr_t))
#endif
{
assert(pCount_!=0); assert(pCount_!=0);
*pCount_ = 1; *pCount_ = 1;
} }
RefCounted(const RefCounted& rhs) RefCounted(const RefCounted& rhs)
: pCount_(rhs.pCount_) : pCount_(rhs.pCount_)
{} {}
// MWCW lacks template friends, hence the following kludge // MWCW lacks template friends, hence the following kludge
template <typename P1> template <typename P1>
skipping to change at line 458 skipping to change at line 462
P Clone(const P& val) P Clone(const P& val)
{ {
++*pCount_; ++*pCount_;
return val; return val;
} }
bool Release(const P&) bool Release(const P&)
{ {
if (!--*pCount_) if (!--*pCount_)
{ {
#if (LOKI_MAX_SMALL_OBJECT_SIZE != 0) && (LOKI_DEFAULT_CHUNK_SIZE != 0) && (LOKI_DEFAULT_OBJECT_ALIGNMENT != 0)
SmallObject<>::operator delete(pCount_, sizeof(uintptr_t)); SmallObject<>::operator delete(pCount_, sizeof(uintptr_t));
#else
delete pCount_;
#endif
pCount_ = NULL; pCount_ = NULL;
return true; return true;
} }
return false; return false;
} }
void Swap(RefCounted& rhs) void Swap(RefCounted& rhs)
{ std::swap(pCount_, rhs.pCount_); } { std::swap(pCount_, rhs.pCount_); }
enum { destructiveCopy = false }; enum { destructiveCopy = false };
skipping to change at line 502 skipping to change at line 510
template <class P> template <class P>
class RefCountedMT : public ThreadingModel< RefCountedMT<P>, MX > class RefCountedMT : public ThreadingModel< RefCountedMT<P>, MX >
{ {
typedef ThreadingModel< RefCountedMT<P>, MX > base_type; typedef ThreadingModel< RefCountedMT<P>, MX > base_type;
typedef typename base_type::IntType CountType; typedef typename base_type::IntType CountType;
typedef volatile CountType *CountPtrType; typedef volatile CountType *CountPtrType;
public: public:
RefCountedMT() RefCountedMT()
{ {
#if (LOKI_MAX_SMALL_OBJECT_SIZE != 0) && (LOKI_DEFAULT_CHUNK_SIZE != 0) && (LOKI_DEFAULT_OBJECT_ALIGNMENT != 0)
pCount_ = static_cast<CountPtrType>( pCount_ = static_cast<CountPtrType>(
SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::opera tor new( SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::opera tor new(
sizeof(*pCount_))); sizeof(*pCount_)));
#else
pCount_ = new CountType();
#endif
assert(pCount_); assert(pCount_);
//*pCount_ = 1; //*pCount_ = 1;
ThreadingModel<RefCountedMT, MX>::AtomicAssign(*pCount_, 1) ; ThreadingModel<RefCountedMT, MX>::AtomicAssign(*pCount_, 1) ;
} }
RefCountedMT(const RefCountedMT& rhs) RefCountedMT(const RefCountedMT& rhs)
: pCount_(rhs.pCount_) : pCount_(rhs.pCount_)
{} {}
//MWCW lacks template friends, hence the following kludge //MWCW lacks template friends, hence the following kludge
skipping to change at line 530 skipping to change at line 542
P Clone(const P& val) P Clone(const P& val)
{ {
ThreadingModel<RefCountedMT, MX>::AtomicIncrement(*pCount_) ; ThreadingModel<RefCountedMT, MX>::AtomicIncrement(*pCount_) ;
return val; return val;
} }
bool Release(const P&) bool Release(const P&)
{ {
if (!ThreadingModel<RefCountedMT, MX>::AtomicDecrement(*pCo unt_)) if (!ThreadingModel<RefCountedMT, MX>::AtomicDecrement(*pCo unt_))
{ {
#if (LOKI_MAX_SMALL_OBJECT_SIZE != 0) && (LOKI_DEFAULT_CHUNK_SIZE != 0) && (LOKI_DEFAULT_OBJECT_ALIGNMENT != 0)
SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::opera tor delete( SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::opera tor delete(
const_cast<CountType *>(pCount_), const_cast<CountType *>(pCount_),
sizeof(*pCount_)); sizeof(*pCount_));
#else
delete const_cast<CountType *>(pCount_);
#endif
return true; return true;
} }
return false; return false;
} }
void Swap(RefCountedMT& rhs) void Swap(RefCountedMT& rhs)
{ std::swap(pCount_, rhs.pCount_); } { std::swap(pCount_, rhs.pCount_); }
enum { destructiveCopy = false }; enum { destructiveCopy = false };
 End of changes. 9 change blocks. 
3 lines changed or deleted 19 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/