xref: /Universal-ctags/main/objpool.h (revision e013efc125e8f9eb50fe3e63e8c4146ef731f9b2)
1 /*
2 *   Copyright (c) 2016, Jiri Techet
3 *
4 *   This source code is released for free distribution under the terms of the
5 *   GNU General Public License version 2 or (at your option) any later version.
6 *
7 *   Defines generic pool for object reuse reducing the amount of allocations
8 *   and deallocations.
9 */
10 #ifndef CTAGS_MAIN_OBJPOOL_H
11 #define CTAGS_MAIN_OBJPOOL_H
12 
13 /*
14 *   INCLUDE FILES
15 */
16 #include "general.h"  /* must always come first */
17 
18 #include "ptrarray.h"
19 
20 /*
21 *   DATA DECLARATIONS
22 */
23 typedef void * (*objPoolCreateFunc) (void *createArg);
24 typedef void (*objPoolDeleteFunc) (void *data);
25 typedef void (*objPoolClearFunc) (void *data);
26 
27 struct sObjPool;
28 typedef struct sObjPool objPool;
29 
30 /*
31 *   FUNCTION PROTOTYPES
32 */
33 extern objPool *objPoolNew (unsigned int size,
34 	objPoolCreateFunc createFunc, objPoolDeleteFunc deleteFunc, objPoolClearFunc clearFunc,
35 	void *createArg);
36 extern void objPoolDelete (objPool *pool);
37 extern void *objPoolGet (objPool *pool);
38 extern void objPoolPut (objPool *pool, void *obj);
39 
40 #endif  /* CTAGS_MAIN_OBJPOOL_H */
41