From 6e2ed233dd40ccc93a20e6fdfbdfaca8cf9b8e51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 5 Oct 2008 12:40:24 +0300 Subject: [PATCH] Remove slow and leaking var_AcquireMutex --- include/vlc_variables.h | 19 ------------------- src/libvlccore.sym | 1 - src/misc/threads.c | 41 ----------------------------------------- 3 files changed, 61 deletions(-) diff --git a/include/vlc_variables.h b/include/vlc_variables.h index 9015b0b329..b43a44d25e 100644 --- a/include/vlc_variables.h +++ b/include/vlc_variables.h @@ -133,25 +133,6 @@ VLC_EXPORT( int, __var_Get, ( vlc_object_t *, const char *, vlc_value_t * ) ); #define var_Command(a,b,c,d,e) __var_Command( VLC_OBJECT( a ), b, c, d, e ) VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, const char *, char ** ) ); -VLC_EXPORT( vlc_mutex_t *, var_AcquireMutex, ( const char * ) LIBVLC_USED ); -#ifdef __GNUC__ -static -__attribute__((unused)) -__attribute__((noinline)) -__attribute__((error("variable mutex name leaks memory at run-time"))) -const char *nonconst_mutex_name( const char *str ) -{ - return str; -} - -# define check_named_mutex( m ) \ - (__builtin_constant_p(m) ? m : nonconst_mutex_name(m)) -#else -# define check_named_mutex( m ) (m) -#endif - -#define var_AcquireMutex( n ) var_AcquireMutex(check_named_mutex(n)) - /** * __var_Create() with automatic casting. */ diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 300e5ddf86..badcf07d78 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -411,7 +411,6 @@ utf8_scandir utf8_stat utf8_unlink utf8_vfprintf -var_AcquireMutex __var_AddCallback __var_Change __var_Command diff --git a/src/misc/threads.c b/src/misc/threads.c index 8d7f9ba3d4..19f4ded3e0 100644 --- a/src/misc/threads.c +++ b/src/misc/threads.c @@ -45,17 +45,6 @@ static vlc_threadvar_t cancel_key; #endif -static struct -{ - vlc_dictionary_t list; - vlc_mutex_t lock; -} named_mutexes = { - { 0, NULL, }, -#ifdef LIBVLC_USE_PTHREAD - PTHREAD_MUTEX_INITIALIZER, -#endif -}; - #ifdef HAVE_EXECINFO_H # include #endif @@ -167,8 +156,6 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) switch (fdwReason) { case DLL_PROCESS_ATTACH: - vlc_dictionary_init (&named_mutexes.list, 0); - vlc_mutex_init (&named_mutexes.lock); vlc_mutex_init (&super_mutex); vlc_threadvar_create (&cancel_key, free); break; @@ -176,8 +163,6 @@ BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) case DLL_PROCESS_DETACH: vlc_threadvar_delete( &cancel_key ); vlc_mutex_destroy (&super_mutex); - vlc_mutex_destroy (&named_mutexes.lock); - vlc_dictionary_clear (&named_mutexes.list); break; } return TRUE; @@ -1060,29 +1045,3 @@ void vlc_control_cancel (int cmd, ...) va_end (ap); #endif } - - -#undef var_AcquireMutex -/** - * Finds a process-wide mutex, creates it if needed, and locks it. - * Unlock with vlc_mutex_unlock(). - * FIXME: This is very inefficient, this is not memory-safe and this leaks - * memory. Use static locks instead. - */ -vlc_mutex_t *var_AcquireMutex( const char *name ) -{ - vlc_mutex_t *lock; - - vlc_mutex_lock (&named_mutexes.lock); - lock = vlc_dictionary_value_for_key (&named_mutexes.list, name); - if (lock == kVLCDictionaryNotFound) - { - lock = malloc (sizeof (*lock)); - vlc_mutex_init (lock); - vlc_dictionary_insert (&named_mutexes.list, name, lock); - } - vlc_mutex_unlock (&named_mutexes.lock); - - vlc_mutex_lock (lock); - return lock; -} -- 2.39.2