os/kernelhwsrv/kernel/eka/include/nkern/nklib.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\include\nkern\nklib.h
sl@0
    15
// 
sl@0
    16
// WARNING: This file contains some APIs which are internal and are subject
sl@0
    17
//          to change without notice. Such APIs should therefore not be used
sl@0
    18
//          outside the Kernel and Hardware Services package.
sl@0
    19
//
sl@0
    20
sl@0
    21
#ifndef __NKLIB_H__
sl@0
    22
#define __NKLIB_H__
sl@0
    23
#include <e32err.h>
sl@0
    24
#include <nk_cpu.h>
sl@0
    25
sl@0
    26
#ifndef __KERNEL_MODE__
sl@0
    27
#error Including kernel header in user code
sl@0
    28
#endif
sl@0
    29
sl@0
    30
#if defined(__GCC32__)
sl@0
    31
sl@0
    32
sl@0
    33
sl@0
    34
sl@0
    35
/**
sl@0
    36
@publishedPartner
sl@0
    37
@released
sl@0
    38
sl@0
    39
64-bit signed integer type.
sl@0
    40
*/
sl@0
    41
typedef long long Int64;
sl@0
    42
sl@0
    43
sl@0
    44
sl@0
    45
sl@0
    46
/**
sl@0
    47
@publishedPartner
sl@0
    48
@released
sl@0
    49
	
sl@0
    50
64-bit unsigned integer type.	
sl@0
    51
*/
sl@0
    52
typedef unsigned long long Uint64;
sl@0
    53
sl@0
    54
sl@0
    55
sl@0
    56
sl@0
    57
#elif defined(__VC32__)
sl@0
    58
typedef __int64 Int64;
sl@0
    59
typedef unsigned __int64 Uint64;
sl@0
    60
#elif defined(__CW32__)
sl@0
    61
#pragma longlong on
sl@0
    62
typedef long long Int64;
sl@0
    63
typedef unsigned long long Uint64;
sl@0
    64
#endif
sl@0
    65
sl@0
    66
sl@0
    67
sl@0
    68
sl@0
    69
/**
sl@0
    70
@publishedPartner
sl@0
    71
@released
sl@0
    72
	
sl@0
    73
Defines a 64-bit time value. 
sl@0
    74
*/
sl@0
    75
typedef Int64 TTimeK;
sl@0
    76
sl@0
    77
sl@0
    78
sl@0
    79
sl@0
    80
#if defined(__VC32__) || defined(__CW32__)
sl@0
    81
extern "C"
sl@0
    82
/** @internalComponent */
sl@0
    83
__NORETURN__ void abort();
sl@0
    84
#endif
sl@0
    85
sl@0
    86
#ifndef __PLACEMENT_NEW_INLINE
sl@0
    87
#define __PLACEMENT_NEW_INLINE
sl@0
    88
// Global placement operator new
sl@0
    89
/** @internalComponent */
sl@0
    90
inline TAny* operator new(TUint /*aSize*/, TAny* aBase) __NO_THROW
sl@0
    91
	{return aBase;}
sl@0
    92
sl@0
    93
// Global placement operator delete
sl@0
    94
/** @internalComponent */
sl@0
    95
inline void operator delete(TAny* /*aPtr*/, TAny* /*aBase*/) __NO_THROW
sl@0
    96
	{}
sl@0
    97
#endif //__PLACEMENT_NEW_INLINE
sl@0
    98
sl@0
    99
#ifndef __PLACEMENT_VEC_NEW_INLINE
sl@0
   100
#define __PLACEMENT_VEC_NEW_INLINE
sl@0
   101
// Global placement operator new[]
sl@0
   102
/** @internalComponent */
sl@0
   103
inline TAny* operator new[](TUint /*aSize*/, TAny* aBase) __NO_THROW
sl@0
   104
	{return aBase;}
sl@0
   105
sl@0
   106
// Global placement operator delete[]
sl@0
   107
/** @internalComponent */
sl@0
   108
inline void operator delete[](TAny* /*aPtr*/, TAny* /*aBase*/) __NO_THROW
sl@0
   109
	{}
sl@0
   110
#endif //__PLACEMENT_VEC_NEW_INLINE
sl@0
   111
sl@0
   112
/**
sl@0
   113
	Macro to offset a SDblQueLink pointer back to the base of a class containing it
sl@0
   114
	@publishedPartner
sl@0
   115
	@released
sl@0
   116
*/
sl@0
   117
#define _LOFF(p,T,f) ((T*)(((TUint8*)(p))-_FOFF(T,f)))
sl@0
   118
sl@0
   119
#ifdef _DEBUG
sl@0
   120
sl@0
   121
/** @internalComponent */
sl@0
   122
#define KILL_LINK_VALUE (SDblQueLink*)0xdfdfdfdf
sl@0
   123
sl@0
   124
/** @internalComponent */
sl@0
   125
#define KILL_LINK(l)	(l)->iNext=(l)->iPrev=KILL_LINK_VALUE
sl@0
   126
sl@0
   127
#else
sl@0
   128
sl@0
   129
#define KILL_LINK(l)
sl@0
   130
sl@0
   131
#endif
sl@0
   132
sl@0
   133
sl@0
   134
#ifdef __ARMCC__
sl@0
   135
#define FORCE_INLINE __forceinline
sl@0
   136
#else
sl@0
   137
#define FORCE_INLINE inline
sl@0
   138
#endif
sl@0
   139
sl@0
   140
sl@0
   141
/**
sl@0
   142
@publishedPartner
sl@0
   143
@released
sl@0
   144
sl@0
   145
An object that forms part of a doubly linked list.
sl@0
   146
sl@0
   147
SDblQueLink can also be embedded within another object so that that object
sl@0
   148
can form part of the doubly linked list.
sl@0
   149
sl@0
   150
@see SDblQue
sl@0
   151
*/
sl@0
   152
struct SDblQueLink
sl@0
   153
	{
sl@0
   154
	
sl@0
   155
#ifdef _DEBUG
sl@0
   156
    /**
sl@0
   157
    Default constructor; only defined for debug builds.
sl@0
   158
    
sl@0
   159
    It initialises the link pointers.
sl@0
   160
    */
sl@0
   161
	FORCE_INLINE SDblQueLink() {iNext=iPrev=NULL;}
sl@0
   162
#endif
sl@0
   163
sl@0
   164
sl@0
   165
    /**
sl@0
   166
    Removes this link item from the doubly linked list.
sl@0
   167
    
sl@0
   168
    @return A pointer to this link item.
sl@0
   169
    */
sl@0
   170
	FORCE_INLINE SDblQueLink* Deque()
sl@0
   171
		{
sl@0
   172
		SDblQueLink* next = iNext;
sl@0
   173
		SDblQueLink* prev = iPrev;
sl@0
   174
		next->iPrev=prev;
sl@0
   175
		prev->iNext=next;
sl@0
   176
		KILL_LINK(this);
sl@0
   177
		return this;
sl@0
   178
		}
sl@0
   179
sl@0
   180
sl@0
   181
    /**
sl@0
   182
    Inserts this link item into the list so that it precedes the specified link item.
sl@0
   183
    
sl@0
   184
    @param aL A pointer to the link item which is to follow this link item.
sl@0
   185
    */
sl@0
   186
	FORCE_INLINE void InsertBefore(SDblQueLink* aL)
sl@0
   187
		{
sl@0
   188
		SDblQueLink* prev = aL->iPrev;
sl@0
   189
		iNext=aL;
sl@0
   190
		iPrev=prev;
sl@0
   191
		prev->iNext=this;
sl@0
   192
		aL->iPrev=this;
sl@0
   193
		}
sl@0
   194
	
sl@0
   195
		
sl@0
   196
	/**
sl@0
   197
	Inserts this link item into the list so that it follows the specified link item.
sl@0
   198
    
sl@0
   199
    @param aL A pointer to the link item which is to precede this link item.
sl@0
   200
    */
sl@0
   201
	FORCE_INLINE void InsertAfter(SDblQueLink* aL)
sl@0
   202
		{
sl@0
   203
		SDblQueLink* next = aL->iNext;
sl@0
   204
		iPrev=aL;
sl@0
   205
		iNext=next;
sl@0
   206
		next->iPrev=this;
sl@0
   207
		aL->iNext=this;
sl@0
   208
		}
sl@0
   209
	
sl@0
   210
	
sl@0
   211
	/**
sl@0
   212
	Tests whether this is the only link item in the list.
sl@0
   213
	
sl@0
   214
	@return True, if this is the only link item in the list; false, otherwise.
sl@0
   215
    */
sl@0
   216
	inline TBool Alone() const
sl@0
   217
		{ return (iNext==iPrev); }
sl@0
   218
    
sl@0
   219
    
sl@0
   220
    /**
sl@0
   221
    Pointer to the next link item in the list.
sl@0
   222
    */
sl@0
   223
	SDblQueLink* iNext;
sl@0
   224
	
sl@0
   225
	/**
sl@0
   226
    Pointer to the previous link item in the list.
sl@0
   227
    */
sl@0
   228
	SDblQueLink* iPrev;
sl@0
   229
	};
sl@0
   230
sl@0
   231
sl@0
   232
sl@0
   233
sl@0
   234
/**
sl@0
   235
@publishedPartner
sl@0
   236
@released
sl@0
   237
sl@0
   238
Anchor for a doubly linked list of SDblQueLink items.
sl@0
   239
sl@0
   240
@see SDblQueLink
sl@0
   241
*/
sl@0
   242
struct SDblQue
sl@0
   243
	{
sl@0
   244
	
sl@0
   245
	
sl@0
   246
	/**
sl@0
   247
	Default constructor.
sl@0
   248
	*/
sl@0
   249
	FORCE_INLINE SDblQue()
sl@0
   250
		{ iA.iNext=iA.iPrev=&iA; }
sl@0
   251
		
sl@0
   252
	
sl@0
   253
	/**
sl@0
   254
	Moves link items from the specified list onto this list, and clears the specified list
sl@0
   255
	
sl@0
   256
	@param aQ The source linked list. This list must not be empty.
sl@0
   257
	*/	
sl@0
   258
	inline SDblQue(SDblQue* aQ, TInt)		// move entries from aQ onto this queue and clear aQ - aQ must not be empty
sl@0
   259
		{ new (this) SDblQue(*aQ); iA.iNext->iPrev=&iA; iA.iPrev->iNext=&iA; new (aQ) SDblQue; }
sl@0
   260
		
sl@0
   261
		
sl@0
   262
	/**
sl@0
   263
	Tests whether this doubly linked list is empty.
sl@0
   264
	
sl@0
   265
	@return True, if the list is empty; false, otherwise.
sl@0
   266
	*/
sl@0
   267
	FORCE_INLINE TBool IsEmpty() const
sl@0
   268
		{ return (iA.iNext==&iA); }
sl@0
   269
	
sl@0
   270
		
sl@0
   271
    /**
sl@0
   272
    Gets a pointer to the first item in this doubly linked list.
sl@0
   273
    
sl@0
   274
    @return A pointer to the first item.
sl@0
   275
    */		
sl@0
   276
	FORCE_INLINE SDblQueLink* First() const
sl@0
   277
		{ return iA.iNext; }
sl@0
   278
	
sl@0
   279
		
sl@0
   280
    /**
sl@0
   281
    Gets a pointer to the last item in this doubly linked list.
sl@0
   282
    
sl@0
   283
    @return A pointer to the last item.
sl@0
   284
    */		
sl@0
   285
	FORCE_INLINE SDblQueLink* Last() const
sl@0
   286
		{ return iA.iPrev; }
sl@0
   287
	
sl@0
   288
		
sl@0
   289
	/**
sl@0
   290
	Adds the specified link item onto the end of this doubly linked list.
sl@0
   291
	
sl@0
   292
	@param aL A pointer to the link item to be added.
sl@0
   293
	*/
sl@0
   294
	FORCE_INLINE void Add(SDblQueLink* aL)
sl@0
   295
		{
sl@0
   296
		SDblQueLink* prev = iA.iPrev;
sl@0
   297
		aL->iNext=&iA;
sl@0
   298
		aL->iPrev=prev;
sl@0
   299
		prev->iNext=aL;
sl@0
   300
		iA.iPrev=aL;
sl@0
   301
		}
sl@0
   302
	
sl@0
   303
		
sl@0
   304
	/**
sl@0
   305
	Adds the specified link item onto the front of this doubly linked list.
sl@0
   306
	
sl@0
   307
	@param aL A pointer to the link item to be added.
sl@0
   308
	*/
sl@0
   309
	FORCE_INLINE void AddHead(SDblQueLink* aL)
sl@0
   310
		{
sl@0
   311
		SDblQueLink* next = iA.iNext;
sl@0
   312
		aL->iNext=next;
sl@0
   313
		aL->iPrev=&iA;
sl@0
   314
		next->iPrev=aL;
sl@0
   315
		iA.iNext=aL;
sl@0
   316
		}
sl@0
   317
	
sl@0
   318
		
sl@0
   319
	/**
sl@0
   320
    Removes the last link item from the linked list and adds it to the front
sl@0
   321
    of the list. 
sl@0
   322
	*/
sl@0
   323
	inline void Rotate()
sl@0
   324
		{ SDblQueLink* pL=iA.iPrev; pL->Deque(); AddHead(pL); }
sl@0
   325
		
sl@0
   326
		
sl@0
   327
	/**
sl@0
   328
	Gets the first link item in the linked list.
sl@0
   329
	
sl@0
   330
	@return The first link item in the list; NULL, if the list is empty.
sl@0
   331
	*/
sl@0
   332
	inline SDblQueLink* GetFirst()
sl@0
   333
		{ if (IsEmpty()) return NULL; else return First()->Deque(); }
sl@0
   334
sl@0
   335
sl@0
   336
	/**
sl@0
   337
	Gets the last link item in the linked list.
sl@0
   338
	
sl@0
   339
	@return The last link item in the list; NULL, if the list is empty.
sl@0
   340
	*/
sl@0
   341
	inline SDblQueLink* GetLast()
sl@0
   342
		{ if (IsEmpty()) return NULL; else return Last()->Deque(); }
sl@0
   343
sl@0
   344
sl@0
   345
	/**
sl@0
   346
	Appends entries from the specified linked list onto this list, and clears
sl@0
   347
	the specified link list anchor.
sl@0
   348
	
sl@0
   349
	@param aQ The source linked list.
sl@0
   350
	*/
sl@0
   351
	inline void MoveFrom(SDblQue* aQ)	// append entries from aQ onto this queue and clear aQ
sl@0
   352
		{ if (!aQ->IsEmpty())
sl@0
   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; }
sl@0
   354
		}
sl@0
   355
sl@0
   356
sl@0
   357
    /**
sl@0
   358
    The anchor point for the doubly linked list.
sl@0
   359
    */
sl@0
   360
	SDblQueLink iA;
sl@0
   361
	};
sl@0
   362
sl@0
   363
sl@0
   364
sl@0
   365
sl@0
   366
/**
sl@0
   367
@publishedPartner
sl@0
   368
@released
sl@0
   369
sl@0
   370
An object that forms part of a doubly linked list arranged
sl@0
   371
in descending key order.
sl@0
   372
sl@0
   373
@see SOrdQue
sl@0
   374
*/
sl@0
   375
struct SOrdQueLink : public SDblQueLink
sl@0
   376
	{
sl@0
   377
	
sl@0
   378
	
sl@0
   379
	/**
sl@0
   380
	The key value used to order the link item.
sl@0
   381
	*/
sl@0
   382
	TInt iKey;
sl@0
   383
	};
sl@0
   384
sl@0
   385
sl@0
   386
sl@0
   387
sl@0
   388
/**
sl@0
   389
@publishedPartner
sl@0
   390
@released
sl@0
   391
sl@0
   392
Anchor for a doubly linked list of SOrdQueLink items.
sl@0
   393
sl@0
   394
The items in this linked list are in descending key order.
sl@0
   395
sl@0
   396
@see SOrdQueLink
sl@0
   397
*/
sl@0
   398
struct SOrdQue : public SDblQue
sl@0
   399
	{
sl@0
   400
	
sl@0
   401
	
sl@0
   402
	/**
sl@0
   403
	Adds the specified link item into this doubly linked list so that
sl@0
   404
	the list remains in descending key order.
sl@0
   405
	
sl@0
   406
	@param aL A pointer to the link item to be added.
sl@0
   407
	*/
sl@0
   408
	inline void Add(SOrdQueLink* aL)
sl@0
   409
		{
sl@0
   410
		SOrdQueLink* pQ=(SOrdQueLink*)iA.iNext;
sl@0
   411
		TInt k=aL->iKey;
sl@0
   412
		while(pQ!=&iA && (pQ->iKey>=k)) pQ=(SOrdQueLink*)pQ->iNext;
sl@0
   413
		aL->InsertBefore(pQ);
sl@0
   414
		}
sl@0
   415
	};
sl@0
   416
sl@0
   417
sl@0
   418
sl@0
   419
sl@0
   420
/**
sl@0
   421
@publishedPartner
sl@0
   422
@released
sl@0
   423
sl@0
   424
An object that forms part of a doubly linked list arranged
sl@0
   425
in 'delta' order.
sl@0
   426
sl@0
   427
The item represents some value that is an increment, or delta,
sl@0
   428
on the value represented by a preceding element.
sl@0
   429
sl@0
   430
@see SDeltaQue
sl@0
   431
*/
sl@0
   432
struct SDeltaQueLink : public SDblQueLink
sl@0
   433
	{
sl@0
   434
	/**
sl@0
   435
	The delta value.
sl@0
   436
	*/
sl@0
   437
	TInt iDelta;
sl@0
   438
	};
sl@0
   439
sl@0
   440
sl@0
   441
sl@0
   442
sl@0
   443
/**
sl@0
   444
@publishedPartner
sl@0
   445
@released
sl@0
   446
sl@0
   447
Anchor for a doubly linked list of SDeltaQueLink items.
sl@0
   448
sl@0
   449
An item in this linked list represents a value that is an increment,
sl@0
   450
or a delta, on the value represented by a preceding element.
sl@0
   451
The list is ordered so that the head of the queue represents a nominal zero point.
sl@0
   452
sl@0
   453
@see SDeltaQueLink
sl@0
   454
*/
sl@0
   455
struct SDeltaQue : public SDblQue
sl@0
   456
	{
sl@0
   457
	
sl@0
   458
	
sl@0
   459
	/**
sl@0
   460
	Gets the delta value of the first link item in the list.
sl@0
   461
sl@0
   462
    @return The delta value.
sl@0
   463
	*/
sl@0
   464
	inline TInt FirstDelta() const
sl@0
   465
		{return ((SDeltaQueLink*)First())->iDelta;}
sl@0
   466
		
sl@0
   467
		
sl@0
   468
    /**
sl@0
   469
    Decrements the delta value of the first item in the list by the specified value.
sl@0
   470
sl@0
   471
    @param aCount The amount by which the delta value is to be reduced.
sl@0
   472
sl@0
   473
    @return True, if the resulting delta value is negative or zero;
sl@0
   474
            false, if the value is positive.
sl@0
   475
    */		
sl@0
   476
	inline TBool CountDown(TInt aCount)
sl@0
   477
		{SDeltaQueLink& l=*(SDeltaQueLink*)First(); return((l.iDelta-=aCount)<=0);}
sl@0
   478
		
sl@0
   479
	
sl@0
   480
	/**
sl@0
   481
	Adds the specified list item, having the specified 'distance' from
sl@0
   482
	the nominal zero point, into the list.
sl@0
   483
sl@0
   484
    The item is added into the list, the adjacent delta values are adjusted,
sl@0
   485
    and a suitable delta value assigned to the new item so that
sl@0
   486
    the new item is at the specified 'distance' from the nominal zero point.
sl@0
   487
sl@0
   488
    @param aL     The item to be inserted. 
sl@0
   489
    @param aDelta The 'distance' of the item from the nominal zero point.
sl@0
   490
	*/
sl@0
   491
	inline void Add(SDeltaQueLink* aL, TInt aDelta)
sl@0
   492
		{
sl@0
   493
		SDeltaQueLink* pQ=(SDeltaQueLink*)iA.iNext;
sl@0
   494
		while(pQ!=&iA && aDelta>=pQ->iDelta)
sl@0
   495
			{ aDelta-=pQ->iDelta; pQ=(SDeltaQueLink*)pQ->iNext; }
sl@0
   496
		aL->iDelta=aDelta;
sl@0
   497
		aL->InsertBefore(pQ);
sl@0
   498
		if (pQ!=&iA) pQ->iDelta-=aDelta;
sl@0
   499
		}
sl@0
   500
				
sl@0
   501
		
sl@0
   502
	/**
sl@0
   503
	Removes the specified link item from the list.
sl@0
   504
	
sl@0
   505
	The delta value of the item following the removed item is adjusted
sl@0
   506
	so that its 'distance' from the nominal zero point remains the same.
sl@0
   507
	
sl@0
   508
	@param aL The list item to be removed.
sl@0
   509
	
sl@0
   510
	@return A pointer to the item removed from the queue.
sl@0
   511
	*/
sl@0
   512
	inline SDeltaQueLink* Remove(SDeltaQueLink* aL)
sl@0
   513
		{
sl@0
   514
		if (aL->iNext!=&iA)
sl@0
   515
			{
sl@0
   516
			SDeltaQueLink& next=*(SDeltaQueLink*)aL->iNext;
sl@0
   517
			next.iDelta+=aL->iDelta;
sl@0
   518
			}
sl@0
   519
		return (SDeltaQueLink*)aL->Deque();
sl@0
   520
		}
sl@0
   521
		
sl@0
   522
		
sl@0
   523
    /**
sl@0
   524
    Removes the first item from the linked list if its delta value
sl@0
   525
    is zero or negative.
sl@0
   526
    
sl@0
   527
    @return A pointer to the item removed from the linked list.
sl@0
   528
            This is NULL, if the first element has a positive delta value,
sl@0
   529
            and has not been removed from the list.
sl@0
   530
    */		
sl@0
   531
	inline SDeltaQueLink* RemoveFirst()
sl@0
   532
		{
sl@0
   533
		SDeltaQueLink& l=*(SDeltaQueLink*)First();
sl@0
   534
		if (l.iDelta<=0)
sl@0
   535
			return Remove(&l);
sl@0
   536
		return NULL;
sl@0
   537
		}
sl@0
   538
	};
sl@0
   539
sl@0
   540
sl@0
   541
sl@0
   542
sl@0
   543
/**
sl@0
   544
@publishedPartner
sl@0
   545
@released
sl@0
   546
sl@0
   547
An object that forms part of a TPriList, priority ordered lists.
sl@0
   548
sl@0
   549
@see TPriListBase
sl@0
   550
@see TPriList
sl@0
   551
*/
sl@0
   552
class TPriListLink : public SDblQueLink
sl@0
   553
	{
sl@0
   554
public:
sl@0
   555
sl@0
   556
    
sl@0
   557
    /**
sl@0
   558
    Default constructor.
sl@0
   559
    
sl@0
   560
    Sets the priority value to zero.
sl@0
   561
    */
sl@0
   562
	inline TPriListLink() : iPriority(0) {}
sl@0
   563
	
sl@0
   564
	
sl@0
   565
    /**
sl@0
   566
    Constructor.
sl@0
   567
    
sl@0
   568
    Sets the priority to the specified value.
sl@0
   569
    
sl@0
   570
    @param aPriority The priority value.
sl@0
   571
    */
sl@0
   572
	inline TPriListLink(TInt aPriority) : iPriority((TUint8)aPriority) {}
sl@0
   573
	
sl@0
   574
	
sl@0
   575
	/**
sl@0
   576
	Tests whether this is a solitary link item.
sl@0
   577
	
sl@0
   578
	@return True, if this is a solitary link item; false, otherwise. 
sl@0
   579
	*/
sl@0
   580
	inline TBool Alone() const
sl@0
   581
		{ return (iNext==(SDblQueLink*)this); }
sl@0
   582
public:
sl@0
   583
sl@0
   584
    /** 
sl@0
   585
    The priority value.
sl@0
   586
    */
sl@0
   587
	TUint8 iPriority;
sl@0
   588
	
sl@0
   589
	/**
sl@0
   590
	Reserved for future use.
sl@0
   591
	*/
sl@0
   592
	TUint8 iSpare1;
sl@0
   593
	
sl@0
   594
		
sl@0
   595
	/**
sl@0
   596
	Reserved for future use.
sl@0
   597
	*/
sl@0
   598
	TUint8 iSpare2;
sl@0
   599
	
sl@0
   600
		
sl@0
   601
	/**
sl@0
   602
	Reserved for future use.
sl@0
   603
	*/
sl@0
   604
	TUint8 iSpare3;
sl@0
   605
	};
sl@0
   606
sl@0
   607
sl@0
   608
sl@0
   609
sl@0
   610
/**
sl@0
   611
@publishedPartner
sl@0
   612
@released
sl@0
   613
sl@0
   614
Base class for a TPriList, priority ordered lists.
sl@0
   615
sl@0
   616
@see TPriListLink
sl@0
   617
@see TPriList
sl@0
   618
*/
sl@0
   619
class TPriListBase
sl@0
   620
	{
sl@0
   621
public:
sl@0
   622
	IMPORT_C TPriListBase(TInt aNumPriorities);
sl@0
   623
	IMPORT_C TInt HighestPriority();
sl@0
   624
	IMPORT_C TPriListLink* First();
sl@0
   625
	IMPORT_C void Add(TPriListLink* aLink);
sl@0
   626
	IMPORT_C void AddHead(TPriListLink* aLink);
sl@0
   627
	IMPORT_C void Remove(TPriListLink* aLink);
sl@0
   628
	IMPORT_C void ChangePriority(TPriListLink* aLink, TInt aNewPriority);
sl@0
   629
	
sl@0
   630
	/**
sl@0
   631
	Tests whether there are any non-empty lists.
sl@0
   632
		
sl@0
   633
	@return True, if there are non-empty lists; false, if all lists are empty.
sl@0
   634
	*/
sl@0
   635
	inline TBool NonEmpty() const
sl@0
   636
		{ return iPresent[0]|iPresent[1]; }
sl@0
   637
		
sl@0
   638
	/**
sl@0
   639
	Tests whether there are any non-empty lists.
sl@0
   640
		
sl@0
   641
	@return True, if all lists are empty
sl@0
   642
	*/
sl@0
   643
	inline TBool IsEmpty() const
sl@0
   644
		{ return !iPresent[0] && !iPresent[1]; }
sl@0
   645
		
sl@0
   646
	/**
sl@0
   647
	Tests whether any linked list with priority greater than p is non-empty.
sl@0
   648
sl@0
   649
	@param p The priority value (0-63).
sl@0
   650
sl@0
   651
	@return True, if any list with priority greater than p is non-empty; false, otherwise.	
sl@0
   652
	*/
sl@0
   653
	inline TBool operator>(TInt p) const
sl@0
   654
		{ return ((p<32) ? (iPresent[1] | (iPresent[0]>>p)>>1) : (iPresent[1]>>(p-32))>>1 ); }
sl@0
   655
public:
sl@0
   656
sl@0
   657
    /**
sl@0
   658
    64-bit mask to indicate which list is non-empty.
sl@0
   659
sl@0
   660
    Bit n in the mask is set if and only if the linked list for priority n is non-empty.
sl@0
   661
    */
sl@0
   662
	union
sl@0
   663
		{
sl@0
   664
		TUint iPresent[2];
sl@0
   665
		TUint64 iPresent64;
sl@0
   666
		};
sl@0
   667
	
sl@0
   668
	/**
sl@0
   669
	Pointer to the first linked list.
sl@0
   670
	*/
sl@0
   671
	SDblQueLink* iQueue[1];
sl@0
   672
	};
sl@0
   673
sl@0
   674
sl@0
   675
sl@0
   676
sl@0
   677
template<class T, int n>
sl@0
   678
/**
sl@0
   679
@publishedPartner
sl@0
   680
@released
sl@0
   681
sl@0
   682
Anchor for a collection of doubly linked lists, where each list
sl@0
   683
corresponds to a priority value.
sl@0
   684
sl@0
   685
The lists are ordered by priority value, but items within
sl@0
   686
a list are in chronological order.
sl@0
   687
sl@0
   688
The number of lists is defined by the template integer parameter,
sl@0
   689
and each item in each list is of a class type defined by the template class parameter.
sl@0
   690
The number of lists must be between 1 and 64 inclusive.
sl@0
   691
sl@0
   692
@see TPriListLink
sl@0
   693
*/
sl@0
   694
class TPriList : public TPriListBase
sl@0
   695
	{
sl@0
   696
public:
sl@0
   697
    /**
sl@0
   698
    Constructor.
sl@0
   699
    */
sl@0
   700
	inline TPriList() : TPriListBase(n) {}
sl@0
   701
	
sl@0
   702
	
sl@0
   703
	/**
sl@0
   704
	Finds the highest priority item present on a priority list.
sl@0
   705
	If multiple items at the same priority are present, return the first to be
sl@0
   706
	added in chronological order.
sl@0
   707
sl@0
   708
	@return	a pointer to the item or NULL if the list is empty.
sl@0
   709
	*/
sl@0
   710
	inline T* First() { return (T*)TPriListBase::First(); }
sl@0
   711
private:
sl@0
   712
	SDblQueLink* iExtraQueues[n-1];
sl@0
   713
	};
sl@0
   714
sl@0
   715
sl@0
   716
sl@0
   717
/** Base for variant interface block
sl@0
   718
@internalTechnology
sl@0
   719
@prototype
sl@0
   720
*/
sl@0
   721
struct SInterfaceBlockBase
sl@0
   722
	{
sl@0
   723
	TUint32	iVer;	// version number
sl@0
   724
	TUint32	iSize;	// size in bytes
sl@0
   725
	};
sl@0
   726
#endif