gst/gstinfo.c: Add mutex to serialise access to the hash table with the function pointer => function name string mapp...

Original commit message from CVS:
Reviewed by: Tim-Philipp Müller  <tim at centricular dot net>
* gst/gstinfo.c: (_gst_debug_nameof_funcptr),
(_gst_debug_register_funcptr):
Add mutex to serialise access to the hash table with
the function pointer => function name string mapping;
make that hash table static scope (#316809).
This commit is contained in:
Tim-Philipp Müller 2005-09-21 21:36:00 +00:00
parent a07f338da8
commit 66ce301647
2 changed files with 27 additions and 7 deletions

View file

@ -1,4 +1,15 @@
2005-09-13 Steve Lhomme <steve.lhomme@free.fr> 2005-09-21 Francis Labonte <francis_labonte at hotmail dot com>
Reviewed by: Tim-Philipp Müller <tim at centricular dot net>
* gst/gstinfo.c: (_gst_debug_nameof_funcptr),
(_gst_debug_register_funcptr):
Add mutex to serialise access to the hash table with
the function pointer => function name string mapping;
make that hash table static scope (#316809).
2005-09-13 Steve Lhomme <steve.lhomme@free.fr>
* win32/config.h: * win32/config.h:
update some defines for cleaner and better compilation update some defines for cleaner and better compilation
* win32/gst-typefind.vcproj: * win32/gst-typefind.vcproj:

View file

@ -1038,7 +1038,9 @@ gst_debug_get_all_categories (void)
/*** FUNCTION POINTERS ********************************************************/ /*** FUNCTION POINTERS ********************************************************/
GHashTable *__gst_function_pointers = NULL; static GHashTable *__gst_function_pointers; /* NULL */
static GStaticMutex __dbg_functions_mutex = G_STATIC_MUTEX_INIT;
const gchar * const gchar *
_gst_debug_nameof_funcptr (void *ptr) _gst_debug_nameof_funcptr (void *ptr)
G_GNUC_NO_INSTRUMENT; G_GNUC_NO_INSTRUMENT;
@ -1052,8 +1054,11 @@ _gst_debug_nameof_funcptr (void *ptr)
Dl_info dlinfo; Dl_info dlinfo;
#endif #endif
if (__gst_function_pointers if (__gst_function_pointers) {
&& (ptrname = g_hash_table_lookup (__gst_function_pointers, ptr))) { g_static_mutex_lock (&__dbg_functions_mutex);
ptrname = g_hash_table_lookup (__gst_function_pointers, ptr);
g_static_mutex_unlock (&__dbg_functions_mutex);
if (ptrname)
return ptrname; return ptrname;
} }
/* we need to create an entry in the hash table for this one so we don't leak /* we need to create an entry in the hash table for this one so we don't leak
@ -1077,11 +1082,15 @@ _gst_debug_nameof_funcptr (void *ptr)
void * void *
_gst_debug_register_funcptr (void *ptr, gchar * ptrname) _gst_debug_register_funcptr (void *ptr, gchar * ptrname)
{ {
g_static_mutex_lock (&__dbg_functions_mutex);
if (!__gst_function_pointers) if (!__gst_function_pointers)
__gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal); __gst_function_pointers = g_hash_table_new (g_direct_hash, g_direct_equal);
if (!g_hash_table_lookup (__gst_function_pointers, ptr)) if (!g_hash_table_lookup (__gst_function_pointers, ptr))
g_hash_table_insert (__gst_function_pointers, ptr, ptrname); g_hash_table_insert (__gst_function_pointers, ptr, ptrname);
g_static_mutex_unlock (&__dbg_functions_mutex);
return ptr; return ptr;
} }