44
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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\drivers\usbcc\queue.cpp
|
|
15 |
// Platform independent layer (PIL) of the USB Device controller driver:
|
|
16 |
// Simple singly linked list + its iterator.
|
|
17 |
//
|
|
18 |
//
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file queue.cpp
|
|
22 |
@internalTechnology
|
|
23 |
*/
|
|
24 |
|
|
25 |
#include <drivers/usbc.h>
|
|
26 |
|
|
27 |
|
|
28 |
void TSglQueLink::Enque(TSglQueLink* aLink)
|
|
29 |
//
|
|
30 |
// Enque this after aLink.
|
|
31 |
//
|
|
32 |
{
|
|
33 |
iNext = aLink->iNext;
|
|
34 |
aLink->iNext = this;
|
|
35 |
}
|
|
36 |
|
|
37 |
|
|
38 |
TSglQueBase::TSglQueBase(TInt aOffset)
|
|
39 |
//
|
|
40 |
// Constructor
|
|
41 |
//
|
|
42 |
: iHead(NULL), iLast((TSglQueLink*) &iHead), iOffset(aOffset), iElements(0)
|
|
43 |
{
|
|
44 |
// ESQueOffsetNotAligned
|
|
45 |
__ASSERT_ALWAYS((iOffset % 4 == 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
void TSglQueBase::DoAddLast(TAny* aPtr)
|
|
50 |
//
|
|
51 |
// Add the object at the end of the queue.
|
|
52 |
//
|
|
53 |
{
|
|
54 |
TSglQueLink* pL = PtrAdd((TSglQueLink*) aPtr, iOffset);
|
|
55 |
pL->Enque(iLast);
|
|
56 |
iLast = pL;
|
|
57 |
iElements++;
|
|
58 |
__ASSERT_DEBUG((iElements > 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
void TSglQueBase::DoRemove(TAny* aPtr)
|
|
63 |
//
|
|
64 |
// Remove the object from the queue.
|
|
65 |
//
|
|
66 |
{
|
|
67 |
TSglQueLink* pP = (TSglQueLink*) (&iHead);
|
|
68 |
TSglQueLink* pL = PtrAdd((TSglQueLink*) aPtr, iOffset);
|
|
69 |
TSglQueLink* pN = pP->iNext;
|
|
70 |
while (pN)
|
|
71 |
{
|
|
72 |
if (pN == pL)
|
|
73 |
{
|
|
74 |
pP->iNext = pN->iNext;
|
|
75 |
if (iLast == pL)
|
|
76 |
{
|
|
77 |
iLast = pP;
|
|
78 |
if (iLast == NULL)
|
|
79 |
iLast = (TSglQueLink*) (&iHead);
|
|
80 |
}
|
|
81 |
iElements--;
|
|
82 |
__ASSERT_DEBUG((iElements >= 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
|
|
83 |
return;
|
|
84 |
}
|
|
85 |
pP = pN;
|
|
86 |
pN = pP->iNext;
|
|
87 |
}
|
|
88 |
// This doesn't have to indicate an error (but might):
|
44
|
89 |
__KTRACE_OPT(KPANIC, Kern::Printf("TSglQueBase::DoRemove: ESQueLinkNotQueued"));
|
0
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
TSglQueIterBase::TSglQueIterBase(TSglQueBase& aQue)
|
|
94 |
//
|
|
95 |
// Constructor.
|
|
96 |
//
|
|
97 |
: iOffset(aQue.iOffset), iHead(aQue.iHead), iNext(aQue.iHead)
|
|
98 |
{
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
void TSglQueIterBase::SetToFirst()
|
|
103 |
//
|
|
104 |
// Start from the beginning of the que.
|
|
105 |
//
|
|
106 |
{
|
|
107 |
iNext = iHead->iNext;
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
TAny* TSglQueIterBase::DoPostInc()
|
|
112 |
//
|
|
113 |
// Return the current pointer and increment.
|
|
114 |
//
|
|
115 |
{
|
|
116 |
TAny* pN = iNext;
|
|
117 |
if (pN == NULL)
|
|
118 |
return NULL;
|
|
119 |
iNext = iNext->iNext;
|
|
120 |
return PtrSub(pN, iOffset);
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
//---
|