Update contrib.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 A container for storing objects keyed on a virtual address.
22 class RAddressedContainer
26 @param aReadLock Fast mutex used to synchronise read operations,
27 i.e. the Find functions. This may be the null pointer to
28 indicate that extra locking is required.
29 @param aWriteLock Reference to the mutex used to synchronise write operations,
30 i.e. #Add and Remove functions. This mutex if not used by
31 the RAddressedContainer class but it is used for asserting
32 correct preconditions in debug builds
34 RAddressedContainer(NFastMutex* aReadLock, DMutex*& aWriteLock);
36 ~RAddressedContainer();
39 Add an object to the container.
41 @param aAddress The address key for the object.
42 @param aObject Pointer to the object to add. This may not be the null pointer.
44 @pre The write lock must be held.
46 TInt Add(TLinAddr aAddress, TAny* aObject);
49 Remove an object from the container.
51 @param aAddress The address key for the object.
53 @return The pointer of the object removed, or the null pointer if there
54 was none with the specified address key.
56 @pre The write lock must be held.
58 TAny* Remove(TLinAddr aAddress);
61 Find an object in the container.
63 @param aAddress The address key for the object.
65 @return The pointer of the object found, or the null pointer if there
66 was none with the specified address key.
68 @pre The read lock must be held, or if there is no read lock, the write lock must be held.
70 TAny* Find(TLinAddr aAddress);
73 Find the object in the container which has the highest value
74 address key less-than-or-equal to the specified address.
76 @param aAddress The address key to search on.
78 @param[out] aOffset Reference to an value which will be set to the difference
79 between \a aAddress and the address key of the found object.
81 @return The pointer of the object found, or the null pointer if there
82 was none matching the search criteria.
84 @pre The read lock must be held, or if there is no read lock, the write lock must be held.
86 TAny* Find(TLinAddr aAddress, TUint& aOffset);
88 /** Acquire the read lock. */
89 FORCE_INLINE void ReadLock()
92 NKern::FMWait(iReadLock);
95 /** Release the read lock. */
96 FORCE_INLINE void ReadUnlock()
99 NKern::FMSignal(iReadLock);
102 /** Flash (release and re-acquire) the read lock. */
103 FORCE_INLINE void ReadFlash()
106 NKern::FMFlash(iReadLock);
109 /** The number of objects in the container. */
110 FORCE_INLINE TUint Count()
115 TUint FindIndex(TLinAddr aAddress);
116 TUint CalculateGrow();
117 TUint CalculateShrink(TUint aCount);
118 TBool CheckWriteLock();
130 NFastMutex* iReadLock;
134 #endif // MADDRCONT_H