From 78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 21 Aug 2009 22:12:10 +0000 Subject: Added loads of debugging to sharedcore, we're sure it's to blame, but not as much anymore, for the fishtrax issues, maybe. --- src/fbasicstring.h | 5 ++++ src/list.h | 6 +++++ src/sharedcore.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ src/sharedcore.h | 49 ++++++++++++++++++++++++++++++++--- src/tests/sharedcore.cpp | 9 +++++++ 5 files changed, 132 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/fbasicstring.h b/src/fbasicstring.h index cf7a786..a654d91 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -82,6 +82,11 @@ namespace Bu } } + virtual ~FStringCore() + { + clear(); + } + mutable long nLength; mutable Chunk *pFirst; mutable Chunk *pLast; diff --git a/src/list.h b/src/list.h index d06bc9e..9574bca 100644 --- a/src/list.h +++ b/src/list.h @@ -33,6 +33,12 @@ namespace Bu pLast( NULL ), nSize( 0 ) { } + + virtual ~ListCore() + { + clear(); + } + Link *pFirst; Link *pLast; long nSize; diff --git a/src/sharedcore.cpp b/src/sharedcore.cpp index 6333335..24d8972 100644 --- a/src/sharedcore.cpp +++ b/src/sharedcore.cpp @@ -7,3 +7,70 @@ #include "bu/sharedcore.h" +void hardlog(const char *fmt, ...) +{ + va_list ap; + va_start( ap, fmt ); + + FILE *fh = fopen("sharedcore.log", "ab"); + vfprintf( fh, fmt, ap ); + va_end( ap ); + fclose( fh ); +} + +int iDepth = 0; + +void fncin( void *base, const char *fn, void *core, int *iRefCount, int params, ... ) +{ + va_list ap; + va_start( ap, params ); + + FILE *fh = fopen("sharedcore.log", "ab"); + fprintf( fh, "%08X: ", base ); + for( int j = 0; j < iDepth; j++ ) + fprintf( fh, " " ); + fprintf( fh, "%s(", fn ); + for( int j = 0; j < params; j++ ) + if( j == 0 ) + fprintf( fh, " %08X", va_arg( ap, void * ) ); + else + fprintf( fh, ", %08X", va_arg( ap, void * ) ); + if( params > 0 ) + fprintf( fh, " )"); + else + fprintf( fh, ")"); + + fprintf( fh, " [%08X / %08X] (%d)\n", core, iRefCount, rc ); + va_end( ap ); + fclose( fh ); + + iDepth++; +} + +void fncout( void *base, const char *fn, void *core, int *iRefCount, int params, ... ) +{ + va_list ap; + va_start( ap, params ); + + iDepth--; + + FILE *fh = fopen("sharedcore.log", "ab"); + fprintf( fh, "%08X: ", base ); + for( int j = 0; j < iDepth; j++ ) + fprintf( fh, " " ); + fprintf( fh, "%s(", fn ); + for( int j = 0; j < params; j++ ) + if( j == 0 ) + fprintf( fh, " %08X", va_arg( ap, void * ) ); + else + fprintf( fh, ", %08X", va_arg( ap, void * ) ); + if( params > 0 ) + fprintf( fh, " )"); + else + fprintf( fh, ")"); + + fprintf( fh, " [%08X / %08X] (%d)\n", core, iRefCount, rc ); + va_end( ap ); + fclose( fh ); +} + diff --git a/src/sharedcore.h b/src/sharedcore.h index 3b60c42..7960fa2 100644 --- a/src/sharedcore.h +++ b/src/sharedcore.h @@ -10,6 +10,20 @@ #include "bu/util.h" +#include +#include + +void hardlog(const char *fmt, ...); + +void fncin( void *base, const char *fn, void *core, int *refcnt, int params, ... ); +void fncout( void *base, const char *fn, void *core, int *refcnt, int params, ... ); + + +#define fin( count, ... ) fncin( (void *)this, __FUNCTION__, core, iRefCount, count, ##__VA_ARGS__ ) +#define fout( count, ... ) fncout( (void *)this, __FUNCTION__, core, iRefCount, count, ##__VA_ARGS__ ) + +#define rc ((iRefCount==NULL)?(-1):(*iRefCount)) + namespace Bu { template @@ -18,26 +32,36 @@ namespace Bu typedef class SharedCore _SharedType; public: SharedCore() : - core( _allocateCore() ), - iRefCount( new int(1) ) + core( NULL ), + iRefCount( NULL ) { + fin( 0 ); + core = _allocateCore(); + iRefCount = new int(1); + fout( 0 ); } SharedCore( const _SharedType &rSrc ) : core( NULL ), iRefCount( NULL ) { + fin( 1, &rSrc ); _softCopy( rSrc ); + fout( 1, &rSrc ); } virtual ~SharedCore() { + fin( 0 ); _deref(); + fout( 0 ); } SharedCore &operator=( const SharedCore &rhs ) { + fin( 1, &rhs ); _softCopy( rhs ); + fout( 1, &rhs ); return *this; } @@ -50,34 +74,43 @@ namespace Bu Core *core; void _hardCopy() { + fin( 0 ); if( !core || !iRefCount ) - return; + { fout( 0 ); return; } if( (*iRefCount) == 1 ) - return; + { fout( 0 ); return; } Core *copy = _copyCore( core ); _deref(); core = copy; iRefCount = new int( 1 ); + fout( 0 ); } virtual Core *_allocateCore() { + fin( 0 ); + fout( 0 ); return new Core(); } virtual Core *_copyCore( Core *pSrc ) { + fin( 0 ); + fout( 0 ); return new Core( *pSrc ); } virtual void _deallocateCore( Core *pSrc ) { + fin( 0 ); + fout( 0 ); delete pSrc; } private: void _deref() { + fin( 0 ); if( (--(*iRefCount)) == 0 ) { _deallocateCore( core ); @@ -85,25 +118,33 @@ namespace Bu } core = NULL; iRefCount = NULL; + fout( 0 ); } void _incRefCount() { + fin( 0 ); if( iRefCount && core ) ++(*iRefCount); + fout( 0 ); } void _softCopy( const _SharedType &rSrc ) { + fin( 1, &rSrc ); if( core ) _deref(); core = rSrc.core; iRefCount = rSrc.iRefCount; _incRefCount(); + fout( 1, &rSrc ); } int *iRefCount; }; }; +#undef fin +#undef fout + #endif diff --git a/src/tests/sharedcore.cpp b/src/tests/sharedcore.cpp index 9f65ac5..381661a 100644 --- a/src/tests/sharedcore.cpp +++ b/src/tests/sharedcore.cpp @@ -78,5 +78,14 @@ int main() line( a.setVal( b.getVal() ); ) line( a == b; ) + + { + Shint c( b ); + Shint d( c ); + sio << c.getVal(); + d.setVal( 43 ); + } + + sio << b.getVal(); } -- cgit v1.2.3