os/kernelhwsrv/kernel/eka/include/kernel/smap.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 // e32\include\kernel\smap.h
    15 
    16 #ifndef SMAP_H
    17 #define SMAP_H
    18 
    19 class DMutex;
    20 
    21 /**
    22 	@file
    23 	@internalComponent
    24 	@prototype
    25 */
    26 
    27 /**
    28    SMap uses a binary search to perform quick lookups (finds) whilst Add and
    29    Remove and Iterating is happening concurrently. This container is optimised
    30    for fast lookups.
    31 
    32    Add, Remove and Iterator check that the caller has the heavy wait Mutex lock
    33    held.
    34 
    35    Find methods use the fast lock whilst performing look ups.
    36  */
    37 
    38 class SMap
    39 	{
    40 public:
    41 	SMap(NFastMutex* aFastLock, DMutex* aSlowLock);
    42 	~SMap();
    43 
    44 	TInt Add(TUint aKey, TAny* aObject);
    45 	TAny* Remove(TUint aKey);
    46 	TAny* Find(TUint aKey);
    47 
    48 	FORCE_INLINE TUint Count()
    49 		{
    50 		return iCount;
    51 		}
    52 
    53 	class TEntry
    54 		{
    55 	public:
    56 		TUint	iKey;
    57 		TAny*	iObj;
    58 		};
    59 
    60 	/**
    61 	   An iterator index.
    62 	*/
    63 
    64 	class TIterator
    65 		{
    66 	public:
    67 		FORCE_INLINE TIterator(SMap& aMap) : iMap(aMap), iPos(0)
    68 			{
    69 			}
    70 
    71 		void Reset();
    72 
    73 		TEntry* Next();
    74 
    75 	private:
    76 		SMap& iMap;
    77 		TUint iPos;
    78 		TInt iSpare1;
    79 		};
    80 private:
    81 	FORCE_INLINE void FastLock()
    82 		{
    83 	    NKern::FMWait(iFastLock);
    84 		}
    85 
    86 	FORCE_INLINE void FastUnlock()
    87 		{
    88 	    NKern::FMSignal(iFastLock);
    89 		}
    90 
    91 	TUint FindIndex(TUint aKey);
    92 
    93 private:
    94 	TUint iCount;
    95 	TEntry* iList;
    96 	NFastMutex* iFastLock;
    97 	DMutex* iSlowLock;
    98 	TInt iSpare1;
    99 
   100 	friend class TIterator;
   101 	};
   102 
   103 
   104 
   105 #endif // SMAP_H