aboutsummaryrefslogtreecommitdiff
path: root/src/sharedcore.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-08-22 04:00:54 +0000
committerMike Buland <eichlan@xagasoft.com>2009-08-22 04:00:54 +0000
commit6d4a2e8f5153eefcada061d346aa5d852f2500ee (patch)
treea65dbe1ef11d3fae1b3d049c4df3d2dcec4face2 /src/sharedcore.h
parent78499c848a9c2bafe1db1ec7ceaf8556e2d7c7cc (diff)
downloadlibbu++-6d4a2e8f5153eefcada061d346aa5d852f2500ee.tar.gz
libbu++-6d4a2e8f5153eefcada061d346aa5d852f2500ee.tar.bz2
libbu++-6d4a2e8f5153eefcada061d346aa5d852f2500ee.tar.xz
libbu++-6d4a2e8f5153eefcada061d346aa5d852f2500ee.zip
Pretty much just removed the debugging from SharedCore, it wasn't at fault, and
it passed many more valgrind tests.
Diffstat (limited to '')
-rw-r--r--src/sharedcore.h37
1 files changed, 2 insertions, 35 deletions
diff --git a/src/sharedcore.h b/src/sharedcore.h
index 7960fa2..046e973 100644
--- a/src/sharedcore.h
+++ b/src/sharedcore.h
@@ -13,17 +13,6 @@
13#include <stdio.h> 13#include <stdio.h>
14#include <stdarg.h> 14#include <stdarg.h>
15 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
27namespace Bu 16namespace Bu
28{ 17{
29 template<typename Core> 18 template<typename Core>
@@ -35,33 +24,25 @@ namespace Bu
35 core( NULL ), 24 core( NULL ),
36 iRefCount( NULL ) 25 iRefCount( NULL )
37 { 26 {
38 fin( 0 );
39 core = _allocateCore(); 27 core = _allocateCore();
40 iRefCount = new int(1); 28 iRefCount = new int(1);
41 fout( 0 );
42 } 29 }
43 30
44 SharedCore( const _SharedType &rSrc ) : 31 SharedCore( const _SharedType &rSrc ) :
45 core( NULL ), 32 core( NULL ),
46 iRefCount( NULL ) 33 iRefCount( NULL )
47 { 34 {
48 fin( 1, &rSrc );
49 _softCopy( rSrc ); 35 _softCopy( rSrc );
50 fout( 1, &rSrc );
51 } 36 }
52 37
53 virtual ~SharedCore() 38 virtual ~SharedCore()
54 { 39 {
55 fin( 0 );
56 _deref(); 40 _deref();
57 fout( 0 );
58 } 41 }
59 42
60 SharedCore &operator=( const SharedCore &rhs ) 43 SharedCore &operator=( const SharedCore &rhs )
61 { 44 {
62 fin( 1, &rhs );
63 _softCopy( rhs ); 45 _softCopy( rhs );
64 fout( 1, &rhs );
65 return *this; 46 return *this;
66 } 47 }
67 48
@@ -74,43 +55,34 @@ namespace Bu
74 Core *core; 55 Core *core;
75 void _hardCopy() 56 void _hardCopy()
76 { 57 {
77 fin( 0 );
78 if( !core || !iRefCount ) 58 if( !core || !iRefCount )
79 { fout( 0 ); return; } 59 return;
80 if( (*iRefCount) == 1 ) 60 if( (*iRefCount) == 1 )
81 { fout( 0 ); return; } 61 return;
82 Core *copy = _copyCore( core ); 62 Core *copy = _copyCore( core );
83 _deref(); 63 _deref();
84 core = copy; 64 core = copy;
85 iRefCount = new int( 1 ); 65 iRefCount = new int( 1 );
86 fout( 0 );
87 } 66 }
88 67
89 virtual Core *_allocateCore() 68 virtual Core *_allocateCore()
90 { 69 {
91 fin( 0 );
92 fout( 0 );
93 return new Core(); 70 return new Core();
94 } 71 }
95 72
96 virtual Core *_copyCore( Core *pSrc ) 73 virtual Core *_copyCore( Core *pSrc )
97 { 74 {
98 fin( 0 );
99 fout( 0 );
100 return new Core( *pSrc ); 75 return new Core( *pSrc );
101 } 76 }
102 77
103 virtual void _deallocateCore( Core *pSrc ) 78 virtual void _deallocateCore( Core *pSrc )
104 { 79 {
105 fin( 0 );
106 fout( 0 );
107 delete pSrc; 80 delete pSrc;
108 } 81 }
109 82
110 private: 83 private:
111 void _deref() 84 void _deref()
112 { 85 {
113 fin( 0 );
114 if( (--(*iRefCount)) == 0 ) 86 if( (--(*iRefCount)) == 0 )
115 { 87 {
116 _deallocateCore( core ); 88 _deallocateCore( core );
@@ -118,26 +90,21 @@ namespace Bu
118 } 90 }
119 core = NULL; 91 core = NULL;
120 iRefCount = NULL; 92 iRefCount = NULL;
121 fout( 0 );
122 } 93 }
123 94
124 void _incRefCount() 95 void _incRefCount()
125 { 96 {
126 fin( 0 );
127 if( iRefCount && core ) 97 if( iRefCount && core )
128 ++(*iRefCount); 98 ++(*iRefCount);
129 fout( 0 );
130 } 99 }
131 100
132 void _softCopy( const _SharedType &rSrc ) 101 void _softCopy( const _SharedType &rSrc )
133 { 102 {
134 fin( 1, &rSrc );
135 if( core ) 103 if( core )
136 _deref(); 104 _deref();
137 core = rSrc.core; 105 core = rSrc.core;
138 iRefCount = rSrc.iRefCount; 106 iRefCount = rSrc.iRefCount;
139 _incRefCount(); 107 _incRefCount();
140 fout( 1, &rSrc );
141 } 108 }
142 109
143 int *iRefCount; 110 int *iRefCount;