diff -r 0ff24a8f6ca2 -r 98307c651589 perfsrv/memspy/Driver/Kernel/Source/MemSpyDriverObjectIx.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/perfsrv/memspy/Driver/Kernel/Source/MemSpyDriverObjectIx.cpp Mon Sep 06 15:00:47 2010 +0300 @@ -0,0 +1,228 @@ +/* +* 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 "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: +* +*/ + +#include "MemSpyDriverObjectIx.h" + +// System includes +#include +//#include + +//const TInt KObjectIxGranularity=8; +const TInt KObjectIndexMask=0x7fff; +//const TInt KObjectMaxIndex=0x7fff; +const TInt KObjectInstanceShift=16; +const TInt KObjectInstanceMask=0x3fff; +//const TInt KObjectIxMaxHandles=0x8000; + +inline TInt index(TInt aHandle) + {return(aHandle&KObjectIndexMask);} +inline TInt instance(TInt aHandle) + {return((aHandle>>KObjectInstanceShift)&KObjectInstanceMask);} +inline TInt instanceLimit(TInt& aCount) + {return ((aCount&KObjectInstanceMask)==0) ? ((++aCount)&KObjectInstanceMask) : aCount&KObjectInstanceMask;} +inline TInt makeHandle(TInt aIndex, TInt aInstance) + {return((TInt)((aInstance<HandleMutex); + } + +void DMemSpyObjectIx::Signal( DMemSpyObjectIx* aObjectIndex ) + { +// Kern::MutexSignal(*aObjectIndex->HandleMutex); + } +*/ + +/** Counts the number of times an object appears in this index. + + @param aObject Object whose occurrences are to be counted. + + @return Number of times aObject appears in the index. + + @pre Calling thread must be in a critical section. + @pre No fast mutex can be held. + @pre Call in a thread context. + @pre DObject::HandleMutex held + */ +TInt DMemSpyObjectIx::Count(DObject* aObject) + { + //Check preconditions(debug build only) + __ASSERT_CRITICAL; + __ASSERT_NO_FAST_MUTEX; + + TInt c=0; + if (iCount) + { + SDObjectIxRec* pS=iObjects; + SDObjectIxRec* pE=pS+iCount; + do + { + if (pS->obj==aObject) + c++; + } while (++pS=iCount) + return(NULL); + SDObjectIxRec *pS=iObjects+i; + if (pS->str.instance!=instance(aHandle) || pS->str.uniqueID!=aUniqueID) + return(NULL); + return(pS->obj); + } + + +/** Looks up an object in the index by handle. + + The object may be of any type. + + @param aHandle Handle to look up. + + @return Pointer to object or NULL if handle invalid. + + @pre Call in a thread context. + @pre System lock must be held. + */ +DObject* DMemSpyObjectIx::At(TInt aHandle) + { + __ASSERT_SYSTEM_LOCK; //Check preconditions (debug build only) + TInt i=index(aHandle); + if (i>=iCount) + return NULL; + SDObjectIxRec *pS=iObjects+i; + if (pS->str.instance!=instance(aHandle)) + return NULL; + return pS->obj; + } + +/** Finds the object at a specific position in the index array. + + @param aIndex Index into array. + + @return Pointer to the object at that position (could be NULL). + + @pre Call in a thread context. + @pre System lock must be held. + */ +DObject* DMemSpyObjectIx::operator[](TInt aIndex) + { + __ASSERT_SYSTEM_LOCK; //Check preconditions (debug build only) + __ASSERT_ALWAYS(aIndex>=0 && aIndex