aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-08-21 22:12:10 +0000
committerMike Buland <eichlan@xagasoft.com>2009-08-21 22:12:10 +0000
commit78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc (patch)
tree60cc931b6d398b478ac99d6f946e6fbc72d24fb2 /src
parent539d6bf53bcece62e29d3d7d900b83dc03275b65 (diff)
downloadlibbu++-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 '')
-rw-r--r--src/fbasicstring.h5
-rw-r--r--src/list.h6
-rw-r--r--src/sharedcore.cpp67
-rw-r--r--src/sharedcore.h49
-rw-r--r--src/tests/sharedcore.cpp9
5 files changed, 132 insertions, 4 deletions
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
82 } 82 }
83 } 83 }
84 84
85 virtual ~FStringCore()
86 {
87 clear();
88 }
89
85 mutable long nLength; 90 mutable long nLength;
86 mutable Chunk *pFirst; 91 mutable Chunk *pFirst;
87 mutable Chunk *pLast; 92 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
33 pLast( NULL ), 33 pLast( NULL ),
34 nSize( 0 ) 34 nSize( 0 )
35 { } 35 { }
36
37 virtual ~ListCore()
38 {
39 clear();
40 }
41
36 Link *pFirst; 42 Link *pFirst;
37 Link *pLast; 43 Link *pLast;
38 long nSize; 44 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 @@
7 7
8#include "bu/sharedcore.h" 8#include "bu/sharedcore.h"
9 9
10void hardlog(const char *fmt, ...)
11{
12 va_list ap;
13 va_start( ap, fmt );
14
15 FILE *fh = fopen("sharedcore.log", "ab");
16 vfprintf( fh, fmt, ap );
17 va_end( ap );
18 fclose( fh );
19}
20
21int iDepth = 0;
22
23void fncin( void *base, const char *fn, void *core, int *iRefCount, int params, ... )
24{
25 va_list ap;
26 va_start( ap, params );
27
28 FILE *fh = fopen("sharedcore.log", "ab");
29 fprintf( fh, "%08X: ", base );
30 for( int j = 0; j < iDepth; j++ )
31 fprintf( fh, " " );
32 fprintf( fh, "%s(", fn );
33 for( int j = 0; j < params; j++ )
34 if( j == 0 )
35 fprintf( fh, " %08X", va_arg( ap, void * ) );
36 else
37 fprintf( fh, ", %08X", va_arg( ap, void * ) );
38 if( params > 0 )
39 fprintf( fh, " )");
40 else
41 fprintf( fh, ")");
42
43 fprintf( fh, " [%08X / %08X] (%d)\n", core, iRefCount, rc );
44 va_end( ap );
45 fclose( fh );
46
47 iDepth++;
48}
49
50void fncout( void *base, const char *fn, void *core, int *iRefCount, int params, ... )
51{
52 va_list ap;
53 va_start( ap, params );
54
55 iDepth--;
56
57 FILE *fh = fopen("sharedcore.log", "ab");
58 fprintf( fh, "%08X: ", base );
59 for( int j = 0; j < iDepth; j++ )
60 fprintf( fh, " " );
61 fprintf( fh, "%s(", fn );
62 for( int j = 0; j < params; j++ )
63 if( j == 0 )
64 fprintf( fh, " %08X", va_arg( ap, void * ) );
65 else
66 fprintf( fh, ", %08X", va_arg( ap, void * ) );
67 if( params > 0 )
68 fprintf( fh, " )");
69 else
70 fprintf( fh, ")");
71
72 fprintf( fh, " [%08X / %08X] (%d)\n", core, iRefCount, rc );
73 va_end( ap );
74 fclose( fh );
75}
76
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
16void hardlog(const char *fmt, ...);
17
18void fncin( void *base, const char *fn, void *core, int *refcnt, int params, ... );
19void 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
13namespace Bu 27namespace 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
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()
78 78
79 line( a.setVal( b.getVal() ); ) 79 line( a.setVal( b.getVal() ); )
80 line( a == b; ) 80 line( a == b; )
81
82 {
83 Shint c( b );
84 Shint d( c );
85 sio << c.getVal();
86 d.setVal( 43 );
87 }
88
89 sio << b.getVal();
81} 90}
82 91