circbuf.cpp revision 4e4a8e041182dff5c52892bee58a5d8f58f4bdad
/* $Id$ */
/** @file
* IPRT - Lock Free Circular Buffer
*/
/*
* 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.
*
* 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 *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** @todo r=bird: this is missing docs and magic. */
typedef struct RTCIRCBUF
{
/** The current read position in the buffer. */
/** Is a read block acquired currently? */
bool fReading;
/** Is a write block acquired currently? */
bool fWriting;
/** The current write position in the buffer. */
/** How much space of the buffer is currently in use. */
/** How big is the buffer. */
/** The buffer itself. */
void *pvBuf;
} RTCIRCBUF, *PRTCIRCBUF;
{
/* Validate input. */
if (!pTmpBuf)
return VERR_NO_MEMORY;
{
return VINF_SUCCESS;
}
return VERR_NO_MEMORY;
}
{
/* Validate input. */
if (!pBuf)
return;
}
{
/* Validate input. */
}
{
/* Validate input. */
AssertPtrReturn(pBuf, 0);
}
{
/* Validate input. */
AssertPtrReturn(pBuf, 0);
}
{
/* Validate input. */
AssertPtrReturn(pBuf, 0);
}
{
/* Validate input. */
AssertPtrReturn(pBuf, 0);
}
{
/* Validate input. */
AssertPtrReturn(pBuf, 0);
}
RTDECL(void) RTCircBufAcquireReadBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize)
{
/* Validate input. */
*ppvStart = 0;
*pcbSize = 0;
/* How much is in use? */
if (cbUsed > 0)
{
/* Get the size out of the requested size, the read block till the end
* of the buffer & the currently used size. */
if (cbSize > 0)
{
/* Return the pointer address which point to the current read
* position. */
}
}
}
{
/* Validate input. */
/* Split at the end of the buffer. */
}
RTDECL(void) RTCircBufAcquireWriteBlock(PRTCIRCBUF pBuf, size_t cbReqSize, void **ppvStart, size_t *pcbSize)
{
/* Validate input. */
*ppvStart = 0;
*pcbSize = 0;
/* How much is free? */
if (cbFree > 0)
{
/* Get the size out of the requested size, then write block till the end
* of the buffer & the currently free size. */
if (cbSize > 0)
{
/* Return the pointer address which point to the current write
* position. */
}
}
}
{
/* Validate input. */
/* Split at the end of the buffer. */
}