diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2009-08-21 22:12:10 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2009-08-21 22:12:10 +0000 |
| commit | 78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc (patch) | |
| tree | 60cc931b6d398b478ac99d6f946e6fbc72d24fb2 /src/sharedcore.h | |
| parent | 539d6bf53bcece62e29d3d7d900b83dc03275b65 (diff) | |
| download | libbu++-78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc.tar.gz libbu++-78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc.tar.bz2 libbu++-78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc.tar.xz libbu++-78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc.zip | |
Added loads of debugging to sharedcore, we're sure it's to blame, but not as
much anymore, for the fishtrax issues, maybe.
Diffstat (limited to 'src/sharedcore.h')
| -rw-r--r-- | src/sharedcore.h | 49 |
1 files changed, 45 insertions, 4 deletions
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 @@ | |||
| 10 | 10 | ||
| 11 | #include "bu/util.h" | 11 | #include "bu/util.h" |
| 12 | 12 | ||
| 13 | #include <stdio.h> | ||
| 14 | #include <stdarg.h> | ||
| 15 | |||
| 16 | void hardlog(const char *fmt, ...); | ||
| 17 | |||
| 18 | void fncin( void *base, const char *fn, void *core, int *refcnt, int params, ... ); | ||
| 19 | void fncout( void *base, const char *fn, void *core, int *refcnt, int params, ... ); | ||
| 20 | |||
| 21 | |||
| 22 | #define fin( count, ... ) fncin( (void *)this, __FUNCTION__, core, iRefCount, count, ##__VA_ARGS__ ) | ||
| 23 | #define fout( count, ... ) fncout( (void *)this, __FUNCTION__, core, iRefCount, count, ##__VA_ARGS__ ) | ||
| 24 | |||
| 25 | #define rc ((iRefCount==NULL)?(-1):(*iRefCount)) | ||
| 26 | |||
| 13 | namespace Bu | 27 | namespace Bu |
| 14 | { | 28 | { |
| 15 | template<typename Core> | 29 | template<typename Core> |
| @@ -18,26 +32,36 @@ namespace Bu | |||
| 18 | typedef class SharedCore<Core> _SharedType; | 32 | typedef class SharedCore<Core> _SharedType; |
| 19 | public: | 33 | public: |
| 20 | SharedCore() : | 34 | SharedCore() : |
| 21 | core( _allocateCore() ), | 35 | core( NULL ), |
| 22 | iRefCount( new int(1) ) | 36 | iRefCount( NULL ) |
| 23 | { | 37 | { |
| 38 | fin( 0 ); | ||
| 39 | core = _allocateCore(); | ||
| 40 | iRefCount = new int(1); | ||
| 41 | fout( 0 ); | ||
| 24 | } | 42 | } |
| 25 | 43 | ||
| 26 | SharedCore( const _SharedType &rSrc ) : | 44 | SharedCore( const _SharedType &rSrc ) : |
| 27 | core( NULL ), | 45 | core( NULL ), |
| 28 | iRefCount( NULL ) | 46 | iRefCount( NULL ) |
| 29 | { | 47 | { |
| 48 | fin( 1, &rSrc ); | ||
| 30 | _softCopy( rSrc ); | 49 | _softCopy( rSrc ); |
| 50 | fout( 1, &rSrc ); | ||
| 31 | } | 51 | } |
| 32 | 52 | ||
| 33 | virtual ~SharedCore() | 53 | virtual ~SharedCore() |
| 34 | { | 54 | { |
| 55 | fin( 0 ); | ||
| 35 | _deref(); | 56 | _deref(); |
| 57 | fout( 0 ); | ||
| 36 | } | 58 | } |
| 37 | 59 | ||
| 38 | SharedCore &operator=( const SharedCore &rhs ) | 60 | SharedCore &operator=( const SharedCore &rhs ) |
| 39 | { | 61 | { |
| 62 | fin( 1, &rhs ); | ||
| 40 | _softCopy( rhs ); | 63 | _softCopy( rhs ); |
| 64 | fout( 1, &rhs ); | ||
| 41 | return *this; | 65 | return *this; |
| 42 | } | 66 | } |
| 43 | 67 | ||
| @@ -50,34 +74,43 @@ namespace Bu | |||
| 50 | Core *core; | 74 | Core *core; |
| 51 | void _hardCopy() | 75 | void _hardCopy() |
| 52 | { | 76 | { |
| 77 | fin( 0 ); | ||
| 53 | if( !core || !iRefCount ) | 78 | if( !core || !iRefCount ) |
| 54 | return; | 79 | { fout( 0 ); return; } |
| 55 | if( (*iRefCount) == 1 ) | 80 | if( (*iRefCount) == 1 ) |
| 56 | return; | 81 | { fout( 0 ); return; } |
| 57 | Core *copy = _copyCore( core ); | 82 | Core *copy = _copyCore( core ); |
| 58 | _deref(); | 83 | _deref(); |
| 59 | core = copy; | 84 | core = copy; |
| 60 | iRefCount = new int( 1 ); | 85 | iRefCount = new int( 1 ); |
| 86 | fout( 0 ); | ||
| 61 | } | 87 | } |
| 62 | 88 | ||
| 63 | virtual Core *_allocateCore() | 89 | virtual Core *_allocateCore() |
| 64 | { | 90 | { |
| 91 | fin( 0 ); | ||
| 92 | fout( 0 ); | ||
| 65 | return new Core(); | 93 | return new Core(); |
| 66 | } | 94 | } |
| 67 | 95 | ||
| 68 | virtual Core *_copyCore( Core *pSrc ) | 96 | virtual Core *_copyCore( Core *pSrc ) |
| 69 | { | 97 | { |
| 98 | fin( 0 ); | ||
| 99 | fout( 0 ); | ||
| 70 | return new Core( *pSrc ); | 100 | return new Core( *pSrc ); |
| 71 | } | 101 | } |
| 72 | 102 | ||
| 73 | virtual void _deallocateCore( Core *pSrc ) | 103 | virtual void _deallocateCore( Core *pSrc ) |
| 74 | { | 104 | { |
| 105 | fin( 0 ); | ||
| 106 | fout( 0 ); | ||
| 75 | delete pSrc; | 107 | delete pSrc; |
| 76 | } | 108 | } |
| 77 | 109 | ||
| 78 | private: | 110 | private: |
| 79 | void _deref() | 111 | void _deref() |
| 80 | { | 112 | { |
| 113 | fin( 0 ); | ||
| 81 | if( (--(*iRefCount)) == 0 ) | 114 | if( (--(*iRefCount)) == 0 ) |
| 82 | { | 115 | { |
| 83 | _deallocateCore( core ); | 116 | _deallocateCore( core ); |
| @@ -85,25 +118,33 @@ namespace Bu | |||
| 85 | } | 118 | } |
| 86 | core = NULL; | 119 | core = NULL; |
| 87 | iRefCount = NULL; | 120 | iRefCount = NULL; |
| 121 | fout( 0 ); | ||
| 88 | } | 122 | } |
| 89 | 123 | ||
| 90 | void _incRefCount() | 124 | void _incRefCount() |
| 91 | { | 125 | { |
| 126 | fin( 0 ); | ||
| 92 | if( iRefCount && core ) | 127 | if( iRefCount && core ) |
| 93 | ++(*iRefCount); | 128 | ++(*iRefCount); |
| 129 | fout( 0 ); | ||
| 94 | } | 130 | } |
| 95 | 131 | ||
| 96 | void _softCopy( const _SharedType &rSrc ) | 132 | void _softCopy( const _SharedType &rSrc ) |
| 97 | { | 133 | { |
| 134 | fin( 1, &rSrc ); | ||
| 98 | if( core ) | 135 | if( core ) |
| 99 | _deref(); | 136 | _deref(); |
| 100 | core = rSrc.core; | 137 | core = rSrc.core; |
| 101 | iRefCount = rSrc.iRefCount; | 138 | iRefCount = rSrc.iRefCount; |
| 102 | _incRefCount(); | 139 | _incRefCount(); |
| 140 | fout( 1, &rSrc ); | ||
| 103 | } | 141 | } |
| 104 | 142 | ||
| 105 | int *iRefCount; | 143 | int *iRefCount; |
| 106 | }; | 144 | }; |
| 107 | }; | 145 | }; |
| 108 | 146 | ||
| 147 | #undef fin | ||
| 148 | #undef fout | ||
| 149 | |||
| 109 | #endif | 150 | #endif |
