sl@0: /* Copyright (c) 2009 The Khronos Group Inc. sl@0: * sl@0: * Permission is hereby granted, free of charge, to any person obtaining a sl@0: * copy of this software and/or associated documentation files (the sl@0: * "Materials"), to deal in the Materials without restriction, including sl@0: * without limitation the rights to use, copy, modify, merge, publish, sl@0: * distribute, sublicense, and/or sell copies of the Materials, and to sl@0: * permit persons to whom the Materials are furnished to do so, subject to sl@0: * the following conditions: sl@0: * sl@0: * The above copyright notice and this permission notice shall be included sl@0: * in all copies or substantial portions of the Materials. sl@0: * sl@0: * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, sl@0: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF sl@0: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. sl@0: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY sl@0: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, sl@0: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE sl@0: * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. sl@0: */ sl@0: sl@0: /*! sl@0: * \file owfpool.h sl@0: */ sl@0: #ifndef OWFPOOL_H_ sl@0: #define OWFPOOL_H_ sl@0: sl@0: #include sl@0: #include "owftypes.h" sl@0: sl@0: sl@0: #ifdef __cplusplus sl@0: extern "C" sl@0: { sl@0: #endif sl@0: sl@0: sl@0: #define EOC (OWFuint32) 0xFFFFFFFF sl@0: sl@0: sl@0: typedef struct sl@0: { sl@0: /*! linked list of free entries */ sl@0: OWFuint32* entries; sl@0: /*! solid chunk of memory containing all the objects; sl@0: * no book-keeping data here, plain sequentially sl@0: * stored objects only */ sl@0: char* chunk; sl@0: /*! index number of the first free object in the pool; sl@0: * EOC if the pool is empty */ sl@0: OWFuint32 firstFree; sl@0: /*! pools capacity */ sl@0: size_t capacity; sl@0: /*! number of free (unallocated) objects in the pool */ sl@0: size_t free; sl@0: /*! size of an object */ sl@0: size_t entrySize; sl@0: } OWF_POOL; sl@0: sl@0: /*! sl@0: * Creates new object pool. Initially all pool's sl@0: * objects are unallocated. sl@0: * sl@0: * \param objectSize Size of an individual pool object sl@0: * \param objectCount Pool capacity (number of objects) sl@0: * sl@0: * \return New pool or NULL sl@0: */ sl@0: OWF_API_CALL OWF_POOL* sl@0: OWF_Pool_Create(size_t objectSize, size_t objectCount); sl@0: sl@0: /*! sl@0: * Allocate object from pool. The pool retains ownership of sl@0: * the object returned by the function. sl@0: * sl@0: * \param pool Pool from which the object should be allocated sl@0: * sl@0: * \return Object or NULL sl@0: */ sl@0: OWF_API_CALL void* sl@0: OWF_Pool_GetObject(OWF_POOL* pool); sl@0: sl@0: /*! sl@0: * Returns previously allocated object back to the pool. sl@0: * sl@0: * \param object Object (must be valid pool object) sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Pool_PutObject(void* object); sl@0: sl@0: /*! sl@0: * Destroys a pool. Frees all resources allocated by sl@0: * the pool and invalidates all objects in the pool sl@0: * (both allocated and unallocated) sl@0: * sl@0: * \param pool Pool to destroy sl@0: */ sl@0: OWF_API_CALL void sl@0: OWF_Pool_Destroy(OWF_POOL* pool); sl@0: sl@0: sl@0: #ifdef __cplusplus sl@0: } sl@0: #endif sl@0: sl@0: sl@0: #endif /* OWFPOOL_H_ */