Commit 6e2ed233 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Remove slow and leaking var_AcquireMutex

parent e3984284
......@@ -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.
*/
......
......@@ -411,7 +411,6 @@ utf8_scandir
utf8_stat
utf8_unlink
utf8_vfprintf
var_AcquireMutex
__var_AddCallback
__var_Change
__var_Command
......
......@@ -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 <execinfo.h>
#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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment