userlibandfileserver/fileserver/sfile/sf_pool.cpp
author Tom Cosgrove <tom.cosgrove@nokia.com>
Fri, 28 May 2010 16:29:07 +0100
changeset 30 8aab599e3476
parent 0 a41df078684a
child 42 a179b74831c9
permissions -rw-r--r--
Fix for bug 2283 (RVCT 4.0 support is missing from PDK 3.0.h) Have multiple extension sections in the bld.inf, one for each version of the compiler. The RVCT version building the tools will build the runtime libraries for its version, but make sure we extract all the other versions from zip archives. Also add the archive for RVCT4.

// 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 <class T>
CFsPool<T>* CFsPool<T>::New(TInt aPoolSize)
	{
	CFsPool<T>* pool = new CFsPool<T>();
	if(!pool)
		return NULL;
	
	TInt r = pool->Construct(aPoolSize);
	if(r!=KErrNone)
		{
		delete pool;
		return NULL;
		}
	else
		return pool;
	}


template <class T>
CFsPool<T>::CFsPool()
	{
	}

template <class T>
TInt CFsPool<T>::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 <class T>
CFsPool<T>::~CFsPool()
	{
	for(TInt i=0; i < iFreeList.Count(); i++)
		{
		delete iFreeList[i];
		}
	iFreeList.Close();
	}


template <class T>
T* CFsPool<T>::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 <class T>
void CFsPool<T>::Free(T* aBlock)
	{
	iFreeList.Append(aBlock);
	Unlock();
	}

template <class T>
void CFsPool<T>::Lock()
	{
	iPoolLock.Wait();
	}

template <class T>
void CFsPool<T>::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<CFsNotificationBlock>;
#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION