author | Pat Downey <patd@symbian.org> |
Wed, 01 Sep 2010 12:34:56 +0100 | |
branch | RCL_3 |
changeset 44 | 3e88ff8f41d5 |
parent 42 | a179b74831c9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32\sfile\sf_pool.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "sf_pool.h" |
|
19 |
#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
20 |
#include "sf_notifier.h" |
|
21 |
#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
22 |
||
23 |
//=====CFsPool============================= |
|
24 |
||
25 |
template <class T> |
|
26 |
CFsPool<T>* CFsPool<T>::New(TInt aPoolSize) |
|
27 |
{ |
|
28 |
CFsPool<T>* pool = new CFsPool<T>(); |
|
29 |
if(!pool) |
|
30 |
return NULL; |
|
31 |
||
32 |
TInt r = pool->Construct(aPoolSize); |
|
33 |
if(r!=KErrNone) |
|
34 |
{ |
|
35 |
delete pool; |
|
36 |
return NULL; |
|
37 |
} |
|
38 |
else |
|
39 |
return pool; |
|
40 |
} |
|
41 |
||
42 |
||
43 |
template <class T> |
|
44 |
CFsPool<T>::CFsPool() |
|
45 |
{ |
|
46 |
} |
|
47 |
||
48 |
template <class T> |
|
49 |
TInt CFsPool<T>::Construct(TInt aPoolSize) |
|
50 |
{ |
|
51 |
TInt r = iPoolLock.CreateLocal(KNotificationPoolSize); |
|
52 |
if(r != KErrNone) |
|
53 |
return r; |
|
54 |
||
55 |
r = iFreeList.Reserve(KNotificationPoolSize); |
|
56 |
if(r != KErrNone) |
|
57 |
return r; |
|
58 |
||
59 |
TInt i = 0; |
|
60 |
while(i < aPoolSize) |
|
61 |
{ |
|
62 |
T* t = T::New(); |
|
63 |
if(!t) |
|
64 |
{ |
|
65 |
return KErrNoMemory; |
|
66 |
} |
|
42
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
r = iFreeList.Append(t); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
if(r != KErrNone) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
return r; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
} |
0 | 72 |
i++; |
73 |
} |
|
74 |
||
75 |
return KErrNone; |
|
76 |
} |
|
77 |
||
78 |
//This should only be called by the Manager when it holds |
|
79 |
//the manager's write lock meaning that all of the |
|
80 |
//blocks should be unallocated |
|
81 |
template <class T> |
|
82 |
CFsPool<T>::~CFsPool() |
|
83 |
{ |
|
84 |
for(TInt i=0; i < iFreeList.Count(); i++) |
|
85 |
{ |
|
86 |
delete iFreeList[i]; |
|
87 |
} |
|
88 |
iFreeList.Close(); |
|
89 |
} |
|
90 |
||
91 |
||
92 |
template <class T> |
|
93 |
T* CFsPool<T>::Allocate() |
|
94 |
{ |
|
95 |
Lock(); //Waits when there are no free blocks left |
|
96 |
||
97 |
TInt lastIndex = iFreeList.Count()-1; |
|
98 |
T* t = iFreeList[lastIndex]; |
|
99 |
iFreeList.Remove(lastIndex); |
|
100 |
||
101 |
return t; |
|
102 |
} |
|
103 |
||
104 |
template <class T> |
|
105 |
void CFsPool<T>::Free(T* aBlock) |
|
106 |
{ |
|
107 |
iFreeList.Append(aBlock); |
|
108 |
Unlock(); |
|
109 |
} |
|
110 |
||
111 |
template <class T> |
|
112 |
void CFsPool<T>::Lock() |
|
113 |
{ |
|
114 |
iPoolLock.Wait(); |
|
115 |
} |
|
116 |
||
117 |
template <class T> |
|
118 |
void CFsPool<T>::Unlock() |
|
119 |
{ |
|
120 |
iPoolLock.Signal(); |
|
121 |
} |
|
122 |
||
123 |
#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
124 |
//This is needed here because the compiler needs to know which types will be |
|
125 |
//instantiating the template (because it's in a separate file) |
|
126 |
template class CFsPool<CFsNotificationBlock>; |
|
127 |
#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION |
|
128 |