reqqueue.cpp revision 9de47c4ec7b0fc9a384e4b815153de399da7b8de
/* $Id$ */
/** @file
* IPRT - Request Queue.
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
{
if (!pQueue)
return VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
{
/*
* Check input.
*/
if (hQueue == NIL_RTREQQUEUE)
return VINF_SUCCESS;
AssertReturn(ASMAtomicCmpXchgU32(&pQueue->u32Magic, RTREQQUEUE_MAGIC_DEAD, RTREQQUEUE_MAGIC), VERR_INVALID_HANDLE);
{
while (pReq)
{
}
}
return VINF_SUCCESS;
}
{
/*
* Check input.
*/
/*
* Process loop.
*
* We do not repeat the outer loop if we've got an informational status code
* since that code needs processing by our caller.
*/
int rc = VINF_SUCCESS;
while (rc <= VINF_SUCCESS)
{
/*
* Get pending requests.
*/
if (!pReqs)
{
ASMAtomicWriteBool(&pQueue->fBusy, false); /* this aint 100% perfect, but it's good enough for now... */
/** @todo We currently don't care if the entire time wasted here is larger than
* cMillies */
if (rc != VINF_SUCCESS)
break;
continue;
}
/*
* Reverse the list to process it in FIFO order.
*/
while (pReq)
{
}
/*
* Process the requests.
*/
while (pReqs)
{
/* Unchain the first request and advance the list. */
/* Process the request */
if (rc != VINF_SUCCESS)
break; /** @todo r=bird: we're dropping requests here! Add 2nd queue that can hold them. (will fix when writing a testcase) */
}
}
return rc;
}
RTDECL(int) RTReqQueueCall(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...)
{
return rc;
}
RTDECL(int) RTReqQueueCallVoid(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, PFNRT pfnFunction, unsigned cArgs, ...)
{
return rc;
}
RTDECL(int) RTReqQueueCallEx(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...)
{
return rc;
}
RTDECL(int) RTReqQueueCallV(RTREQQUEUE hQueue, PRTREQ *ppReq, RTMSINTERVAL cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args)
{
LogFlow(("RTReqCallV: cMillies=%d fFlags=%#x pfnFunction=%p cArgs=%d\n", cMillies, fFlags, pfnFunction, cArgs));
/*
* Check input.
*/
{
}
AssertMsgReturn(cArgs * sizeof(uintptr_t) <= sizeof(pReq->u.Internal.aArgs), ("cArgs=%u\n", cArgs), VERR_TOO_MUCH_DATA);
/*
* Allocate request
*/
if (rc != VINF_SUCCESS)
return rc;
/*
* Initialize the request data.
*/
/*
* Queue the request and return.
*/
if ( rc != VINF_SUCCESS
&& rc != VERR_TIMEOUT)
{
}
if (!(fFlags & RTREQFLAGS_NO_WAIT))
{
}
else
return rc;
}
{
AssertPtrReturn(pQueue, false);
return true;
return true;
return true;
return false;
}
/**
* Joins the list pList with whatever is linked up at *pHead.
*/
{
for (unsigned cIterations = 0;; cIterations++)
{
if (!pHead)
return;
return;
return;
}
}
/**
* Joins the list pList with whatever is linked up at *pHead.
*/
{
/*
* Split the list if it's too long.
*/
unsigned cReqs = 1;
{
if (cReqs++ > 25)
{
vmr3ReqJoinFreeSub(&pQueue->apReqFree[(i + 2 + (i == pQueue->iReqFree)) % RT_ELEMENTS(pQueue->apReqFree)], pTail->pNext);
return;
}
}
vmr3ReqJoinFreeSub(&pQueue->apReqFree[(pQueue->iReqFree + 2) % RT_ELEMENTS(pQueue->apReqFree)], pList);
}
{
/*
* Validate input.
*/
AssertMsgReturn(enmType > RTREQTYPE_INVALID && enmType < RTREQTYPE_MAX, ("%d\n", enmType), VERR_RT_REQUEST_INVALID_TYPE);
/*
* Try get a recycled packet.
*
* While this could all be solved with a single list with a lock, it's a sport
* of mine to avoid locks.
*/
while (--cTries >= 0)
{
PRTREQ volatile *ppHead = &pQueue->apReqFree[ASMAtomicIncU32(&pQueue->iReqFree) % RT_ELEMENTS(pQueue->apReqFree)];
if (pReq)
{
if ( pNext
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
}
/*
* Ok, allocate a new one.
*/
return rc;
}
/**
* Recycles a requst.
*
* @returns true if recycled, false if it should be freed.
* @param pQueue The queue.
* @param pReq The request.
*/
{
if ( !pQueue
return false;
PRTREQ volatile *ppHead = &pQueue->apReqFree[ASMAtomicIncU32(&pQueue->iReqFree) % RT_ELEMENTS(pQueue->apReqFree)];
do
{
return true;
}
/**
* Submits a request to the queue.
*
* @param pQueue The queue.
* @param pReq The request.
*/
{
do
{
/*
* Notify queue thread.
*/
}