diff -r 000000000000 -r a41df078684a userlibandfileserver/fileserver/sfile/sf_pool.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/userlibandfileserver/fileserver/sfile/sf_pool.cpp Mon Oct 19 15:55:17 2009 +0100 @@ -0,0 +1,124 @@ +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// f32\sfile\sf_pool.cpp +// +// + +#include "sf_pool.h" +#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION +#include "sf_notifier.h" +#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION + +//=====CFsPool============================= + +template +CFsPool* CFsPool::New(TInt aPoolSize) + { + CFsPool* pool = new CFsPool(); + if(!pool) + return NULL; + + TInt r = pool->Construct(aPoolSize); + if(r!=KErrNone) + { + delete pool; + return NULL; + } + else + return pool; + } + + +template +CFsPool::CFsPool() + { + } + +template +TInt CFsPool::Construct(TInt aPoolSize) + { + TInt r = iPoolLock.CreateLocal(KNotificationPoolSize); + if(r != KErrNone) + return r; + + r = iFreeList.Reserve(KNotificationPoolSize); + if(r != KErrNone) + return r; + + TInt i = 0; + while(i < aPoolSize) + { + T* t = T::New(); + if(!t) + { + return KErrNoMemory; + } + iFreeList.Append(t); + i++; + } + + return KErrNone; + } + +//This should only be called by the Manager when it holds +//the manager's write lock meaning that all of the +//blocks should be unallocated +template +CFsPool::~CFsPool() + { + for(TInt i=0; i < iFreeList.Count(); i++) + { + delete iFreeList[i]; + } + iFreeList.Close(); + } + + +template +T* CFsPool::Allocate() + { + Lock(); //Waits when there are no free blocks left + + TInt lastIndex = iFreeList.Count()-1; + T* t = iFreeList[lastIndex]; + iFreeList.Remove(lastIndex); + + return t; + } + +template +void CFsPool::Free(T* aBlock) + { + iFreeList.Append(aBlock); + Unlock(); + } + +template +void CFsPool::Lock() + { + iPoolLock.Wait(); + } + +template +void CFsPool::Unlock() + { + iPoolLock.Signal(); + } + +#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION +//This is needed here because the compiler needs to know which types will be +//instantiating the template (because it's in a separate file) +template class CFsPool; +#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION +