12fc06b87Sbeveloper /* 22fc06b87Sbeveloper * Copyright (c) 2003 Marcus Overhagen 32fc06b87Sbeveloper * 42fc06b87Sbeveloper * Permission is hereby granted, free of charge, to any person obtaining a 52fc06b87Sbeveloper * copy of this software and associated documentation files (the "Software"), 62fc06b87Sbeveloper * to deal in the Software without restriction, including without limitation 72fc06b87Sbeveloper * the rights to use, copy, modify, merge, publish, distribute, sublicense, 82fc06b87Sbeveloper * and/or sell copies of the Software, and to permit persons to whom the 92fc06b87Sbeveloper * Software is furnished to do so, subject to the following conditions: 102fc06b87Sbeveloper * 112fc06b87Sbeveloper * The above copyright notice and this permission notice shall be included in 122fc06b87Sbeveloper * all copies or substantial portions of the Software. 132fc06b87Sbeveloper * 142fc06b87Sbeveloper * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 152fc06b87Sbeveloper * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 162fc06b87Sbeveloper * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 172fc06b87Sbeveloper * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 182fc06b87Sbeveloper * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 192fc06b87Sbeveloper * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 202fc06b87Sbeveloper * DEALINGS IN THE SOFTWARE. 212fc06b87Sbeveloper */ 22e75560e6Sejakowatz #ifndef _BLOCK_CACHE_H 23e75560e6Sejakowatz #define _BLOCK_CACHE_H 24e75560e6Sejakowatz 25e75560e6Sejakowatz #include <BeBuild.h> 26e75560e6Sejakowatz #include <Locker.h> 27e75560e6Sejakowatz 283c839f3fSbeveloper /* The OpenBeOS implementation of the BBlockCache. 292fc06b87Sbeveloper * A class used to manage a pool of memory blocks. 302fc06b87Sbeveloper */ 312fc06b87Sbeveloper 322fc06b87Sbeveloper /* The allocation type to be used in the constructor 332fc06b87Sbeveloper */ 342fc06b87Sbeveloper enum { 35e75560e6Sejakowatz B_OBJECT_CACHE = 0, 36e75560e6Sejakowatz B_MALLOC_CACHE = 1 37e75560e6Sejakowatz }; 38e75560e6Sejakowatz 392fc06b87Sbeveloper /* The BBlockCache class: 402fc06b87Sbeveloper */ 41e75560e6Sejakowatz class BBlockCache 42e75560e6Sejakowatz { 43e75560e6Sejakowatz public: 44ad159f43Sbeveloper BBlockCache(uint32 blockCount, 452fc06b87Sbeveloper size_t blockSize, 462fc06b87Sbeveloper uint32 allocationType); 472fc06b87Sbeveloper virtual ~BBlockCache(); 48e75560e6Sejakowatz 492fc06b87Sbeveloper void * Get(size_t blockSize); 502fc06b87Sbeveloper void Save(void *pointer, size_t blockSize); 51e75560e6Sejakowatz 522fc06b87Sbeveloper /* Private or reserved functions and data 532fc06b87Sbeveloper */ 54e75560e6Sejakowatz private: 55e75560e6Sejakowatz virtual void _ReservedBlockCache1(); 56e75560e6Sejakowatz virtual void _ReservedBlockCache2(); 57e75560e6Sejakowatz 58e75560e6Sejakowatz BBlockCache(const BBlockCache &); 59e75560e6Sejakowatz BBlockCache &operator=(const BBlockCache &); 60e75560e6Sejakowatz 612fc06b87Sbeveloper struct _FreeBlock 622fc06b87Sbeveloper { 632fc06b87Sbeveloper uint32 magic1; 642fc06b87Sbeveloper _FreeBlock *next; 652fc06b87Sbeveloper uint32 magic2; 66e75560e6Sejakowatz }; 67e75560e6Sejakowatz 682fc06b87Sbeveloper _FreeBlock *fFreeList; 692fc06b87Sbeveloper size_t fBlockSize; 70*369eef13SIngo Weinhold int32 fFreeBlocks; 71*369eef13SIngo Weinhold int32 fBlockCount; 722fc06b87Sbeveloper BLocker fLocker; 732fc06b87Sbeveloper void * (*fAlloc)(size_t size); 742fc06b87Sbeveloper void (*fFree)(void *pointer); 75*369eef13SIngo Weinhold uint32 _reserved[2]; 762fc06b87Sbeveloper }; 772fc06b87Sbeveloper 782fc06b87Sbeveloper #endif /* _BLOCK_CACHE_H */ 79