2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Peter Schlaile <peter@schlaile.de> 2005
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file memutil/MEM_CacheLimiterC-Api.h
28 #ifndef __MEM_CACHELIMITERC_API_H__
29 #define __MEM_CACHELIMITERC_API_H__
35 struct MEM_CacheLimiter_s;
36 struct MEM_CacheLimiterHandle_s;
38 typedef struct MEM_CacheLimiter_s MEM_CacheLimiterC;
39 typedef struct MEM_CacheLimiterHandle_s MEM_CacheLimiterHandleC;
41 /* function used to remove data from memory */
42 typedef void(*MEM_CacheLimiter_Destruct_Func)(void*);
44 /* function used to measure stored data element size */
45 typedef size_t(*MEM_CacheLimiter_DataSize_Func) (void*);
47 #ifndef __MEM_CACHELIMITER_H__
48 extern void MEM_CacheLimiter_set_maximum(size_t m);
49 extern int MEM_CacheLimiter_get_maximum(void);
50 #endif /* __MEM_CACHELIMITER_H__ */
52 * Create new MEM_CacheLimiter object
53 * managed objects are destructed with the data_destructor
55 * @param data_destructor
56 * @return A new MEM_CacheLimter object
59 extern MEM_CacheLimiterC * new_MEM_CacheLimiter(
60 MEM_CacheLimiter_Destruct_Func data_destructor,
61 MEM_CacheLimiter_DataSize_Func data_size);
64 * Delete MEM_CacheLimiter
66 * Frees the memory of the CacheLimiter but does not touch managed objects!
68 * @param This "This" pointer
71 extern void delete_MEM_CacheLimiter(MEM_CacheLimiterC * This);
76 * @param This "This" pointer, data data object to manage
77 * @return CacheLimiterHandle to ref, unref, touch the managed object
80 extern MEM_CacheLimiterHandleC * MEM_CacheLimiter_insert(
81 MEM_CacheLimiterC * This, void * data);
84 * Free objects until memory constraints are satisfied
86 * @param This "This" pointer
89 extern void MEM_CacheLimiter_enforce_limits(MEM_CacheLimiterC * This);
92 * Unmanage object previously inserted object.
93 * Does _not_ delete managed object!
95 * @param This "This" pointer, handle of object
98 extern void MEM_CacheLimiter_unmanage(MEM_CacheLimiterHandleC * handle);
102 * Raise priority of object (put it at the tail of the deletion chain)
104 * @param handle of object
107 extern void MEM_CacheLimiter_touch(MEM_CacheLimiterHandleC * handle);
110 * Increment reference counter. Objects with reference counter != 0 are _not_
113 * @param handle of object
116 extern void MEM_CacheLimiter_ref(MEM_CacheLimiterHandleC * handle);
119 * Decrement reference counter. Objects with reference counter != 0 are _not_
122 * @param handle of object
125 extern void MEM_CacheLimiter_unref(MEM_CacheLimiterHandleC * handle);
128 * Get reference counter.
130 * @param This "This" pointer, handle of object
133 extern int MEM_CacheLimiter_get_refcount(MEM_CacheLimiterHandleC * handle);
136 * Get pointer to managed object
138 * @param handle of object
141 extern void * MEM_CacheLimiter_get(MEM_CacheLimiterHandleC * handle);
148 #endif // __MEM_CACHELIMITERC_API_H__