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:
syntheticpp 2007-02-25 12:49:19 +00:00
parent 6050c23d24
commit af68912216
2 changed files with 67 additions and 98 deletions

View file

@ -621,11 +621,33 @@ private:
class LOKI_EXPORT LockableTwoRefCounts
{
typedef SmallValueObject< ::Loki::ClassLevelLockable > ThreadSafePointerAllocator;
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 ) :
m_counts( rhs.m_counts )
@ -648,23 +670,62 @@ protected:
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
{
return m_counts->HasStrongPointer();
}
void Swap( LockableTwoRefCounts & rhs );
void Swap( LockableTwoRefCounts & rhs )
{
std::swap( m_counts, rhs.m_counts );
}
void SetPointer( void * 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
{

View file

@ -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
// ----------------------------------------------------------------------------