Put back callback handlers in mempool implementation.

This commit is contained in:
alexhudson
2009-07-16 06:57:04 +00:00
parent 20f8e515f2
commit 8bb3ebbec0
+26 -1
View File
@@ -13,6 +13,9 @@ MemPrivatePoolZeroCallback(void *buffer, void *clientData)
struct MemPoolPrivateRef {
size_t size;
PoolEntryCB on_alloc;
PoolEntryCB on_free;
void *client_data;
};
EXPORT void *
@@ -22,6 +25,9 @@ MemPrivatePoolAlloc(unsigned char *name, size_t AllocationSize, unsigned int Min
ref = g_new0(struct MemPoolPrivateRef, 1);
ref->size = AllocationSize;
ref->on_alloc = allocCB;
ref->on_free = freeCB;
ref->client_data = clientData;
return (ref);
}
@@ -36,9 +42,22 @@ MemPrivatePoolFree(void *PoolHandle)
EXPORT void *
MemPrivatePoolGetEntryDirect(void *PoolHandle, const char *SourceFile, unsigned long SourceLine)
{
BOOL result = FALSE;
struct MemPoolPrivateRef *ref = (struct MemPoolPrivateRef *)PoolHandle;
return g_slice_alloc0(ref->size);
void *new = g_slice_alloc0(ref->size);
if (ref->on_alloc != NULL) {
PoolEntryCB callback = ref->on_alloc;
result = callback(new, ref->client_data);
}
if (result) {
return new;
} else {
g_slice_free1(ref->size, new);
return NULL;
}
}
EXPORT void
@@ -46,6 +65,12 @@ MemPrivatePoolReturnEntryDirect(void *PoolHandle, void *Source, const char *Sour
{
struct MemPoolPrivateRef *ref = (struct MemPoolPrivateRef *)PoolHandle;
if (ref->on_free != NULL) {
PoolEntryCB callback = ref->on_free;
callback(Source, ref->client_data);
}
g_slice_free1(ref->size, Source);
return;
}