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