aboutsummaryrefslogtreecommitdiff
path: root/doc/oscl_html/oscl__refcounter_8h_source.html
blob: b82e78df56645303f8a1625c4a74d2478e3d43cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>oscl: oscl_refcounter.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<h1>oscl_refcounter.h</h1><a href="oscl__refcounter_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// -*- c++ -*-</span>
<a name="l00002"></a>00002 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="comment">//                   O S C L _ R E F C O U N T E R</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="comment">// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =</span>
<a name="l00007"></a>00007 
<a name="l00021"></a>00021 <span class="preprocessor">#ifndef OSCL_REFCOUNTER_H_INCLUDED</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define OSCL_REFCOUNTER_H_INCLUDED</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="preprocessor">#ifndef OSCL_ASSERT_H_INCLUDED</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="oscl__assert_8h.html" title="The file oscl_assert.h provides an OSCL_ASSERT macro to document assumptions and...">oscl_assert.h</a>&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#endif</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a>00028 <span class="preprocessor">#ifndef OSCL_DEFALLOC_H_INCLUDED</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="oscl__defalloc_8h.html" title="The file defines simple default memory allocator classes. These allocators are used...">oscl_defalloc.h</a>&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#endif</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span>
<a name="l00035"></a><a class="code" href="classOsclRefCounter.html">00035</a> <span class="keyword">class </span><a class="code" href="classOsclRefCounter.html">OsclRefCounter</a>
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037     <span class="keyword">public</span>:
<a name="l00041"></a>00041         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounter.html#a36656788a3ab2b554bc7e917bf6a4adb">addRef</a>() = 0;
<a name="l00042"></a>00042 
<a name="l00046"></a>00046         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounter.html#aa7b138fd57f149a575356e51ee2d4451">removeRef</a>() = 0;
<a name="l00047"></a>00047 
<a name="l00051"></a>00051         <span class="keyword">virtual</span> uint32 <a class="code" href="classOsclRefCounter.html#a647a4b140b695ad7f8e68e41cb3cc137">getCount</a>() = 0;
<a name="l00052"></a>00052 
<a name="l00053"></a><a class="code" href="classOsclRefCounter.html#a1cf3348867331e4649cc853dfa13f327">00053</a>         <span class="keyword">virtual</span> <a class="code" href="classOsclRefCounter.html#a1cf3348867331e4649cc853dfa13f327">~OsclRefCounter</a>() {}
<a name="l00054"></a>00054 };
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 
<a name="l00061"></a><a class="code" href="classOsclRefCounterDA.html">00061</a> <span class="keyword">class </span><a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a> : <span class="keyword">public</span> <a class="code" href="classOsclRefCounter.html">OsclRefCounter</a>
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063     <span class="keyword">public</span>:
<a name="l00064"></a>00064 
<a name="l00085"></a><a class="code" href="classOsclRefCounterDA.html#a753f41e924f2990c31f48b485cf8df24">00085</a>         <a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a>(<a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *p, <a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a> *dealloc):
<a name="l00086"></a>00086                 ptr(p), deallocator(dealloc), refcnt(1)
<a name="l00087"></a>00087         {
<a name="l00088"></a>00088             <a class="code" href="group__osclbase.html#gaf7c21e5b6e4fee4247225dd31f89c8ca">OSCL_ASSERT</a>(ptr != <a class="code" href="group__osclbase.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="The NULL_TERM_CHAR is used to terminate c-style strings.">NULL</a> &amp;&amp; deallocator != <a class="code" href="group__osclbase.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="The NULL_TERM_CHAR is used to terminate c-style strings.">NULL</a>);
<a name="l00089"></a>00089         }
<a name="l00090"></a>00090 
<a name="l00095"></a><a class="code" href="classOsclRefCounterDA.html#ad8265aea5edc5db2da0c98f91d5b57ba">00095</a>         <span class="keyword">virtual</span> <a class="code" href="classOsclRefCounterDA.html#ad8265aea5edc5db2da0c98f91d5b57ba">~OsclRefCounterDA</a>() {}
<a name="l00096"></a>00096 
<a name="l00100"></a><a class="code" href="classOsclRefCounterDA.html#a697b732d60a79d1005e59d40a4b3f46f">00100</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterDA.html#a697b732d60a79d1005e59d40a4b3f46f">addRef</a>()
<a name="l00101"></a>00101         {
<a name="l00102"></a>00102             ++refcnt;
<a name="l00103"></a>00103         }
<a name="l00104"></a>00104 
<a name="l00108"></a><a class="code" href="classOsclRefCounterDA.html#a3623c9b37a3b9ca15101b7bf2b41db14">00108</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterDA.html#a3623c9b37a3b9ca15101b7bf2b41db14">removeRef</a>()
<a name="l00109"></a>00109         {
<a name="l00110"></a>00110             <span class="keywordflow">if</span> (--refcnt == 0)
<a name="l00111"></a>00111             {
<a name="l00112"></a>00112                 <span class="keywordflow">if</span> (ptr == <span class="keyword">this</span>)
<a name="l00113"></a>00113                 {
<a name="l00114"></a>00114                     <span class="comment">// buffer is part of the refcounter</span>
<a name="l00115"></a>00115                     deallocator-&gt;<a class="code" href="classOsclDestructDealloc.html#ad7ceb70eb3012d71a588854d36ddedef">destruct_and_dealloc</a>(<span class="keyword">this</span>);
<a name="l00116"></a>00116                 }
<a name="l00117"></a>00117                 <span class="keywordflow">else</span>
<a name="l00118"></a>00118                 {
<a name="l00119"></a>00119                     <span class="comment">// delete the buffer and the refcounter object</span>
<a name="l00120"></a>00120                     deallocator-&gt;<a class="code" href="classOsclDestructDealloc.html#ad7ceb70eb3012d71a588854d36ddedef">destruct_and_dealloc</a>(ptr);
<a name="l00121"></a>00121                     <span class="keyword">delete</span>(<span class="keyword">this</span>);
<a name="l00122"></a>00122                 }
<a name="l00123"></a>00123             }
<a name="l00124"></a>00124         }
<a name="l00125"></a>00125 
<a name="l00129"></a><a class="code" href="classOsclRefCounterDA.html#aff9119436453eb96a1e4bf4033093f87">00129</a>         uint32 <a class="code" href="classOsclRefCounterDA.html#aff9119436453eb96a1e4bf4033093f87">getCount</a>()
<a name="l00130"></a>00130         {
<a name="l00131"></a>00131             <span class="keywordflow">return</span> refcnt;
<a name="l00132"></a>00132         }
<a name="l00133"></a>00133 
<a name="l00134"></a>00134     <span class="keyword">private</span>:
<a name="l00135"></a>00135         <a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a>();
<a name="l00136"></a>00136         <a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a>(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a>&amp; x);
<a name="l00137"></a>00137         <a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterDA.html">OsclRefCounterDA</a>&amp; x);
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         <a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *ptr;
<a name="l00140"></a>00140         <a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a> *deallocator;
<a name="l00141"></a>00141         uint32 refcnt;
<a name="l00142"></a>00142 };
<a name="l00143"></a>00143 
<a name="l00144"></a>00144 
<a name="l00149"></a>00149 <span class="keyword">template</span>&lt;<span class="keyword">class</span> DeallocType&gt;
<a name="l00150"></a><a class="code" href="classOsclRefCounterSA.html">00150</a> <span class="keyword">class </span><a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA</a> : <span class="keyword">public</span> <a class="code" href="classOsclRefCounter.html">OsclRefCounter</a>
<a name="l00151"></a>00151 {
<a name="l00152"></a>00152     <span class="keyword">public</span>:
<a name="l00169"></a><a class="code" href="classOsclRefCounterSA.html#af61481cc6cec834f1ef2480439181e83">00169</a>         <a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA</a>(<a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *p) :
<a name="l00170"></a>00170                 ptr(p), refcnt(1)
<a name="l00171"></a>00171         {
<a name="l00172"></a>00172             <a class="code" href="group__osclbase.html#gaf7c21e5b6e4fee4247225dd31f89c8ca">OSCL_ASSERT</a>(ptr != <a class="code" href="group__osclbase.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="The NULL_TERM_CHAR is used to terminate c-style strings.">NULL</a>);
<a name="l00173"></a>00173         }
<a name="l00174"></a>00174 
<a name="l00179"></a><a class="code" href="classOsclRefCounterSA.html#ae48211ce5a12880db3da8cb13598d904">00179</a>         <span class="keyword">virtual</span> <a class="code" href="classOsclRefCounterSA.html#ae48211ce5a12880db3da8cb13598d904">~OsclRefCounterSA</a>() {}
<a name="l00180"></a>00180 
<a name="l00184"></a><a class="code" href="classOsclRefCounterSA.html#a52175effb5eaffa65475cdd4c0950d3a">00184</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterSA.html#a52175effb5eaffa65475cdd4c0950d3a">addRef</a>()
<a name="l00185"></a>00185         {
<a name="l00186"></a>00186             ++refcnt;
<a name="l00187"></a>00187         }
<a name="l00188"></a>00188 
<a name="l00192"></a><a class="code" href="classOsclRefCounterSA.html#a8959024a43a1b790aaf04c63c59ea4e5">00192</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterSA.html#a8959024a43a1b790aaf04c63c59ea4e5">removeRef</a>()
<a name="l00193"></a>00193         {
<a name="l00194"></a>00194             <span class="keywordflow">if</span> (--refcnt == 0)
<a name="l00195"></a>00195             {
<a name="l00196"></a>00196                 <span class="keywordflow">if</span> (ptr == <span class="keyword">this</span>)
<a name="l00197"></a>00197                 {
<a name="l00198"></a>00198 
<a name="l00199"></a>00199                     <span class="comment">// buffer is part of the refcounter</span>
<a name="l00200"></a>00200                     DeallocType deallocator;
<a name="l00201"></a>00201                     deallocator.destruct_and_dealloc(<span class="keyword">this</span>);
<a name="l00202"></a>00202                 }
<a name="l00203"></a>00203                 <span class="keywordflow">else</span>
<a name="l00204"></a>00204                 {
<a name="l00205"></a>00205 
<a name="l00206"></a>00206                     <span class="comment">// delete the buffer and the recounter object</span>
<a name="l00207"></a>00207                     DeallocType deallocator;
<a name="l00208"></a>00208                     deallocator.destruct_and_dealloc(ptr);
<a name="l00209"></a>00209                     <span class="keyword">delete</span>(<span class="keyword">this</span>);
<a name="l00210"></a>00210                 }
<a name="l00211"></a>00211             }
<a name="l00212"></a>00212         }
<a name="l00213"></a>00213 
<a name="l00217"></a><a class="code" href="classOsclRefCounterSA.html#a5cc5ade6be2d040b1754eb4587545c28">00217</a>         uint32 <a class="code" href="classOsclRefCounterSA.html#a5cc5ade6be2d040b1754eb4587545c28">getCount</a>()
<a name="l00218"></a>00218         {
<a name="l00219"></a>00219             <span class="keywordflow">return</span> refcnt;
<a name="l00220"></a>00220         }
<a name="l00221"></a>00221 
<a name="l00222"></a>00222     <span class="keyword">private</span>:
<a name="l00223"></a>00223         <a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA</a>();
<a name="l00224"></a>00224         <a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA</a>(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA&lt;DeallocType&gt;</a>&amp; x);
<a name="l00225"></a>00225         <a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA&lt;DeallocType&gt;</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterSA.html">OsclRefCounterSA&lt;DeallocType&gt;</a>&amp; x);
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         <a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *ptr;
<a name="l00228"></a>00228         uint32 refcnt;
<a name="l00229"></a>00229 };
<a name="l00230"></a>00230 
<a name="l00235"></a>00235 <span class="keyword">template</span>&lt;<span class="keyword">class</span> LockType&gt;
<a name="l00236"></a><a class="code" href="classOsclRefCounterMTDA.html">00236</a> <span class="keyword">class </span><a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA</a> : <span class="keyword">public</span> <a class="code" href="classOsclRefCounter.html">OsclRefCounter</a>
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238     <span class="keyword">public</span>:
<a name="l00239"></a>00239 
<a name="l00260"></a><a class="code" href="classOsclRefCounterMTDA.html#a79b9e26eaf436127de81289f83fc41dc">00260</a>         <a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA</a>(<a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *p, <a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a> *dealloc) :
<a name="l00261"></a>00261                 ptr(p), deallocator(dealloc), refcnt(1)
<a name="l00262"></a>00262         {
<a name="l00263"></a>00263             <a class="code" href="group__osclbase.html#gaf7c21e5b6e4fee4247225dd31f89c8ca">OSCL_ASSERT</a>(ptr != <a class="code" href="group__osclbase.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="The NULL_TERM_CHAR is used to terminate c-style strings.">NULL</a> &amp;&amp; deallocator != <a class="code" href="group__osclbase.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="The NULL_TERM_CHAR is used to terminate c-style strings.">NULL</a>);
<a name="l00264"></a>00264         }
<a name="l00265"></a>00265 
<a name="l00270"></a><a class="code" href="classOsclRefCounterMTDA.html#aedb97c08db63effb3e27d47d83a7f2c6">00270</a>         <span class="keyword">virtual</span> <a class="code" href="classOsclRefCounterMTDA.html#aedb97c08db63effb3e27d47d83a7f2c6">~OsclRefCounterMTDA</a>() {}
<a name="l00271"></a>00271 
<a name="l00275"></a><a class="code" href="classOsclRefCounterMTDA.html#a4f4bde5095f2d950ae88df3957a8f1f9">00275</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterMTDA.html#a4f4bde5095f2d950ae88df3957a8f1f9">addRef</a>()
<a name="l00276"></a>00276         {
<a name="l00277"></a>00277             lock.Lock();
<a name="l00278"></a>00278             ++refcnt;
<a name="l00279"></a>00279             lock.Unlock();
<a name="l00280"></a>00280         }
<a name="l00281"></a>00281 
<a name="l00285"></a><a class="code" href="classOsclRefCounterMTDA.html#a09931f739648a13952cc8da43e8cfd53">00285</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterMTDA.html#a09931f739648a13952cc8da43e8cfd53">removeRef</a>()
<a name="l00286"></a>00286         {
<a name="l00287"></a>00287             lock.Lock();
<a name="l00288"></a>00288             <span class="keywordflow">if</span> (--refcnt == 0)
<a name="l00289"></a>00289             {
<a name="l00290"></a>00290                 <span class="keywordflow">if</span> (ptr == <span class="keyword">this</span>)
<a name="l00291"></a>00291                 {
<a name="l00292"></a>00292 
<a name="l00293"></a>00293                     <span class="comment">// buffer is part of the refcounter</span>
<a name="l00294"></a>00294                     deallocator-&gt;<a class="code" href="classOsclDestructDealloc.html#ad7ceb70eb3012d71a588854d36ddedef">destruct_and_dealloc</a>(<span class="keyword">this</span>);
<a name="l00295"></a>00295                 }
<a name="l00296"></a>00296                 <span class="keywordflow">else</span>
<a name="l00297"></a>00297                 {
<a name="l00298"></a>00298                     <span class="comment">// delete the buffer and the refcounter object</span>
<a name="l00299"></a>00299                     deallocator-&gt;<a class="code" href="classOsclDestructDealloc.html#ad7ceb70eb3012d71a588854d36ddedef">destruct_and_dealloc</a>(ptr);
<a name="l00300"></a>00300                     <span class="keyword">delete</span>(<span class="keyword">this</span>);
<a name="l00301"></a>00301                 }
<a name="l00302"></a>00302             }
<a name="l00303"></a>00303             <span class="keywordflow">else</span>
<a name="l00304"></a>00304             {
<a name="l00305"></a>00305                 lock.Unlock();
<a name="l00306"></a>00306             }
<a name="l00307"></a>00307         }
<a name="l00308"></a>00308 
<a name="l00312"></a><a class="code" href="classOsclRefCounterMTDA.html#aeec2f9ae8c94ff951c2cb395c4dc6f03">00312</a>         uint32 <a class="code" href="classOsclRefCounterMTDA.html#aeec2f9ae8c94ff951c2cb395c4dc6f03">getCount</a>()
<a name="l00313"></a>00313         {
<a name="l00314"></a>00314             <span class="keywordflow">return</span> refcnt;
<a name="l00315"></a>00315         }
<a name="l00316"></a>00316 
<a name="l00317"></a>00317     <span class="keyword">private</span>:
<a name="l00318"></a>00318         <a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA</a>();
<a name="l00319"></a>00319         <a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA</a>(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA&lt;LockType&gt;</a>&amp; x);
<a name="l00320"></a>00320         <a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA&lt;LockType&gt;</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterMTDA.html">OsclRefCounterMTDA&lt;LockType&gt;</a>&amp; x);
<a name="l00321"></a>00321 
<a name="l00322"></a>00322         <a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *ptr;
<a name="l00323"></a>00323         <a class="code" href="classOsclDestructDealloc.html">OsclDestructDealloc</a> *deallocator;
<a name="l00324"></a>00324         LockType lock;
<a name="l00325"></a>00325         uint32 refcnt;
<a name="l00326"></a>00326 };
<a name="l00327"></a>00327 
<a name="l00328"></a>00328 
<a name="l00333"></a>00333 <span class="keyword">template</span>&lt;<span class="keyword">class</span> DeallocType, <span class="keyword">class</span> LockType&gt;
<a name="l00334"></a><a class="code" href="classOsclRefCounterMTSA.html">00334</a> <span class="keyword">class </span><a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA</a> : <span class="keyword">public</span> <a class="code" href="classOsclRefCounter.html">OsclRefCounter</a>
<a name="l00335"></a>00335 {
<a name="l00336"></a>00336     <span class="keyword">public</span>:
<a name="l00353"></a><a class="code" href="classOsclRefCounterMTSA.html#ac34c965e8a6a1339e1b7f25b92380cbd">00353</a>         <a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA</a>(<a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *p) :
<a name="l00354"></a>00354                 ptr(p), refcnt(1)
<a name="l00355"></a>00355         {
<a name="l00356"></a>00356             <a class="code" href="group__osclbase.html#gaf7c21e5b6e4fee4247225dd31f89c8ca">OSCL_ASSERT</a>(ptr != <a class="code" href="group__osclbase.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="The NULL_TERM_CHAR is used to terminate c-style strings.">NULL</a>);
<a name="l00357"></a>00357         }
<a name="l00358"></a>00358 
<a name="l00363"></a><a class="code" href="classOsclRefCounterMTSA.html#ab6971ce5a6b62ca31729c6bda27d5519">00363</a>         <span class="keyword">virtual</span> <a class="code" href="classOsclRefCounterMTSA.html#ab6971ce5a6b62ca31729c6bda27d5519">~OsclRefCounterMTSA</a>() {}
<a name="l00364"></a>00364 
<a name="l00368"></a><a class="code" href="classOsclRefCounterMTSA.html#a509c75ca217f1df590c4acfdb7a423ed">00368</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterMTSA.html#a509c75ca217f1df590c4acfdb7a423ed">addRef</a>()
<a name="l00369"></a>00369         {
<a name="l00370"></a>00370             lock.Lock();
<a name="l00371"></a>00371             ++refcnt;
<a name="l00372"></a>00372             lock.Unlock();
<a name="l00373"></a>00373         }
<a name="l00374"></a>00374 
<a name="l00378"></a><a class="code" href="classOsclRefCounterMTSA.html#a738122f256031529af58cb05e3f38d75">00378</a>         <span class="keywordtype">void</span> <a class="code" href="classOsclRefCounterMTSA.html#a738122f256031529af58cb05e3f38d75">removeRef</a>()
<a name="l00379"></a>00379         {
<a name="l00380"></a>00380             lock.Lock();
<a name="l00381"></a>00381             <span class="keywordflow">if</span> (--refcnt == 0)
<a name="l00382"></a>00382             {
<a name="l00383"></a>00383                 <span class="keywordflow">if</span> (ptr == <span class="keyword">this</span>)
<a name="l00384"></a>00384                 {
<a name="l00385"></a>00385                     <span class="comment">// buffer is part of the refcounter</span>
<a name="l00386"></a>00386                     DeallocType deallocator;
<a name="l00387"></a>00387                     deallocator.destruct_and_dealloc(<span class="keyword">this</span>);
<a name="l00388"></a>00388                 }
<a name="l00389"></a>00389                 <span class="keywordflow">else</span>
<a name="l00390"></a>00390                 {
<a name="l00391"></a>00391 
<a name="l00392"></a>00392                     <span class="comment">// delete the buffer and the recounter object</span>
<a name="l00393"></a>00393                     DeallocType deallocator;
<a name="l00394"></a>00394                     deallocator.destruct_and_dealloc(ptr);
<a name="l00395"></a>00395                     <span class="keyword">delete</span>(<span class="keyword">this</span>);
<a name="l00396"></a>00396                 }
<a name="l00397"></a>00397             }
<a name="l00398"></a>00398             <span class="keywordflow">else</span>
<a name="l00399"></a>00399             {
<a name="l00400"></a>00400                 lock.Unlock();
<a name="l00401"></a>00401             }
<a name="l00402"></a>00402         }
<a name="l00403"></a>00403 
<a name="l00407"></a><a class="code" href="classOsclRefCounterMTSA.html#a4be07b2930e3406a6ae41b243bfdc53e">00407</a>         uint32 <a class="code" href="classOsclRefCounterMTSA.html#a4be07b2930e3406a6ae41b243bfdc53e">getCount</a>()
<a name="l00408"></a>00408         {
<a name="l00409"></a>00409             <span class="keywordflow">return</span> refcnt;
<a name="l00410"></a>00410         }
<a name="l00411"></a>00411 
<a name="l00412"></a>00412     <span class="keyword">private</span>:
<a name="l00413"></a>00413         <a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA</a>();
<a name="l00414"></a>00414         <a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA</a>(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA&lt;DeallocType, LockType&gt;</a>&amp; x);
<a name="l00415"></a>00415         <a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA&lt;DeallocType, LockType&gt;</a>&amp; operator=(<span class="keyword">const</span> <a class="code" href="classOsclRefCounterMTSA.html">OsclRefCounterMTSA&lt;DeallocType, LockType&gt;</a>&amp; x);
<a name="l00416"></a>00416 
<a name="l00417"></a>00417         <a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a> *ptr;
<a name="l00418"></a>00418         LockType lock;
<a name="l00419"></a>00419         uint32 refcnt;
<a name="l00420"></a>00420 };
<a name="l00421"></a>00421 
<a name="l00426"></a>00426 <span class="keyword">template</span>&lt;<span class="keyword">class</span> DefAlloc&gt;
<a name="l00427"></a><a class="code" href="classOscl__DefAllocWithRefCounter.html">00427</a> <span class="keyword">class </span><a class="code" href="classOscl__DefAllocWithRefCounter.html">Oscl_DefAllocWithRefCounter</a>: <span class="keyword">public</span> <a class="code" href="classOsclRefCounter.html">OsclRefCounter</a>, <span class="keyword">public</span> DefAlloc
<a name="l00428"></a>00428 {
<a name="l00429"></a>00429     <span class="keyword">public</span>:
<a name="l00432"></a><a class="code" href="classOscl__DefAllocWithRefCounter.html#a9a298fb97e1f18b624aaa1475832c51c">00432</a>         <span class="keyword">static</span> <a class="code" href="classOscl__DefAllocWithRefCounter.html">Oscl_DefAllocWithRefCounter</a>* <a class="code" href="classOscl__DefAllocWithRefCounter.html#a9a298fb97e1f18b624aaa1475832c51c">New</a>()
<a name="l00433"></a>00433         {
<a name="l00434"></a>00434             DefAlloc alloc;
<a name="l00435"></a>00435             <a class="code" href="group__osclbase.html#ga3bac54662348f5e6c08b97ca97066b89" title="The OsclAny is meant to be used the context of a generic pointer (i.e., no specific...">OsclAny</a>* p = alloc.ALLOCATE(<span class="keyword">sizeof</span>(<a class="code" href="classOscl__DefAllocWithRefCounter.html">Oscl_DefAllocWithRefCounter</a>));
<a name="l00436"></a>00436             <span class="keywordflow">return</span> <span class="keyword">new</span>(p) <a class="code" href="classOscl__DefAllocWithRefCounter.html">Oscl_DefAllocWithRefCounter</a>();
<a name="l00437"></a>00437         }
<a name="l00438"></a>00438 
<a name="l00441"></a><a class="code" href="classOscl__DefAllocWithRefCounter.html#aaee91ad79ba1e62dff4f28be453ae27c">00441</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__DefAllocWithRefCounter.html#aaee91ad79ba1e62dff4f28be453ae27c">Delete</a>()
<a name="l00442"></a>00442         {
<a name="l00443"></a>00443             <a class="code" href="classOscl__DefAllocWithRefCounter.html#af05f652de0278cc8eae8d6c7708b4024">removeRef</a>();
<a name="l00444"></a>00444         }
<a name="l00445"></a>00445 
<a name="l00446"></a><a class="code" href="classOscl__DefAllocWithRefCounter.html#af7626b29dde4696927f5500ffabcbb80">00446</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__DefAllocWithRefCounter.html#af7626b29dde4696927f5500ffabcbb80">addRef</a>()
<a name="l00447"></a>00447         {
<a name="l00448"></a>00448             refcount++;
<a name="l00449"></a>00449         }
<a name="l00450"></a>00450 
<a name="l00451"></a><a class="code" href="classOscl__DefAllocWithRefCounter.html#af05f652de0278cc8eae8d6c7708b4024">00451</a>         <span class="keywordtype">void</span> <a class="code" href="classOscl__DefAllocWithRefCounter.html#af05f652de0278cc8eae8d6c7708b4024">removeRef</a>()
<a name="l00452"></a>00452         {
<a name="l00453"></a>00453             --refcount;
<a name="l00454"></a>00454             <span class="keywordflow">if</span> (refcount == 0)
<a name="l00455"></a>00455                 DefAlloc::deallocate(<span class="keyword">this</span>);
<a name="l00456"></a>00456         }
<a name="l00457"></a>00457 
<a name="l00458"></a><a class="code" href="classOscl__DefAllocWithRefCounter.html#a5b45c2be66e6f7ba3689cf964280f40a">00458</a>         uint32 <a class="code" href="classOscl__DefAllocWithRefCounter.html#a5b45c2be66e6f7ba3689cf964280f40a">getCount</a>()
<a name="l00459"></a>00459         {
<a name="l00460"></a>00460             <span class="keywordflow">return</span> refcount;
<a name="l00461"></a>00461         }
<a name="l00462"></a>00462 
<a name="l00463"></a>00463     <span class="keyword">private</span>:
<a name="l00464"></a>00464         <a class="code" href="classOscl__DefAllocWithRefCounter.html">Oscl_DefAllocWithRefCounter</a>(): refcount(1)
<a name="l00465"></a>00465         {}
<a name="l00466"></a>00466         uint32 refcount;
<a name="l00467"></a>00467 };
<a name="l00468"></a>00468 
<a name="l00472"></a>00472 <span class="preprocessor">#endif</span>
</pre></div></div>
<hr size="1"><img src="pvlogo_small.jpg"><address style="align: right;"><small>OSCL API</small>
<address style="align: left;"><small>Posting Version: CORE_9.004.1.1 </small>
</small></address>
</body>
</html>