# HG changeset patch # User nenolod # Date 1167453482 28800 # Node ID e0d7335f56c31a0dc46256d95cde8a8c48d3e485 # Parent 4de6e7d138c677c481ccf0884209eb4e9924469a [svn] - MemoryPool, a simple performance-oriented memory pool. diff -r 4de6e7d138c6 -r e0d7335f56c3 ChangeLog --- a/ChangeLog Fri Dec 29 19:51:55 2006 -0800 +++ b/ChangeLog Fri Dec 29 20:38:02 2006 -0800 @@ -1,3 +1,13 @@ +2006-12-30 03:51:55 +0000 William Pitcock + revision [3449] + - make SIGTERM work in a threadsafe manner. + + trunk/audacious/main.c | 1 + + trunk/audacious/main.h | 1 + + trunk/audacious/signals.c | 25 +++++++++++++++++++++---- + 3 files changed, 23 insertions(+), 4 deletions(-) + + 2006-12-29 22:33:09 +0000 Giacomo Lozito revision [3447] - deletion of the last playlist is now handled directly in playlist_remove_playlist (patch by Joker) ; small code changes in playlist manager diff -r 4de6e7d138c6 -r e0d7335f56c3 audacious/Makefile --- a/audacious/Makefile Fri Dec 29 19:51:55 2006 -0800 +++ b/audacious/Makefile Fri Dec 29 20:38:02 2006 -0800 @@ -81,7 +81,8 @@ iir_fpu.c \ signals.c \ strings.c \ - pixbuf_effects.c + pixbuf_effects.c \ + memorypool.c OBJECTS = ${SOURCES:.c=.o} diff -r 4de6e7d138c6 -r e0d7335f56c3 audacious/memorypool.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audacious/memorypool.c Fri Dec 29 20:38:02 2006 -0800 @@ -0,0 +1,107 @@ +/* Audacious + * Copyright (c) 2007 William Pitcock + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "memorypool.h" + +/* visibility of this object is not available to the outside */ +struct _MemoryPool { + GList *stack; + GDestroyNotify notify; + GMutex *mutex; +}; + +MemoryPool * +memory_pool_new(void) +{ + MemoryPool *pool; + + pool = g_new0(MemoryPool, 1); + pool->notify = g_free; + pool->mutex = g_mutex_new(); + + return pool; +} + +MemoryPool * +memory_pool_with_custom_destructor(GDestroyNotify notify) +{ + MemoryPool *pool; + + pool = g_new0(MemoryPool, 1); + pool->notify = notify; + pool->mutex = g_mutex_new(); + + return pool; +} + +gpointer +memory_pool_allocate(MemoryPool * pool, gsize sz) +{ + gpointer addr; + + g_mutex_lock(pool->mutex); + addr = g_malloc0(sz); + pool->stack = g_list_append(pool->stack, addr); + g_mutex_unlock(pool->mutex); + + return addr; +} + +void +memory_pool_release(MemoryPool * pool, gpointer addr) +{ + g_mutex_lock(pool->mutex); + + pool->stack = g_list_remove(pool->stack, addr); + pool->notify(addr); + + g_mutex_unlock(pool->mutex); +} + +static void +memory_pool_cleanup_nolock(MemoryPool * pool) +{ + GList *iter; + + for (iter = pool->stack; iter != NULL; iter = g_list_next(iter)) + { + pool->stack = g_list_delete_link(pool->stack, iter); + g_warning("MemoryPool<%p> element at %p was not released until cleanup!", pool, iter->data); + pool->notify(iter->data); + } +} + +void +memory_pool_cleanup(MemoryPool * pool) +{ + g_mutex_lock(pool->mutex); + memory_pool_cleanup_nolock(pool); + g_mutex_unlock(pool->mutex); +} + +void +memory_pool_destroy(MemoryPool * pool) +{ + g_mutex_lock(pool->mutex); + memory_pool_cleanup_nolock(pool); + g_mutex_unlock(pool->mutex); + + g_mutex_free(pool->mutex); + g_free(pool); +} diff -r 4de6e7d138c6 -r e0d7335f56c3 audacious/memorypool.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/audacious/memorypool.h Fri Dec 29 20:38:02 2006 -0800 @@ -0,0 +1,33 @@ +/* Audacious + * Copyright (c) 2007 William Pitcock + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef AUDACIOUS_MEMORYPOOL_H +#define AUDACIOUS_MEMORYPOOL_H + +typedef struct _MemoryPool MemoryPool; + +MemoryPool * memory_pool_new(void); +MemoryPool * memory_pool_with_custom_destructor(GDestroyNotify notify); + +gpointer memory_pool_allocate(MemoryPool * pool, gsize sz); +void memory_pool_release(MemoryPool * pool, gpointer addr); + +void memory_pool_cleanup(MemoryPool * pool); + +void memory_pool_destroy(MemoryPool * pool); + +#endif