move macro switched code into the header to fix linker errors.
By this we don't need special libraries for the #if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING) case. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@807 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
6050c23d24
commit
af68912216
2 changed files with 67 additions and 98 deletions
|
@ -621,11 +621,33 @@ private:
|
||||||
|
|
||||||
class LOKI_EXPORT LockableTwoRefCounts
|
class LOKI_EXPORT LockableTwoRefCounts
|
||||||
{
|
{
|
||||||
|
typedef SmallValueObject< ::Loki::ClassLevelLockable > ThreadSafePointerAllocator;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
explicit LockableTwoRefCounts( bool strong );
|
explicit LockableTwoRefCounts( bool strong )
|
||||||
|
: m_counts( NULL )
|
||||||
|
{
|
||||||
|
void * temp = ThreadSafePointerAllocator::operator new(
|
||||||
|
sizeof(Loki::Private::LockableTwoRefCountInfo) );
|
||||||
|
#ifdef DO_EXTRA_LOKI_TESTS
|
||||||
|
assert( temp != 0 );
|
||||||
|
#endif
|
||||||
|
m_counts = new ( temp ) Loki::Private::LockableTwoRefCountInfo( strong );
|
||||||
|
}
|
||||||
|
|
||||||
LockableTwoRefCounts( const void * p, bool strong );
|
LockableTwoRefCounts( const void * p, bool strong )
|
||||||
|
: m_counts( NULL )
|
||||||
|
{
|
||||||
|
void * temp = ThreadSafePointerAllocator::operator new(
|
||||||
|
sizeof(Loki::Private::LockableTwoRefCountInfo) );
|
||||||
|
#ifdef DO_EXTRA_LOKI_TESTS
|
||||||
|
assert( temp != 0 );
|
||||||
|
#endif
|
||||||
|
void * p2 = const_cast< void * >( p );
|
||||||
|
m_counts = new ( temp )
|
||||||
|
Loki::Private::LockableTwoRefCountInfo( p2, strong );
|
||||||
|
}
|
||||||
|
|
||||||
LockableTwoRefCounts( const LockableTwoRefCounts & rhs, bool strong ) :
|
LockableTwoRefCounts( const LockableTwoRefCounts & rhs, bool strong ) :
|
||||||
m_counts( rhs.m_counts )
|
m_counts( rhs.m_counts )
|
||||||
|
@ -648,23 +670,62 @@ protected:
|
||||||
return Decrement( strong );
|
return Decrement( strong );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Increment( bool strong );
|
void Increment( bool strong )
|
||||||
|
{
|
||||||
|
if ( strong )
|
||||||
|
{
|
||||||
|
m_counts->IncStrongCount();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_counts->IncWeakCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Decrement( bool strong );
|
bool Decrement( bool strong )
|
||||||
|
{
|
||||||
|
if ( strong )
|
||||||
|
{
|
||||||
|
m_counts->DecStrongCount();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_counts->DecWeakCount();
|
||||||
|
}
|
||||||
|
return !m_counts->HasStrongPointer();
|
||||||
|
}
|
||||||
|
|
||||||
bool HasStrongPointer( void ) const
|
bool HasStrongPointer( void ) const
|
||||||
{
|
{
|
||||||
return m_counts->HasStrongPointer();
|
return m_counts->HasStrongPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Swap( LockableTwoRefCounts & rhs );
|
void Swap( LockableTwoRefCounts & rhs )
|
||||||
|
{
|
||||||
|
std::swap( m_counts, rhs.m_counts );
|
||||||
|
}
|
||||||
|
|
||||||
void SetPointer( void * p )
|
void SetPointer( void * p )
|
||||||
{
|
{
|
||||||
m_counts->SetPointer( p );
|
m_counts->SetPointer( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZapPointer( void );
|
void ZapPointer( void )
|
||||||
|
{
|
||||||
|
#ifdef DO_EXTRA_LOKI_TESTS
|
||||||
|
assert( !m_counts->HasStrongPointer() );
|
||||||
|
#endif
|
||||||
|
if ( m_counts->HasWeakPointer() )
|
||||||
|
{
|
||||||
|
m_counts->ZapPointer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ThreadSafePointerAllocator::operator delete ( m_counts,
|
||||||
|
sizeof(Loki::Private::LockableTwoRefCountInfo) );
|
||||||
|
m_counts = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void * GetPointer( void ) const
|
inline void * GetPointer( void ) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,98 +110,6 @@ void TwoRefCounts::ZapPointer( void )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if defined (LOKI_OBJECT_LEVEL_THREADING) || defined (LOKI_CLASS_LEVEL_THREADING)
|
|
||||||
|
|
||||||
typedef SmallValueObject< ::Loki::ClassLevelLockable > ThreadSafePointerAllocator;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
LockableTwoRefCounts::LockableTwoRefCounts( bool strong )
|
|
||||||
: m_counts( NULL )
|
|
||||||
{
|
|
||||||
void * temp = ThreadSafePointerAllocator::operator new(
|
|
||||||
sizeof(Loki::Private::LockableTwoRefCountInfo) );
|
|
||||||
#ifdef DO_EXTRA_LOKI_TESTS
|
|
||||||
assert( temp != 0 );
|
|
||||||
#endif
|
|
||||||
m_counts = new ( temp ) Loki::Private::LockableTwoRefCountInfo( strong );
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
LockableTwoRefCounts::LockableTwoRefCounts( const void * p, bool strong )
|
|
||||||
: m_counts( NULL )
|
|
||||||
{
|
|
||||||
void * temp = ThreadSafePointerAllocator::operator new(
|
|
||||||
sizeof(Loki::Private::LockableTwoRefCountInfo) );
|
|
||||||
#ifdef DO_EXTRA_LOKI_TESTS
|
|
||||||
assert( temp != 0 );
|
|
||||||
#endif
|
|
||||||
void * p2 = const_cast< void * >( p );
|
|
||||||
m_counts = new ( temp )
|
|
||||||
Loki::Private::LockableTwoRefCountInfo( p2, strong );
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void LockableTwoRefCounts::Increment( bool strong )
|
|
||||||
{
|
|
||||||
if ( strong )
|
|
||||||
{
|
|
||||||
m_counts->IncStrongCount();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_counts->IncWeakCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool LockableTwoRefCounts::Decrement( bool strong )
|
|
||||||
{
|
|
||||||
if ( strong )
|
|
||||||
{
|
|
||||||
m_counts->DecStrongCount();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_counts->DecWeakCount();
|
|
||||||
}
|
|
||||||
return !m_counts->HasStrongPointer();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void LockableTwoRefCounts::Swap( LockableTwoRefCounts & rhs )
|
|
||||||
{
|
|
||||||
std::swap( m_counts, rhs.m_counts );
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void LockableTwoRefCounts::ZapPointer( void )
|
|
||||||
{
|
|
||||||
#ifdef DO_EXTRA_LOKI_TESTS
|
|
||||||
assert( !m_counts->HasStrongPointer() );
|
|
||||||
#endif
|
|
||||||
if ( m_counts->HasWeakPointer() )
|
|
||||||
{
|
|
||||||
m_counts->ZapPointer();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadSafePointerAllocator::operator delete ( m_counts,
|
|
||||||
sizeof(Loki::Private::LockableTwoRefCountInfo) );
|
|
||||||
m_counts = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // if object-level-locking or class-level-locking
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue