graphicscomposition/openwfcompositionengine/common/include/owfpool.h
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 /* Copyright (c) 2009 The Khronos Group Inc.
       
     2  *
       
     3  * Permission is hereby granted, free of charge, to any person obtaining a
       
     4  * copy of this software and/or associated documentation files (the
       
     5  * "Materials"), to deal in the Materials without restriction, including
       
     6  * without limitation the rights to use, copy, modify, merge, publish,
       
     7  * distribute, sublicense, and/or sell copies of the Materials, and to
       
     8  * permit persons to whom the Materials are furnished to do so, subject to
       
     9  * the following conditions:
       
    10  *
       
    11  * The above copyright notice and this permission notice shall be included
       
    12  * in all copies or substantial portions of the Materials.
       
    13  *
       
    14  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
       
    18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
       
    19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
       
    20  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    21  */
       
    22 
       
    23 /*!
       
    24  *  \file owfpool.h
       
    25  */
       
    26 #ifndef OWFPOOL_H_
       
    27 #define OWFPOOL_H_
       
    28 
       
    29 #include <stdlib.h>
       
    30 #include "owftypes.h"
       
    31 
       
    32 
       
    33 #ifdef __cplusplus
       
    34 extern "C"
       
    35 {
       
    36 #endif
       
    37 
       
    38 
       
    39 #define EOC         (OWFuint32) 0xFFFFFFFF
       
    40 
       
    41 
       
    42 typedef struct
       
    43 {
       
    44     /*! linked list of free entries */
       
    45     OWFuint32* entries;
       
    46     /*! solid chunk of memory containing all the objects;
       
    47      * no book-keeping data here, plain sequentially
       
    48      * stored objects only */
       
    49     char* chunk;
       
    50     /*! index number of the first free object in the pool;
       
    51      * EOC if the pool is empty */
       
    52     OWFuint32 firstFree;
       
    53     /*! pools capacity */
       
    54     size_t capacity;
       
    55     /*! number of free (unallocated) objects in the pool */
       
    56     size_t free;
       
    57     /*! size of an object */
       
    58     size_t entrySize;
       
    59 } OWF_POOL;
       
    60 
       
    61 /*!
       
    62  *  Creates new object pool. Initially all pool's
       
    63  *  objects are unallocated.
       
    64  *
       
    65  *  \param objectSize Size of an individual pool object
       
    66  *  \param objectCount Pool capacity (number of objects)
       
    67  *
       
    68  *  \return New pool or NULL
       
    69  */
       
    70 OWF_API_CALL OWF_POOL*
       
    71 OWF_Pool_Create(size_t objectSize, size_t objectCount);
       
    72 
       
    73 /*!
       
    74  *  Allocate object from pool. The pool retains ownership of
       
    75  *  the object returned by the function.
       
    76  *
       
    77  *  \param pool Pool from which the object should be allocated
       
    78  *
       
    79  *  \return Object or NULL
       
    80  */
       
    81 OWF_API_CALL void*
       
    82 OWF_Pool_GetObject(OWF_POOL* pool);
       
    83 
       
    84 /*!
       
    85  *  Returns previously allocated object back to the pool.
       
    86  *
       
    87  *  \param object Object (must be valid pool object)
       
    88  */
       
    89 OWF_API_CALL void
       
    90 OWF_Pool_PutObject(void* object);
       
    91 
       
    92 /*!
       
    93  *  Destroys a pool. Frees all resources allocated by
       
    94  *  the pool and invalidates all objects in the pool
       
    95  *  (both allocated and unallocated)
       
    96  *
       
    97  *  \param pool Pool to destroy
       
    98  */
       
    99 OWF_API_CALL void
       
   100 OWF_Pool_Destroy(OWF_POOL* pool);
       
   101 
       
   102 
       
   103 #ifdef __cplusplus
       
   104 }
       
   105 #endif
       
   106 
       
   107 
       
   108 #endif /* OWFPOOL_H_ */