Exemple #1
0
        private static void free(UsbTransferQueue transferParam)
        {
            for (int i = 0; i < transferParam.MaxOutstandingIO; i++)
            {
                if (!ReferenceEquals(transferParam.mTransferHandles[i], null))
                {
                    if (transferParam.mTransferHandles[i].InUse)
                    {
                        if (!transferParam.mTransferHandles[i].Context.IsCompleted)
                        {
                            transferParam.EndpointBase.Abort();
                            Thread.Sleep(1);
                        }

                        transferParam.mTransferHandles[i].InUse = false;
                        transferParam.mTransferHandles[i].Context.Dispose();
                    }
                    transferParam.mTransferHandles[i] = null;
                }
            }
            transferParam.mOutstandingTransferCount = 0;
            transferParam.mTransferHandleNextIndex  = 0;
            transferParam.mTransferHandleWaitIndex  = 0;
        }
Exemple #2
0
        private static ErrorCode transfer(UsbTransferQueue transferParam, out Handle handle)
        {
            handle = null;
            ErrorCode ret = ErrorCode.Success;

            // Submit transfers until the maximum number of outstanding transfer(s) is reached.
            while (transferParam.mOutstandingTransferCount < transferParam.MaxOutstandingIO)
            {
                if (ReferenceEquals(transferParam.mTransferHandles[transferParam.mTransferHandleNextIndex], null))
                {
                    handle = transferParam.mTransferHandles[transferParam.mTransferHandleNextIndex] =
                        new Handle(transferParam.EndpointBase.NewAsyncTransfer(), transferParam.mBuffer[transferParam.mTransferHandleNextIndex]);

                    // Get the next available benchmark transfer handle.
                    handle.Context.Fill(handle.Data, 0, handle.Data.Length, transferParam.Timeout, transferParam.IsoPacketSize);
                }
                else
                {
                    // Get the next available benchmark transfer handle.
                    handle = transferParam.mTransferHandles[transferParam.mTransferHandleNextIndex];
                }

                handle.Transferred = 0;

                // Submit this transfer now.
                handle.Context.Reset();
                ret = handle.Context.Submit();
                if (ret != ErrorCode.Success)
                {
                    goto Done;
                }

                // Mark this handle has InUse.
                handle.InUse = true;

                // When transfers ir successfully submitted, OutstandingTransferCount goes up; when
                // they are completed it goes down.
                //
                transferParam.mOutstandingTransferCount++;

                // Move TransferHandleNextIndex to the next available transfer.
                IncWithRoll(ref transferParam.mTransferHandleNextIndex, transferParam.MaxOutstandingIO);
            }

            // If the number of outstanding transfers has reached the limit, wait for the
            // oldest outstanding transfer to complete.
            //
            if (transferParam.mOutstandingTransferCount == transferParam.MaxOutstandingIO)
            {
                // TransferHandleWaitIndex is the index of the oldest outstanding transfer.
                handle = transferParam.mTransferHandles[transferParam.mTransferHandleWaitIndex];
                ret    = handle.Context.Wait(out handle.Transferred, false);
                if (ret != ErrorCode.Success)
                {
                    goto Done;
                }

                // Mark this handle has no longer InUse.
                handle.InUse = false;

                // When transfers ir successfully submitted, OutstandingTransferCount goes up; when
                // they are completed it goes down.
                //
                transferParam.mOutstandingTransferCount--;

                // Move TransferHandleWaitIndex to the oldest outstanding transfer.
                IncWithRoll(ref transferParam.mTransferHandleWaitIndex, transferParam.MaxOutstandingIO);

                return(ErrorCode.Success);
            }

Done:
            return(ret);
        }