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