libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
{
+ libvlc_threads_init ();
+
libvlc_instance_t *p_new = malloc (sizeof (*p_new));
if (unlikely(p_new == NULL))
return NULL;
- libvlc_init_threads ();
-
const char *my_argv[argc + 2];
my_argv[0] = "libvlc"; /* dummy arg0, skipped by getopt() et al */
for( int i = 0; i < argc; i++ )
return p_new;
error:
- libvlc_deinit_threads ();
free (p_new);
+ libvlc_threads_deinit ();
return NULL;
}
libvlc_InternalCleanup( p_instance->p_libvlc_int );
libvlc_InternalDestroy( p_instance->p_libvlc_int );
free( p_instance );
- libvlc_deinit_threads ();
+ libvlc_threads_deinit ();
}
}
/* TODO: use only one thread-specific key for whole libvlc */
static vlc_threadvar_t context;
-static void libvlc_setup_threads (bool init)
-{
- static vlc_mutex_t lock = VLC_STATIC_MUTEX;
- static uintptr_t refs = 0;
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+static uintptr_t refs = 0;
+void libvlc_threads_init (void)
+{
vlc_mutex_lock (&lock);
- if (init)
- {
- if (refs++ == 0)
- vlc_threadvar_create (&context, free);
- }
- else
- {
- assert (refs > 0);
- if (--refs == 0)
- vlc_threadvar_delete (&context);
- }
+ if (refs++ == 0)
+ vlc_threadvar_create (&context, free);
vlc_mutex_unlock (&lock);
}
-void libvlc_init_threads (void)
+void libvlc_threads_deinit (void)
{
- libvlc_setup_threads (true);
-}
-
-void libvlc_deinit_threads (void)
-{
- libvlc_setup_threads (false);
+ vlc_mutex_lock (&lock);
+ assert (refs > 0);
+ if (--refs == 0)
+ vlc_threadvar_delete (&context);
+ vlc_mutex_unlock (&lock);
}
static char *get_error (void)
***************************************************************************/
/* Thread context */
-void libvlc_init_threads (void);
-void libvlc_deinit_threads (void);
+void libvlc_threads_init (void);
+void libvlc_threads_deinit (void);
/* Events */
libvlc_event_manager_t * libvlc_event_manager_new(