/* $Id$ */
/** @file
* IPRT - Memory Allocation Pool.
*/
/*
* Copyright (C) 2009-2012 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/spinlock.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** Pointer to a memory pool instance. */
/** Pointer to a memory pool entry. */
/**
* Memory pool entry.
*/
typedef struct RTMEMPOOLENTRY
{
/** Pointer to the pool */
/** Pointer to the next entry. */
/** Pointer to the previous entry. */
/** The number of references to the pool entry. */
/**
* Memory pool instance data.
*/
typedef struct RTMEMPOOLINT
{
/** Magic number (RTMEMPOOL_MAGIC). */
/** Spinlock protecting the pool entry list updates. */
/** Head entry pointer. */
/** The number of entries in the pool (for statistical purposes). */
/** User data associated with the pool. */
void *pvUser;
/** The pool name. (variable length) */
} RTMEMPOOLINT;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Validates a memory pool handle, translating RTMEMPOOL_DEFAULT when found,
* and returns rc if not valid. */
do { \
if (pMemPool == RTMEMPOOL_DEFAULT) \
pMemPool = &g_rtMemPoolDefault; \
else \
{ \
} \
} while (0)
/** Validates a memory pool entry and returns rc if not valid. */
do { \
} while (0)
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The */
{
/* .u32Magic = */ RTMEMPOOL_MAGIC,
/* .hSpinLock = */ NIL_RTSPINLOCK,
/* .pHead = */ NULL,
/* .cEntries = */ 0,
/* .pvUser = */ NULL,
/* .szName = */ "default"
};
{
if (!pMemPool)
return VERR_NO_MEMORY;
int rc = RTSpinlockCreate(&pMemPool->hSpinLock, RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, "RTMemPoolCreate");
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}
{
if (hMemPool == NIL_RTMEMPOOL)
return VINF_SUCCESS;
if (pMemPool == &g_rtMemPoolDefault)
return VINF_SUCCESS;
/*
* Invalidate the handle and free all associated resources.
*/
while (pEntry)
{
}
return VINF_SUCCESS;
}
{
{
if (pHead)
}
}
{
{
if (pNext)
if (pPrev)
else
}
else
}
{
if (!pEntry)
return NULL;
return pEntry + 1;
}
{
if (!pEntry)
return NULL;
return pEntry + 1;
}
{
if (!pEntry)
return NULL;
return pEntry + 1;
}
RTDECL(void *) RTMemPoolDupEx(RTMEMPOOL hMemPool, const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW
{
if (!pEntry)
return NULL;
return pEntry + 1;
}
{
/*
* Fend off the odd cases.
*/
if (!cbNew)
{
return NULL;
}
if (!pvOld)
/*
* Real realloc.
*/
/*
* Unlink it from the current pool and try reallocate it.
*/
if (!pEntry)
{
return NULL;
}
return pEntry + 1;
}
{
}
{
return cRefs;
}
{
if (!pv)
return 0;
if (!cRefs)
{
}
return cRefs;
}
{
return cRefs;
}