VDIoBackendMem.cpp revision 078c5b8c5c814755aab943bf62cadef7e91c419c
/** $Id$ */
/** @file
*
* VBox HDD container test utility, async I/O memory backend
*/
/*
* Copyright (C) 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.
*/
#include <iprt/semaphore.h>
#include "VDMemDisk.h"
#include "VDIoBackendMem.h"
#define VDMEMIOBACKEND_REQS 1024
/**
* Memory I/O request.
*/
typedef struct VDIOBACKENDREQ
{
/** I/O request direction. */
/** Memory disk handle. */
/** Start offset. */
/** Size of the transfer. */
/** Segments array. */
/** Number of segments in the array. */
unsigned cSegs;
/** Completion handler to call. */
/** Opaque user data. */
void *pvUser;
/**
* I/O memory backend
*/
typedef struct VDIOBACKENDMEM
{
/** Thread handle for the backend. */
/** Circular buffer used for submitting requests. */
/** Size of the buffer in request items. */
unsigned cReqsRing;
/** Event semaphore the thread waits on for more work. */
/** Flag whether the the server should be still running. */
volatile bool fRunning;
/**
* Pokes the I/O thread that something interesting happened.
*
* @returns IPRT status code.
*
* @param pIoBackend The backend to poke.
*/
{
}
{
int rc = VINF_SUCCESS;
if (pIoBackend)
{
if (RT_SUCCESS(rc))
{
pIoBackend->fRunning = true;
if (RT_SUCCESS(rc))
{
RTTHREADFLAGS_WAITABLE, "MemIo");
if (RT_SUCCESS(rc))
{
LogFlowFunc(("returns success\n"));
return VINF_SUCCESS;
}
}
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
return VINF_SUCCESS;
}
{
RTCircBufAcquireWriteBlock(pIoBackend->pRequestRing, sizeof(VDIOBACKENDREQ), (void **)&pReq, &cbData);
if (!pReq)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
}
/**
* I/O thread for the memory backend.
*
* @returns IPRT status code.
*
* @param hThread The thread handle.
* @param pvUser Opaque user data.
*/
{
while (pIoBackend->fRunning)
{
break;
RTCircBufAcquireReadBlock(pIoBackend->pRequestRing, sizeof(VDIOBACKENDREQ), (void **)&pReq, &cbData);
while (pReq)
{
int rcReq = VINF_SUCCESS;
{
case VDIOTXDIR_READ:
{
break;
}
case VDIOTXDIR_WRITE:
{
break;
}
case VDIOTXDIR_FLUSH:
break;
default:
AssertMsgFailed(("Invalid TX direction!\n"));
}
/* Notify completion. */
/* Do we have another request? */
RTCircBufAcquireReadBlock(pIoBackend->pRequestRing, sizeof(VDIOBACKENDREQ), (void **)&pReq, &cbData);
}
}
return VINF_SUCCESS;
}