sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\drivers\usbcc\queue.cpp sl@0: // Platform independent layer (PIL) of the USB Device controller driver: sl@0: // Simple singly linked list + its iterator. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file queue.cpp sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: sl@0: sl@0: void TSglQueLink::Enque(TSglQueLink* aLink) sl@0: // sl@0: // Enque this after aLink. sl@0: // sl@0: { sl@0: iNext = aLink->iNext; sl@0: aLink->iNext = this; sl@0: } sl@0: sl@0: sl@0: TSglQueBase::TSglQueBase(TInt aOffset) sl@0: // sl@0: // Constructor sl@0: // sl@0: : iHead(NULL), iLast((TSglQueLink*) &iHead), iOffset(aOffset), iElements(0) sl@0: { sl@0: // ESQueOffsetNotAligned sl@0: __ASSERT_ALWAYS((iOffset % 4 == 0), Kern::Fault(KUsbPILPanicCat, __LINE__)); sl@0: } sl@0: sl@0: sl@0: void TSglQueBase::DoAddLast(TAny* aPtr) sl@0: // sl@0: // Add the object at the end of the queue. sl@0: // sl@0: { sl@0: TSglQueLink* pL = PtrAdd((TSglQueLink*) aPtr, iOffset); sl@0: pL->Enque(iLast); sl@0: iLast = pL; sl@0: iElements++; sl@0: __ASSERT_DEBUG((iElements > 0), Kern::Fault(KUsbPILPanicCat, __LINE__)); sl@0: } sl@0: sl@0: sl@0: void TSglQueBase::DoRemove(TAny* aPtr) sl@0: // sl@0: // Remove the object from the queue. sl@0: // sl@0: { sl@0: TSglQueLink* pP = (TSglQueLink*) (&iHead); sl@0: TSglQueLink* pL = PtrAdd((TSglQueLink*) aPtr, iOffset); sl@0: TSglQueLink* pN = pP->iNext; sl@0: while (pN) sl@0: { sl@0: if (pN == pL) sl@0: { sl@0: pP->iNext = pN->iNext; sl@0: if (iLast == pL) sl@0: { sl@0: iLast = pP; sl@0: if (iLast == NULL) sl@0: iLast = (TSglQueLink*) (&iHead); sl@0: } sl@0: iElements--; sl@0: __ASSERT_DEBUG((iElements >= 0), Kern::Fault(KUsbPILPanicCat, __LINE__)); sl@0: return; sl@0: } sl@0: pP = pN; sl@0: pN = pP->iNext; sl@0: } sl@0: // This doesn't have to indicate an error (but might): sl@0: __KTRACE_OPT(KPANIC, Kern::Printf("TSglQueBase::DoRemove: ESQueLinkNotQueued")); sl@0: } sl@0: sl@0: sl@0: TSglQueIterBase::TSglQueIterBase(TSglQueBase& aQue) sl@0: // sl@0: // Constructor. sl@0: // sl@0: : iOffset(aQue.iOffset), iHead(aQue.iHead), iNext(aQue.iHead) sl@0: { sl@0: } sl@0: sl@0: sl@0: void TSglQueIterBase::SetToFirst() sl@0: // sl@0: // Start from the beginning of the que. sl@0: // sl@0: { sl@0: iNext = iHead->iNext; sl@0: } sl@0: sl@0: sl@0: TAny* TSglQueIterBase::DoPostInc() sl@0: // sl@0: // Return the current pointer and increment. sl@0: // sl@0: { sl@0: TAny* pN = iNext; sl@0: if (pN == NULL) sl@0: return NULL; sl@0: iNext = iNext->iNext; sl@0: return PtrSub(pN, iOffset); sl@0: } sl@0: sl@0: sl@0: //---