aiomgr.cpp revision 377d3eefbc092f9d4220535d896c510d560bbd74
/* $Id$ */
/** @file
* IPRT - Async I/O manager.
*/
/*
* Copyright (C) 2013 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/critsect.h>
#include <iprt/semaphore.h>
#include <iprt/queueatomic.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Pointer to an internal async I/O file instance. */
typedef struct RTAIOMGRFILEINT *PRTAIOMGRFILEINT;
/**
* Blocking event types.
*/
typedef enum RTAIOMGREVENT
{
/** Invalid tye */
/** An endpoint is added to the manager. */
/** An endpoint is about to be closed. */
/** 32bit hack */
RTAIOMGREVENT_32BIT_HACK = 0x7fffffff
/**
* Async I/O manager instance data.
*/
typedef struct RTAIOMGRINT
{
/** Magic value. */
/** Reference count. */
/** Running flag. */
volatile bool fRunning;
/** Async I/O context handle. */
/** async I/O thread. */
/** List of files assigned to this manager. */
/** Number of requests active currently. */
unsigned cReqsActive;
/** Number of maximum requests active. */
/** Pointer to an array of free async I/O request handles. */
/** Index of the next free entry in the cache. */
/** Size of the array. */
unsigned cReqEntries;
/** Critical section protecting the blocking event handling. */
/** Event semaphore for blocking external events.
* The caller waits on it until the async I/O manager
* finished processing the event. */
/** Flag whether a blocking event is pending and needs
* processing by the I/O manager. */
volatile bool fBlockingEventPending;
/** Blocking event type */
volatile RTAIOMGREVENT enmBlockingEvent;
/** Event type data */
union
{
/** The file to be added */
volatile PRTAIOMGRFILEINT pFileAdd;
/** The file to be closed */
volatile PRTAIOMGRFILEINT pFileClose;
} RTAIOMGRINT;
/** Pointer to an internal async I/O manager instance. */
typedef RTAIOMGRINT *PRTAIOMGRINT;
/**
* Async I/O manager file instance data.
*/
typedef struct RTAIOMGRFILEINT
{
/** Magic value. */
/** Reference count. */
/** File handle. */
/** async I/O manager this file belongs to. */
/** Work queue for new requests. */
/** Data for exclusive use by the assigned async I/O manager. */
struct
{
/** Pointer to the next file assigned to the manager. */
#if 0
/** List of pending requests (not submitted due to usage restrictions
* or a pending flush request) */
/** Tail of pending requests. */
/** Tree of currently locked ranges.
* If a write task is enqueued the range gets locked and any other
* task writing to that range has to wait until the task completes.
*/
/** Number of requests with a range lock active. */
unsigned cLockedReqsActive;
/** Number of requests currently being processed for this endpoint
* (excluded flush requests). */
unsigned cRequestsActive;
#endif
} AioMgr;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
do { \
} while (0)
/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
/** Validates a handle and returns (void) if not valid. */
#define RTAIOMGR_VALID_RETURN_VOID(a_hAioMgr) \
do { \
} while (0)
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/**
* async I/O manager worker loop.
*
* @returns IPRT status code.
* @param hThreadSelf The thread handle this worker belongs to.
* @param pvUser Opaque user data (Pointer to async I/O manager instance).
*/
{
bool fRunning = true;
do
{
uint32_t cReqsCompleted = 0;
{
}
} while (fRunning);
return VINF_SUCCESS;
}
/**
* Destroys an async I/O manager.
*
* @returns nothing.
* @param pThis The async I/O manager instance to destroy.
*/
{
int rc;
}
/**
* Destroys an async I/O manager file.
*
* @returns nothing.
* @param pThis The async I/O manager file.
*/
{
}
{
int rc = VINF_SUCCESS;
if (pThis)
{
: cReqsMax,
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
{
}
}
if (RT_FAILURE(rc))
}
else
rc = VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
return rc;
}
{
return cRefs;
}
{
if (pThis == NIL_RTAIOMGR)
return 0;
if (cRefs == 0)
return cRefs;
}
RTDECL(int) RTAioMgrFileCreate(RTAIOMGR hAioMgr, RTFILE hFile, PFNRTAIOMGRREQCOMPLETE pfnReqComplete,
{
int rc = VINF_SUCCESS;
if (pThis)
{
if (RT_FAILURE(rc))
}
else
rc = VERR_NO_MEMORY;
if (RT_SUCCESS(rc))
*phAioMgrFile = pThis;
return rc;
}
{
return cRefs;
}
{
if (pThis == NIL_RTAIOMGRFILE)
return 0;
if (cRefs == 0)
return cRefs;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
return VERR_NOT_IMPLEMENTED;
}