Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenutcache.c
Go to the documentation of this file.
00001 /****************************************************************************** 00002 * 00003 * Module Name: utcache - local cache allocation routines 00004 * 00005 *****************************************************************************/ 00006 00007 /****************************************************************************** 00008 * 00009 * 1. Copyright Notice 00010 * 00011 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. 00012 * All rights reserved. 00013 * 00014 * 2. License 00015 * 00016 * 2.1. This is your license from Intel Corp. under its intellectual property 00017 * rights. You may have additional license terms from the party that provided 00018 * you this software, covering your right to use that party's intellectual 00019 * property rights. 00020 * 00021 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 00022 * copy of the source code appearing in this file ("Covered Code") an 00023 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 00024 * base code distributed originally by Intel ("Original Intel Code") to copy, 00025 * make derivatives, distribute, use and display any portion of the Covered 00026 * Code in any form, with the right to sublicense such rights; and 00027 * 00028 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 00029 * license (with the right to sublicense), under only those claims of Intel 00030 * patents that are infringed by the Original Intel Code, to make, use, sell, 00031 * offer to sell, and import the Covered Code and derivative works thereof 00032 * solely to the minimum extent necessary to exercise the above copyright 00033 * license, and in no event shall the patent license extend to any additions 00034 * to or modifications of the Original Intel Code. No other license or right 00035 * is granted directly or by implication, estoppel or otherwise; 00036 * 00037 * The above copyright and patent license is granted only if the following 00038 * conditions are met: 00039 * 00040 * 3. Conditions 00041 * 00042 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 00043 * Redistribution of source code of any substantial portion of the Covered 00044 * Code or modification with rights to further distribute source must include 00045 * the above Copyright Notice, the above License, this list of Conditions, 00046 * and the following Disclaimer and Export Compliance provision. In addition, 00047 * Licensee must cause all Covered Code to which Licensee contributes to 00048 * contain a file documenting the changes Licensee made to create that Covered 00049 * Code and the date of any change. Licensee must include in that file the 00050 * documentation of any changes made by any predecessor Licensee. Licensee 00051 * must include a prominent statement that the modification is derived, 00052 * directly or indirectly, from Original Intel Code. 00053 * 00054 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 00055 * Redistribution of source code of any substantial portion of the Covered 00056 * Code or modification without rights to further distribute source must 00057 * include the following Disclaimer and Export Compliance provision in the 00058 * documentation and/or other materials provided with distribution. In 00059 * addition, Licensee may not authorize further sublicense of source of any 00060 * portion of the Covered Code, and must include terms to the effect that the 00061 * license from Licensee to its licensee is limited to the intellectual 00062 * property embodied in the software Licensee provides to its licensee, and 00063 * not to intellectual property embodied in modifications its licensee may 00064 * make. 00065 * 00066 * 3.3. Redistribution of Executable. Redistribution in executable form of any 00067 * substantial portion of the Covered Code or modification must reproduce the 00068 * above Copyright Notice, and the following Disclaimer and Export Compliance 00069 * provision in the documentation and/or other materials provided with the 00070 * distribution. 00071 * 00072 * 3.4. Intel retains all right, title, and interest in and to the Original 00073 * Intel Code. 00074 * 00075 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 00076 * Intel shall be used in advertising or otherwise to promote the sale, use or 00077 * other dealings in products derived from or relating to the Covered Code 00078 * without prior written authorization from Intel. 00079 * 00080 * 4. Disclaimer and Export Compliance 00081 * 00082 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 00083 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 00084 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 00085 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 00086 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 00087 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 00088 * PARTICULAR PURPOSE. 00089 * 00090 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 00091 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 00092 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 00093 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 00094 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 00095 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 00096 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 00097 * LIMITED REMEDY. 00098 * 00099 * 4.3. Licensee shall not export, either directly or indirectly, any of this 00100 * software or system incorporating such software without first obtaining any 00101 * required license or other approval from the U. S. Department of Commerce or 00102 * any other agency or department of the United States Government. In the 00103 * event Licensee exports any such software from the United States or 00104 * re-exports any such software from a foreign destination, Licensee shall 00105 * ensure that the distribution and export/re-export of the software is in 00106 * compliance with all laws, regulations, orders, or other restrictions of the 00107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 00108 * any of its subsidiaries will export/re-export any technical data, process, 00109 * software, or service, directly or indirectly, to any country for which the 00110 * United States government or any agency thereof requires an export license, 00111 * other governmental approval, or letter of assurance, without first obtaining 00112 * such license, approval or letter. 00113 * 00114 *****************************************************************************/ 00115 00116 #define __UTCACHE_C__ 00117 00118 #include "acpi.h" 00119 #include "accommon.h" 00120 00121 #define _COMPONENT ACPI_UTILITIES 00122 ACPI_MODULE_NAME ("utcache") 00123 00124 00125 #ifdef ACPI_USE_LOCAL_CACHE 00126 /******************************************************************************* 00127 * 00128 * FUNCTION: AcpiOsCreateCache 00129 * 00130 * PARAMETERS: CacheName - Ascii name for the cache 00131 * ObjectSize - Size of each cached object 00132 * MaxDepth - Maximum depth of the cache (in objects) 00133 * ReturnCache - Where the new cache object is returned 00134 * 00135 * RETURN: Status 00136 * 00137 * DESCRIPTION: Create a cache object 00138 * 00139 ******************************************************************************/ 00140 00141 ACPI_STATUS 00142 AcpiOsCreateCache ( 00143 char *CacheName, 00144 UINT16 ObjectSize, 00145 UINT16 MaxDepth, 00146 ACPI_MEMORY_LIST **ReturnCache) 00147 { 00148 ACPI_MEMORY_LIST *Cache; 00149 00150 00151 ACPI_FUNCTION_ENTRY (); 00152 00153 00154 if (!CacheName || !ReturnCache || (ObjectSize < 16)) 00155 { 00156 return (AE_BAD_PARAMETER); 00157 } 00158 00159 /* Create the cache object */ 00160 00161 Cache = AcpiOsAllocate (sizeof (ACPI_MEMORY_LIST)); 00162 if (!Cache) 00163 { 00164 return (AE_NO_MEMORY); 00165 } 00166 00167 /* Populate the cache object and return it */ 00168 00169 ACPI_MEMSET (Cache, 0, sizeof (ACPI_MEMORY_LIST)); 00170 Cache->LinkOffset = 8; 00171 Cache->ListName = CacheName; 00172 Cache->ObjectSize = ObjectSize; 00173 Cache->MaxDepth = MaxDepth; 00174 00175 *ReturnCache = Cache; 00176 return (AE_OK); 00177 } 00178 00179 00180 /******************************************************************************* 00181 * 00182 * FUNCTION: AcpiOsPurgeCache 00183 * 00184 * PARAMETERS: Cache - Handle to cache object 00185 * 00186 * RETURN: Status 00187 * 00188 * DESCRIPTION: Free all objects within the requested cache. 00189 * 00190 ******************************************************************************/ 00191 00192 ACPI_STATUS 00193 AcpiOsPurgeCache ( 00194 ACPI_MEMORY_LIST *Cache) 00195 { 00196 char *Next; 00197 ACPI_STATUS Status; 00198 00199 00200 ACPI_FUNCTION_ENTRY (); 00201 00202 00203 if (!Cache) 00204 { 00205 return (AE_BAD_PARAMETER); 00206 } 00207 00208 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES); 00209 if (ACPI_FAILURE (Status)) 00210 { 00211 return (Status); 00212 } 00213 00214 /* Walk the list of objects in this cache */ 00215 00216 while (Cache->ListHead) 00217 { 00218 /* Delete and unlink one cached state object */ 00219 00220 Next = *(ACPI_CAST_INDIRECT_PTR (char, 00221 &(((char *) Cache->ListHead)[Cache->LinkOffset]))); 00222 ACPI_FREE (Cache->ListHead); 00223 00224 Cache->ListHead = Next; 00225 Cache->CurrentDepth--; 00226 } 00227 00228 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES); 00229 return (AE_OK); 00230 } 00231 00232 00233 /******************************************************************************* 00234 * 00235 * FUNCTION: AcpiOsDeleteCache 00236 * 00237 * PARAMETERS: Cache - Handle to cache object 00238 * 00239 * RETURN: Status 00240 * 00241 * DESCRIPTION: Free all objects within the requested cache and delete the 00242 * cache object. 00243 * 00244 ******************************************************************************/ 00245 00246 ACPI_STATUS 00247 AcpiOsDeleteCache ( 00248 ACPI_MEMORY_LIST *Cache) 00249 { 00250 ACPI_STATUS Status; 00251 00252 00253 ACPI_FUNCTION_ENTRY (); 00254 00255 00256 /* Purge all objects in the cache */ 00257 00258 Status = AcpiOsPurgeCache (Cache); 00259 if (ACPI_FAILURE (Status)) 00260 { 00261 return (Status); 00262 } 00263 00264 /* Now we can delete the cache object */ 00265 00266 AcpiOsFree (Cache); 00267 return (AE_OK); 00268 } 00269 00270 00271 /******************************************************************************* 00272 * 00273 * FUNCTION: AcpiOsReleaseObject 00274 * 00275 * PARAMETERS: Cache - Handle to cache object 00276 * Object - The object to be released 00277 * 00278 * RETURN: None 00279 * 00280 * DESCRIPTION: Release an object to the specified cache. If cache is full, 00281 * the object is deleted. 00282 * 00283 ******************************************************************************/ 00284 00285 ACPI_STATUS 00286 AcpiOsReleaseObject ( 00287 ACPI_MEMORY_LIST *Cache, 00288 void *Object) 00289 { 00290 ACPI_STATUS Status; 00291 00292 00293 ACPI_FUNCTION_ENTRY (); 00294 00295 00296 if (!Cache || !Object) 00297 { 00298 return (AE_BAD_PARAMETER); 00299 } 00300 00301 /* If cache is full, just free this object */ 00302 00303 if (Cache->CurrentDepth >= Cache->MaxDepth) 00304 { 00305 ACPI_FREE (Object); 00306 ACPI_MEM_TRACKING (Cache->TotalFreed++); 00307 } 00308 00309 /* Otherwise put this object back into the cache */ 00310 00311 else 00312 { 00313 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES); 00314 if (ACPI_FAILURE (Status)) 00315 { 00316 return (Status); 00317 } 00318 00319 /* Mark the object as cached */ 00320 00321 ACPI_MEMSET (Object, 0xCA, Cache->ObjectSize); 00322 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_CACHED); 00323 00324 /* Put the object at the head of the cache list */ 00325 00326 * (ACPI_CAST_INDIRECT_PTR (char, 00327 &(((char *) Object)[Cache->LinkOffset]))) = Cache->ListHead; 00328 Cache->ListHead = Object; 00329 Cache->CurrentDepth++; 00330 00331 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES); 00332 } 00333 00334 return (AE_OK); 00335 } 00336 00337 00338 /******************************************************************************* 00339 * 00340 * FUNCTION: AcpiOsAcquireObject 00341 * 00342 * PARAMETERS: Cache - Handle to cache object 00343 * 00344 * RETURN: the acquired object. NULL on error 00345 * 00346 * DESCRIPTION: Get an object from the specified cache. If cache is empty, 00347 * the object is allocated. 00348 * 00349 ******************************************************************************/ 00350 00351 void * 00352 AcpiOsAcquireObject ( 00353 ACPI_MEMORY_LIST *Cache) 00354 { 00355 ACPI_STATUS Status; 00356 void *Object; 00357 00358 00359 ACPI_FUNCTION_NAME (OsAcquireObject); 00360 00361 00362 if (!Cache) 00363 { 00364 return (NULL); 00365 } 00366 00367 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES); 00368 if (ACPI_FAILURE (Status)) 00369 { 00370 return (NULL); 00371 } 00372 00373 ACPI_MEM_TRACKING (Cache->Requests++); 00374 00375 /* Check the cache first */ 00376 00377 if (Cache->ListHead) 00378 { 00379 /* There is an object available, use it */ 00380 00381 Object = Cache->ListHead; 00382 Cache->ListHead = *(ACPI_CAST_INDIRECT_PTR (char, 00383 &(((char *) Object)[Cache->LinkOffset]))); 00384 00385 Cache->CurrentDepth--; 00386 00387 ACPI_MEM_TRACKING (Cache->Hits++); 00388 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 00389 "Object %p from %s cache\n", Object, Cache->ListName)); 00390 00391 Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES); 00392 if (ACPI_FAILURE (Status)) 00393 { 00394 return (NULL); 00395 } 00396 00397 /* Clear (zero) the previously used Object */ 00398 00399 ACPI_MEMSET (Object, 0, Cache->ObjectSize); 00400 } 00401 else 00402 { 00403 /* The cache is empty, create a new object */ 00404 00405 ACPI_MEM_TRACKING (Cache->TotalAllocated++); 00406 00407 #ifdef ACPI_DBG_TRACK_ALLOCATIONS 00408 if ((Cache->TotalAllocated - Cache->TotalFreed) > Cache->MaxOccupied) 00409 { 00410 Cache->MaxOccupied = Cache->TotalAllocated - Cache->TotalFreed; 00411 } 00412 #endif 00413 00414 /* Avoid deadlock with ACPI_ALLOCATE_ZEROED */ 00415 00416 Status = AcpiUtReleaseMutex (ACPI_MTX_CACHES); 00417 if (ACPI_FAILURE (Status)) 00418 { 00419 return (NULL); 00420 } 00421 00422 Object = ACPI_ALLOCATE_ZEROED (Cache->ObjectSize); 00423 if (!Object) 00424 { 00425 return (NULL); 00426 } 00427 } 00428 00429 return (Object); 00430 } 00431 #endif /* ACPI_USE_LOCAL_CACHE */ 00432 00433 Generated on Sun May 27 2012 04:27:23 for ReactOS by
1.7.6.1
|