utcache.c revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0
/******************************************************************************
*
* Module Name: utcache - local cache allocation routines
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2011, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#define __UTCACHE_C__
#include "acpi.h"
#include "accommon.h"
#define _COMPONENT ACPI_UTILITIES
ACPI_MODULE_NAME ("utcache")
#ifdef ACPI_USE_LOCAL_CACHE
/*******************************************************************************
*
* FUNCTION: AcpiOsCreateCache
*
* PARAMETERS: CacheName - Ascii name for the cache
* ObjectSize - Size of each cached object
* MaxDepth - Maximum depth of the cache (in objects)
* ReturnCache - Where the new cache object is returned
*
* RETURN: Status
*
* DESCRIPTION: Create a cache object
*
******************************************************************************/
char *CacheName,
{
{
return (AE_BAD_PARAMETER);
}
/* Create the cache object */
if (!Cache)
{
return (AE_NO_MEMORY);
}
/* Populate the cache object and return it */
*ReturnCache = Cache;
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiOsPurgeCache
*
* PARAMETERS: Cache - Handle to cache object
*
* RETURN: Status
*
* DESCRIPTION: Free all objects within the requested cache.
*
******************************************************************************/
{
char *Next;
if (!Cache)
{
return (AE_BAD_PARAMETER);
}
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Walk the list of objects in this cache */
{
/* Delete and unlink one cached state object */
Next = *(ACPI_CAST_INDIRECT_PTR (char,
Cache->CurrentDepth--;
}
(void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiOsDeleteCache
*
* PARAMETERS: Cache - Handle to cache object
*
* RETURN: Status
*
* DESCRIPTION: Free all objects within the requested cache and delete the
* cache object.
*
******************************************************************************/
{
/* Purge all objects in the cache */
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Now we can delete the cache object */
AcpiOsFree (Cache);
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiOsReleaseObject
*
* PARAMETERS: Cache - Handle to cache object
* Object - The object to be released
*
* RETURN: None
*
* DESCRIPTION: Release an object to the specified cache. If cache is full,
* the object is deleted.
*
******************************************************************************/
void *Object)
{
{
return (AE_BAD_PARAMETER);
}
/* If cache is full, just free this object */
{
}
/* Otherwise put this object back into the cache */
else
{
if (ACPI_FAILURE (Status))
{
return (Status);
}
/* Mark the object as cached */
/* Put the object at the head of the cache list */
* (ACPI_CAST_INDIRECT_PTR (char,
Cache->CurrentDepth++;
(void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiOsAcquireObject
*
* PARAMETERS: Cache - Handle to cache object
*
* RETURN: the acquired object. NULL on error
*
* DESCRIPTION: Get an object from the specified cache. If cache is empty,
* the object is allocated.
*
******************************************************************************/
void *
{
void *Object;
if (!Cache)
{
return (NULL);
}
if (ACPI_FAILURE (Status))
{
return (NULL);
}
/* Check the cache first */
{
/* There is an object available, use it */
Cache->CurrentDepth--;
if (ACPI_FAILURE (Status))
{
return (NULL);
}
/* Clear (zero) the previously used Object */
}
else
{
/* The cache is empty, create a new object */
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
{
}
#endif
/* Avoid deadlock with ACPI_ALLOCATE_ZEROED */
if (ACPI_FAILURE (Status))
{
return (NULL);
}
if (!Object)
{
return (NULL);
}
}
return (Object);
}
#endif /* ACPI_USE_LOCAL_CACHE */