FreeBSD/sys/contrib/dev/acpica/components/utilities/utcache.c
/*******************************************************************************
 *
 * 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.
 *
 ******************************************************************************/
AcpiOsAcquireObject
PARAMETERS:  Cache           - Handle to cache object

the acquired object. NULL on error

Get an object from the specified cache. If cache is empty,
the object is allocated.
AcpiOsAcquireObject PARAMETERS : Cache - Handle to cache object the acquired object . NULL on error Get an object from the specified cache . If cache is empty the object is allocated .
void *
AcpiOsAcquireObject (
    ACPI_MEMORY_LIST        *Cache)
{
    ACPI_STATUS             Status;
    void                    *Object;
    ACPI_FUNCTION_TRACE (OsAcquireObject);
    if (!Cache)
    {
        return_PTR (NULL);
    }
    Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
    if (ACPI_FAILURE (Status))
    {
        return_PTR (NULL);
    }
    ACPI_MEM_TRACKING (Cache->Requests++);
    if (Cache->ListHead)
    {
        Object = Cache->ListHead;
        Cache->ListHead = ACPI_GET_DESCRIPTOR_PTR (Object);
        Cache->CurrentDepth--;
        ACPI_MEM_TRACKING (Cache->Hits++);
        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
            "Object %p from %s cache\n", Object, Cache->ListName));
        Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
        if (ACPI_FAILURE (Status))
        {
            return_PTR (NULL);
        }
        memset (Object, 0, Cache->ObjectSize);
    }
    else
    {
        ACPI_MEM_TRACKING (Cache->TotalAllocated++);
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
        if ((Cache->TotalAllocated - Cache->TotalFreed) > Cache->MaxOccupied)
        {
            Cache->MaxOccupied = Cache->TotalAllocated - Cache->TotalFreed;
        }
#endif
        Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES);
        if (ACPI_FAILURE (Status))
        {
            return_PTR (NULL);
        }
        Object = ACPI_ALLOCATE_ZEROED (Cache->ObjectSize);
        if (!Object)
        {
            return_PTR (NULL);
        }
    }
    return_PTR (Object);
}
void * AcpiOsAcquireObject ( ACPI_MEMORY_LIST * Cache ) { ACPI_STATUS Status ; void * Object ; ACPI_FUNCTION_TRACE ( OsAcquireObject ) ; if ( ! Cache ) { return_PTR ( NULL ) ; } Status = AcpiUtAcquireMutex ( ACPI_MTX_CACHES ) ; if ( ACPI_FAILURE ( Status ) ) { return_PTR ( NULL ) ; } ACPI_MEM_TRACKING ( Cache -> Requests ++ ) ; if ( Cache -> ListHead ) { Object = Cache -> ListHead ; Cache -> ListHead = ACPI_GET_DESCRIPTOR_PTR ( Object ) ; Cache -> CurrentDepth -- ; ACPI_MEM_TRACKING ( Cache -> Hits ++ ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_EXEC , " \n " , Object , Cache -> ListName ) ) ; Status = AcpiUtReleaseMutex ( ACPI_MTX_CACHES ) ; if ( ACPI_FAILURE ( Status ) ) { return_PTR ( NULL ) ; } memset ( Object , 0 , Cache -> ObjectSize ) ; } else { ACPI_MEM_TRACKING ( Cache -> TotalAllocated ++ ) ; #ifdef ACPI_DBG_TRACK_ALLOCATIONS if ( ( Cache -> TotalAllocated - Cache -> TotalFreed ) > Cache -> MaxOccupied ) { Cache -> MaxOccupied = Cache -> TotalAllocated - Cache -> TotalFreed ; } #endif Status = AcpiUtReleaseMutex ( ACPI_MTX_CACHES ) ; if ( ACPI_FAILURE ( Status ) ) { return_PTR ( NULL ) ; } Object = ACPI_ALLOCATE_ZEROED ( Cache -> ObjectSize ) ; if ( ! Object ) { return_PTR ( NULL ) ; } } return_PTR ( Object ) ; }
FUNCTION:    AcpiOsAcquireObject
 PARAMETERS:  Cache           - Handle to cache object
FUNCTION : AcpiOsAcquireObject PARAMETERS : Cache - Handle to cache object
/* Check the cache first */ /* There is an object available, use it */ /* Clear (zero) the previously used Object */ /* The cache is empty, create a new object */ /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */