1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/common/include/owfpool.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,108 @@
1.4 +/* Copyright (c) 2009 The Khronos Group Inc.
1.5 + *
1.6 + * Permission is hereby granted, free of charge, to any person obtaining a
1.7 + * copy of this software and/or associated documentation files (the
1.8 + * "Materials"), to deal in the Materials without restriction, including
1.9 + * without limitation the rights to use, copy, modify, merge, publish,
1.10 + * distribute, sublicense, and/or sell copies of the Materials, and to
1.11 + * permit persons to whom the Materials are furnished to do so, subject to
1.12 + * the following conditions:
1.13 + *
1.14 + * The above copyright notice and this permission notice shall be included
1.15 + * in all copies or substantial portions of the Materials.
1.16 + *
1.17 + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1.18 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1.19 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1.20 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1.21 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1.22 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1.23 + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
1.24 + */
1.25 +
1.26 +/*!
1.27 + * \file owfpool.h
1.28 + */
1.29 +#ifndef OWFPOOL_H_
1.30 +#define OWFPOOL_H_
1.31 +
1.32 +#include <stdlib.h>
1.33 +#include "owftypes.h"
1.34 +
1.35 +
1.36 +#ifdef __cplusplus
1.37 +extern "C"
1.38 +{
1.39 +#endif
1.40 +
1.41 +
1.42 +#define EOC (OWFuint32) 0xFFFFFFFF
1.43 +
1.44 +
1.45 +typedef struct
1.46 +{
1.47 + /*! linked list of free entries */
1.48 + OWFuint32* entries;
1.49 + /*! solid chunk of memory containing all the objects;
1.50 + * no book-keeping data here, plain sequentially
1.51 + * stored objects only */
1.52 + char* chunk;
1.53 + /*! index number of the first free object in the pool;
1.54 + * EOC if the pool is empty */
1.55 + OWFuint32 firstFree;
1.56 + /*! pools capacity */
1.57 + size_t capacity;
1.58 + /*! number of free (unallocated) objects in the pool */
1.59 + size_t free;
1.60 + /*! size of an object */
1.61 + size_t entrySize;
1.62 +} OWF_POOL;
1.63 +
1.64 +/*!
1.65 + * Creates new object pool. Initially all pool's
1.66 + * objects are unallocated.
1.67 + *
1.68 + * \param objectSize Size of an individual pool object
1.69 + * \param objectCount Pool capacity (number of objects)
1.70 + *
1.71 + * \return New pool or NULL
1.72 + */
1.73 +OWF_API_CALL OWF_POOL*
1.74 +OWF_Pool_Create(size_t objectSize, size_t objectCount);
1.75 +
1.76 +/*!
1.77 + * Allocate object from pool. The pool retains ownership of
1.78 + * the object returned by the function.
1.79 + *
1.80 + * \param pool Pool from which the object should be allocated
1.81 + *
1.82 + * \return Object or NULL
1.83 + */
1.84 +OWF_API_CALL void*
1.85 +OWF_Pool_GetObject(OWF_POOL* pool);
1.86 +
1.87 +/*!
1.88 + * Returns previously allocated object back to the pool.
1.89 + *
1.90 + * \param object Object (must be valid pool object)
1.91 + */
1.92 +OWF_API_CALL void
1.93 +OWF_Pool_PutObject(void* object);
1.94 +
1.95 +/*!
1.96 + * Destroys a pool. Frees all resources allocated by
1.97 + * the pool and invalidates all objects in the pool
1.98 + * (both allocated and unallocated)
1.99 + *
1.100 + * \param pool Pool to destroy
1.101 + */
1.102 +OWF_API_CALL void
1.103 +OWF_Pool_Destroy(OWF_POOL* pool);
1.104 +
1.105 +
1.106 +#ifdef __cplusplus
1.107 +}
1.108 +#endif
1.109 +
1.110 +
1.111 +#endif /* OWFPOOL_H_ */