reqpool.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * IPRT - Request Pool.
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * Copyright (C) 2006-2012 Oracle Corporation
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * This file is part of VirtualBox Open Source Edition (OSE), as
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * available from http://www.virtualbox.org. This file is free software;
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * you can redistribute it and/or modify it under the terms of the GNU
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * General Public License (GPL) as published by the Free Software
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * Foundation, in version 2 as it comes in the "COPYING" file of the
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * The contents of this file may alternatively be used under the terms
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * of the Common Development and Distribution License Version 1.0
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * VirtualBox OSE distribution, in which case the provisions of the
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * CDDL are applicable instead of those of the GPL.
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * You may elect to license modified versions of this file under the
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney * terms and conditions of either the GPL or the CDDL or both.
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney/*******************************************************************************
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney* Header Files *
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney*******************************************************************************/
typedef struct RTREQPOOLTHREAD
typedef struct RTREQPOOLINT
bool volatile fDestructing;
} RTREQPOOLINT;
if (!fLocked)
if (pReq)
AssertFailed();
return VINF_SUCCESS;
static void rtReqPoolThreadProcessRequest(PRTREQPOOLINT pPool, PRTREQPOOLTHREAD pThread, PRTREQINT pReq)
if (pReq)
if (pReq)
if (pReq)
if (!pThread)
int rc;
return rc;
return rc;
if (pThread)
if ( pPool
AssertMsgReturn(cMaxThreads > 0 && cMaxThreads <= RTREQPOOL_MAX_THREADS, ("%u\n", cMaxThreads), VERR_OUT_OF_RANGE);
if (cThreadsPushBackThreshold == 0)
AssertMsgReturn(cThreadsPushBackThreshold <= cMaxThreads, ("%u/%u\n", cThreadsPushBackThreshold, cMaxThreads), VERR_OUT_OF_RANGE);
AssertMsgReturn(cMsMaxPushBack <= RTREQPOOL_PUSH_BACK_MAX_MS, ("%llu\n", cMsMaxPushBack), VERR_OUT_OF_RANGE);
if (!pPool)
return VERR_NO_MEMORY;
pPool->cMsMinIdle = cMsMinIdle == RT_INDEFINITE_WAIT || cMsMinIdle >= UINT32_MAX ? UINT32_MAX : cMsMinIdle;
pPool->cMsIdleSleep = pPool->cMsMinIdle == UINT32_MAX ? RT_INDEFINITE_WAIT : RT_MAX(RT_MS_1SEC, pPool->cMsMinIdle);
return VINF_SUCCESS;
return rc;
AssertReturn(enmVar > RTREQPOOLCFGVAR_INVALID && enmVar < RTREQPOOLCFGVAR_END, VERR_INVALID_PARAMETER);
bool fWakeUpIdleThreads = false;
switch (enmVar)
pPool->cThreadsPushBackThreshold = pPool->cMinThreads + (pPool->cMaxThreads - pPool->cMinThreads) / 2;
AssertMsgBreakStmt(uValue <= RTREQPOOL_MAX_THREADS && uValue >= 1, ("%llu\n", uValue), rc = VERR_OUT_OF_RANGE);
fWakeUpIdleThreads = true;
pPool->cThreadsPushBackThreshold = pPool->cMinThreads + (pPool->cMaxThreads - pPool->cMinThreads) / 2;
AssertMsgBreakStmt(uValue < UINT32_MAX || uValue == RT_INDEFINITE_WAIT, ("%llu\n", uValue), rc = VERR_OUT_OF_RANGE);
else if (uValue == 0)
AssertMsgBreakStmt(uValue <= RTREQPOOL_PUSH_BACK_MAX_MS, ("%llu\n", uValue), rc = VERR_OUT_OF_RANGE);
AssertMsgBreakStmt(uValue <= RTREQPOOL_PUSH_BACK_MAX_MS, ("%llu\n", uValue), rc = VERR_OUT_OF_RANGE);
AssertMsgBreakStmt(uValue <= RTREQPOOL_MAX_FREE_REQUESTS, ("%llu\n", uValue), rc = VERR_OUT_OF_RANGE);
AssertFailed();
if (fWakeUpIdleThreads)
return rc;
switch (enmVar)
AssertFailed();
return u64;
switch (enmStat)
case RTREQPOOLSTAT_NS_AVERAGE_REQ_PROCESSING: u64 = pPool->cNsTotalReqProcessing / RT_MAX(pPool->cReqProcessed, 1); break;
case RTREQPOOLSTAT_NS_AVERAGE_REQ_QUEUED: u64 = pPool->cNsTotalReqQueued / RT_MAX(pPool->cReqProcessed, 1); break;
AssertFailed();
return u64;
if (!hPool)
if (cRefs == 0)
AssertReturn(ASMAtomicCmpXchgU32(&pPool->u32Magic, RTREQPOOL_MAGIC_DEAD, RTREQPOOL_MAGIC), UINT32_MAX);
#ifdef RT_STRICT
if (!pReq)
return cRefs;
if (pReq)
return rc;
return rc;
RTDECL(int) RTReqPoolCallEx( RTREQPOOL hPool, RTMSINTERVAL cMillies, PRTREQ *phReq, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, ...)
return rc;
RTDECL(int) RTReqPoolCallExV(RTREQPOOL hPool, RTMSINTERVAL cMillies, PRTREQ *phReq, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, va_list va)
AssertMsgReturn(!((uint32_t)fFlags & ~(uint32_t)(RTREQFLAGS_NO_WAIT | RTREQFLAGS_RETURN_MASK)), ("%#x\n", (uint32_t)fFlags), VERR_INVALID_PARAMETER);
AssertMsgReturn(cArgs * sizeof(uintptr_t) <= sizeof(pReq->u.Internal.aArgs), ("cArgs=%u\n", cArgs), VERR_TOO_MUCH_DATA);
return rc;
return rc;
return rc;
return rc;
return rc;
return rc;