Update contrib.
1 // Copyright (c) 1995-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.
14 // e32\include\nkern\nklib.h
16 // WARNING: This file contains some APIs which are internal and are subject
17 // to change without notice. Such APIs should therefore not be used
18 // outside the Kernel and Hardware Services package.
26 #ifndef __KERNEL_MODE__
27 #error Including kernel header in user code
30 #if defined(__GCC32__)
39 64-bit signed integer type.
41 typedef long long Int64;
50 64-bit unsigned integer type.
52 typedef unsigned long long Uint64;
57 #elif defined(__VC32__)
58 typedef __int64 Int64;
59 typedef unsigned __int64 Uint64;
60 #elif defined(__CW32__)
62 typedef long long Int64;
63 typedef unsigned long long Uint64;
73 Defines a 64-bit time value.
80 #if defined(__VC32__) || defined(__CW32__)
82 /** @internalComponent */
83 __NORETURN__ void abort();
86 #ifndef __PLACEMENT_NEW_INLINE
87 #define __PLACEMENT_NEW_INLINE
88 // Global placement operator new
89 /** @internalComponent */
90 inline TAny* operator new(TUint /*aSize*/, TAny* aBase) __NO_THROW
93 // Global placement operator delete
94 /** @internalComponent */
95 inline void operator delete(TAny* /*aPtr*/, TAny* /*aBase*/) __NO_THROW
97 #endif //__PLACEMENT_NEW_INLINE
99 #ifndef __PLACEMENT_VEC_NEW_INLINE
100 #define __PLACEMENT_VEC_NEW_INLINE
101 // Global placement operator new[]
102 /** @internalComponent */
103 inline TAny* operator new[](TUint /*aSize*/, TAny* aBase) __NO_THROW
106 // Global placement operator delete[]
107 /** @internalComponent */
108 inline void operator delete[](TAny* /*aPtr*/, TAny* /*aBase*/) __NO_THROW
110 #endif //__PLACEMENT_VEC_NEW_INLINE
113 Macro to offset a SDblQueLink pointer back to the base of a class containing it
117 #define _LOFF(p,T,f) ((T*)(((TUint8*)(p))-_FOFF(T,f)))
121 /** @internalComponent */
122 #define KILL_LINK_VALUE (SDblQueLink*)0xdfdfdfdf
124 /** @internalComponent */
125 #define KILL_LINK(l) (l)->iNext=(l)->iPrev=KILL_LINK_VALUE
135 #define FORCE_INLINE __forceinline
137 #define FORCE_INLINE inline
145 An object that forms part of a doubly linked list.
147 SDblQueLink can also be embedded within another object so that that object
148 can form part of the doubly linked list.
157 Default constructor; only defined for debug builds.
159 It initialises the link pointers.
161 FORCE_INLINE SDblQueLink() {iNext=iPrev=NULL;}
166 Removes this link item from the doubly linked list.
168 @return A pointer to this link item.
170 FORCE_INLINE SDblQueLink* Deque()
172 SDblQueLink* next = iNext;
173 SDblQueLink* prev = iPrev;
182 Inserts this link item into the list so that it precedes the specified link item.
184 @param aL A pointer to the link item which is to follow this link item.
186 FORCE_INLINE void InsertBefore(SDblQueLink* aL)
188 SDblQueLink* prev = aL->iPrev;
197 Inserts this link item into the list so that it follows the specified link item.
199 @param aL A pointer to the link item which is to precede this link item.
201 FORCE_INLINE void InsertAfter(SDblQueLink* aL)
203 SDblQueLink* next = aL->iNext;
212 Tests whether this is the only link item in the list.
214 @return True, if this is the only link item in the list; false, otherwise.
216 inline TBool Alone() const
217 { return (iNext==iPrev); }
221 Pointer to the next link item in the list.
226 Pointer to the previous link item in the list.
238 Anchor for a doubly linked list of SDblQueLink items.
249 FORCE_INLINE SDblQue()
250 { iA.iNext=iA.iPrev=&iA; }
254 Moves link items from the specified list onto this list, and clears the specified list
256 @param aQ The source linked list. This list must not be empty.
258 inline SDblQue(SDblQue* aQ, TInt) // move entries from aQ onto this queue and clear aQ - aQ must not be empty
259 { new (this) SDblQue(*aQ); iA.iNext->iPrev=&iA; iA.iPrev->iNext=&iA; new (aQ) SDblQue; }
263 Tests whether this doubly linked list is empty.
265 @return True, if the list is empty; false, otherwise.
267 FORCE_INLINE TBool IsEmpty() const
268 { return (iA.iNext==&iA); }
272 Gets a pointer to the first item in this doubly linked list.
274 @return A pointer to the first item.
276 FORCE_INLINE SDblQueLink* First() const
281 Gets a pointer to the last item in this doubly linked list.
283 @return A pointer to the last item.
285 FORCE_INLINE SDblQueLink* Last() const
290 Adds the specified link item onto the end of this doubly linked list.
292 @param aL A pointer to the link item to be added.
294 FORCE_INLINE void Add(SDblQueLink* aL)
296 SDblQueLink* prev = iA.iPrev;
305 Adds the specified link item onto the front of this doubly linked list.
307 @param aL A pointer to the link item to be added.
309 FORCE_INLINE void AddHead(SDblQueLink* aL)
311 SDblQueLink* next = iA.iNext;
320 Removes the last link item from the linked list and adds it to the front
324 { SDblQueLink* pL=iA.iPrev; pL->Deque(); AddHead(pL); }
328 Gets the first link item in the linked list.
330 @return The first link item in the list; NULL, if the list is empty.
332 inline SDblQueLink* GetFirst()
333 { if (IsEmpty()) return NULL; else return First()->Deque(); }
337 Gets the last link item in the linked list.
339 @return The last link item in the list; NULL, if the list is empty.
341 inline SDblQueLink* GetLast()
342 { if (IsEmpty()) return NULL; else return Last()->Deque(); }
346 Appends entries from the specified linked list onto this list, and clears
347 the specified link list anchor.
349 @param aQ The source linked list.
351 inline void MoveFrom(SDblQue* aQ) // append entries from aQ onto this queue and clear aQ
352 { if (!aQ->IsEmpty())
353 {iA.iPrev->iNext=aQ->iA.iNext; aQ->iA.iNext->iPrev=iA.iPrev; iA.iPrev=aQ->iA.iPrev; iA.iPrev->iNext=&iA; new (aQ) SDblQue; }
358 The anchor point for the doubly linked list.
370 An object that forms part of a doubly linked list arranged
371 in descending key order.
375 struct SOrdQueLink : public SDblQueLink
380 The key value used to order the link item.
392 Anchor for a doubly linked list of SOrdQueLink items.
394 The items in this linked list are in descending key order.
398 struct SOrdQue : public SDblQue
403 Adds the specified link item into this doubly linked list so that
404 the list remains in descending key order.
406 @param aL A pointer to the link item to be added.
408 inline void Add(SOrdQueLink* aL)
410 SOrdQueLink* pQ=(SOrdQueLink*)iA.iNext;
412 while(pQ!=&iA && (pQ->iKey>=k)) pQ=(SOrdQueLink*)pQ->iNext;
413 aL->InsertBefore(pQ);
424 An object that forms part of a doubly linked list arranged
427 The item represents some value that is an increment, or delta,
428 on the value represented by a preceding element.
432 struct SDeltaQueLink : public SDblQueLink
447 Anchor for a doubly linked list of SDeltaQueLink items.
449 An item in this linked list represents a value that is an increment,
450 or a delta, on the value represented by a preceding element.
451 The list is ordered so that the head of the queue represents a nominal zero point.
455 struct SDeltaQue : public SDblQue
460 Gets the delta value of the first link item in the list.
462 @return The delta value.
464 inline TInt FirstDelta() const
465 {return ((SDeltaQueLink*)First())->iDelta;}
469 Decrements the delta value of the first item in the list by the specified value.
471 @param aCount The amount by which the delta value is to be reduced.
473 @return True, if the resulting delta value is negative or zero;
474 false, if the value is positive.
476 inline TBool CountDown(TInt aCount)
477 {SDeltaQueLink& l=*(SDeltaQueLink*)First(); return((l.iDelta-=aCount)<=0);}
481 Adds the specified list item, having the specified 'distance' from
482 the nominal zero point, into the list.
484 The item is added into the list, the adjacent delta values are adjusted,
485 and a suitable delta value assigned to the new item so that
486 the new item is at the specified 'distance' from the nominal zero point.
488 @param aL The item to be inserted.
489 @param aDelta The 'distance' of the item from the nominal zero point.
491 inline void Add(SDeltaQueLink* aL, TInt aDelta)
493 SDeltaQueLink* pQ=(SDeltaQueLink*)iA.iNext;
494 while(pQ!=&iA && aDelta>=pQ->iDelta)
495 { aDelta-=pQ->iDelta; pQ=(SDeltaQueLink*)pQ->iNext; }
497 aL->InsertBefore(pQ);
498 if (pQ!=&iA) pQ->iDelta-=aDelta;
503 Removes the specified link item from the list.
505 The delta value of the item following the removed item is adjusted
506 so that its 'distance' from the nominal zero point remains the same.
508 @param aL The list item to be removed.
510 @return A pointer to the item removed from the queue.
512 inline SDeltaQueLink* Remove(SDeltaQueLink* aL)
516 SDeltaQueLink& next=*(SDeltaQueLink*)aL->iNext;
517 next.iDelta+=aL->iDelta;
519 return (SDeltaQueLink*)aL->Deque();
524 Removes the first item from the linked list if its delta value
527 @return A pointer to the item removed from the linked list.
528 This is NULL, if the first element has a positive delta value,
529 and has not been removed from the list.
531 inline SDeltaQueLink* RemoveFirst()
533 SDeltaQueLink& l=*(SDeltaQueLink*)First();
547 An object that forms part of a TPriList, priority ordered lists.
552 class TPriListLink : public SDblQueLink
560 Sets the priority value to zero.
562 inline TPriListLink() : iPriority(0) {}
568 Sets the priority to the specified value.
570 @param aPriority The priority value.
572 inline TPriListLink(TInt aPriority) : iPriority((TUint8)aPriority) {}
576 Tests whether this is a solitary link item.
578 @return True, if this is a solitary link item; false, otherwise.
580 inline TBool Alone() const
581 { return (iNext==(SDblQueLink*)this); }
590 Reserved for future use.
596 Reserved for future use.
602 Reserved for future use.
614 Base class for a TPriList, priority ordered lists.
622 IMPORT_C TPriListBase(TInt aNumPriorities);
623 IMPORT_C TInt HighestPriority();
624 IMPORT_C TPriListLink* First();
625 IMPORT_C void Add(TPriListLink* aLink);
626 IMPORT_C void AddHead(TPriListLink* aLink);
627 IMPORT_C void Remove(TPriListLink* aLink);
628 IMPORT_C void ChangePriority(TPriListLink* aLink, TInt aNewPriority);
631 Tests whether there are any non-empty lists.
633 @return True, if there are non-empty lists; false, if all lists are empty.
635 inline TBool NonEmpty() const
636 { return iPresent[0]|iPresent[1]; }
639 Tests whether there are any non-empty lists.
641 @return True, if all lists are empty
643 inline TBool IsEmpty() const
644 { return !iPresent[0] && !iPresent[1]; }
647 Tests whether any linked list with priority greater than p is non-empty.
649 @param p The priority value (0-63).
651 @return True, if any list with priority greater than p is non-empty; false, otherwise.
653 inline TBool operator>(TInt p) const
654 { return ((p<32) ? (iPresent[1] | (iPresent[0]>>p)>>1) : (iPresent[1]>>(p-32))>>1 ); }
658 64-bit mask to indicate which list is non-empty.
660 Bit n in the mask is set if and only if the linked list for priority n is non-empty.
669 Pointer to the first linked list.
671 SDblQueLink* iQueue[1];
677 template<class T, int n>
682 Anchor for a collection of doubly linked lists, where each list
683 corresponds to a priority value.
685 The lists are ordered by priority value, but items within
686 a list are in chronological order.
688 The number of lists is defined by the template integer parameter,
689 and each item in each list is of a class type defined by the template class parameter.
690 The number of lists must be between 1 and 64 inclusive.
694 class TPriList : public TPriListBase
700 inline TPriList() : TPriListBase(n) {}
704 Finds the highest priority item present on a priority list.
705 If multiple items at the same priority are present, return the first to be
706 added in chronological order.
708 @return a pointer to the item or NULL if the list is empty.
710 inline T* First() { return (T*)TPriListBase::First(); }
712 SDblQueLink* iExtraQueues[n-1];
717 /** Base for variant interface block
721 struct SInterfaceBlockBase
723 TUint32 iVer; // version number
724 TUint32 iSize; // size in bytes