static void libvlc_setup_threads (bool init) { static vlc_mutex_t lock = VLC_STATIC_MUTEX; static uintptr_t refs = 0; vlc_mutex_lock (&lock); if (init) { #ifdef ANDROID if (refs++ == 0) { vlc_threadvar_create (&context, free); pthread_cancel_initialize (); } #else if (refs++ == 0) vlc_threadvar_create (&context, free); #endif } else { #ifdef ANDROID if (--refs == 0) { vlc_threadvar_delete (&context); pthread_cancel_deinitialize (); } #else if (--refs == 0) vlc_threadvar_delete (&context); #endif } vlc_mutex_unlock (&lock); }
//BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) BOOL WINAPI _CRT_INIT (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) // sunqueen modify { (void) hinstDll; (void) lpvReserved; switch (fdwReason) { case DLL_PROCESS_ATTACH: InitializeCriticalSection (&clock_lock); vlc_mutex_init (&super_mutex); vlc_cond_init (&super_variable); vlc_threadvar_create (&thread_key, NULL); vlc_rwlock_init (&config_lock); vlc_CPU_init (); break; case DLL_PROCESS_DETACH: vlc_rwlock_destroy (&config_lock); vlc_threadvar_delete (&thread_key); vlc_cond_destroy (&super_variable); vlc_mutex_destroy (&super_mutex); DeleteCriticalSection (&clock_lock); break; } return TRUE; }
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) { (void) hinstDll; (void) lpvReserved; switch (fdwReason) { case DLL_PROCESS_ATTACH: #if (_WIN32_WINNT < 0x0601) if (!QueryPerformanceFrequency (&freq)) return FALSE; #endif vlc_mutex_init (&super_mutex); vlc_cond_init (&super_variable); vlc_threadvar_create (&thread_key, NULL); vlc_rwlock_init (&config_lock); vlc_rwlock_init (&msg_lock); vlc_CPU_init (); break; case DLL_PROCESS_DETACH: vlc_rwlock_destroy (&msg_lock); vlc_rwlock_destroy (&config_lock); vlc_threadvar_delete (&thread_key); vlc_cond_destroy (&super_variable); vlc_mutex_destroy (&super_mutex); break; } return TRUE; }
unsigned long _System _DLL_InitTerm(unsigned long hmod, unsigned long flag) { VLC_UNUSED (hmod); switch (flag) { case 0 : /* Initialization */ if(_CRT_init() == -1) return 0; vlc_mutex_init (&super_mutex); vlc_cond_init (&super_variable); vlc_threadvar_create (&thread_key, NULL); vlc_rwlock_init (&config_lock); vlc_rwlock_init (&msg_lock); vlc_CPU_init (); return 1; case 1 : /* Termination */ vlc_rwlock_destroy (&msg_lock); vlc_rwlock_destroy (&config_lock); vlc_threadvar_delete (&thread_key); vlc_cond_destroy (&super_variable); vlc_mutex_destroy (&super_mutex); _CRT_term(); return 1; } return 0; /* Failed */ }
/************************************************************************** * libvlc_event_async_fini (internal) : * * Destroy what might have been created by. **************************************************************************/ void libvlc_event_async_fini(libvlc_event_manager_t * p_em) { if(!is_queue_initialized(p_em)) return; if(current_thread_is_asynch_thread(p_em)) { fprintf(stderr, "*** Error: releasing the last reference of the observed object from its callback thread is not (yet!) supported\n"); abort(); } vlc_thread_t thread = queue(p_em)->thread; if(thread) { vlc_cancel(thread); vlc_join(thread, NULL); } vlc_mutex_destroy(&queue(p_em)->lock); vlc_cond_destroy(&queue(p_em)->signal); vlc_cond_destroy(&queue(p_em)->signal_idle); vlc_threadvar_delete(&queue(p_em)->is_asynch_dispatch_thread_var); struct queue_elmt * iter = queue(p_em)->elements; while (iter) { struct queue_elmt * elemt_to_delete = iter; iter = iter->next; free(elemt_to_delete); } free(queue(p_em)); }
/** * Deinitializes an interruption context. * The context shall no longer be used by any thread. */ void vlc_interrupt_deinit(vlc_interrupt_t *ctx) { assert(ctx->callback == NULL); assert(!ctx->attached); vlc_mutex_destroy(&ctx->lock); vlc_rwlock_wrlock(&vlc_interrupt_lock); assert(vlc_interrupt_refs > 0); if (--vlc_interrupt_refs == 0) vlc_threadvar_delete(&vlc_interrupt_var); vlc_rwlock_unlock(&vlc_interrupt_lock); }
/***************************************************************************** * vlc_threads_end: stop threads system ***************************************************************************** * FIXME: This function is far from being threadsafe. *****************************************************************************/ void vlc_threads_end( void ) { #if defined( LIBVLC_USE_PTHREAD ) pthread_mutex_lock( &once_mutex ); #endif assert( i_initializations > 0 ); if( i_initializations == 1 ) { vlc_object_release( p_root ); vlc_threadvar_delete( &msg_context_global_key ); #ifndef NDEBUG vlc_threadvar_delete( &thread_object_key ); #endif } i_initializations--; #if defined( LIBVLC_USE_PTHREAD ) pthread_mutex_unlock( &once_mutex ); #endif }
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) { (void) hinstDll; (void) lpvReserved; switch (fdwReason) { case DLL_PROCESS_ATTACH: vlc_mutex_init (&super_mutex); vlc_threadvar_create (&cancel_key, free); break; case DLL_PROCESS_DETACH: vlc_threadvar_delete( &cancel_key ); vlc_mutex_destroy (&super_mutex); break; } return TRUE; }
/** * Destroy the message queues * * This functions prints all messages remaining in the queues, * then frees all the allocated resources * No other messages interface functions should be called after this one. */ void msg_Destroy (msg_bank_t *bank) { if (unlikely(bank->i_sub != 0)) fputs ("stale interface subscribers (LibVLC might crash)\n", stderr); vlc_mutex_lock( &msg_stack_lock ); assert(banks > 0); if( --banks == 0 ) vlc_threadvar_delete( &msg_context ); vlc_mutex_unlock( &msg_stack_lock ); if (bank->locale != (locale_t)0) freelocale (bank->locale); vlc_dictionary_clear (&bank->enabled_objects, NULL, NULL); vlc_rwlock_destroy (&bank->lock); free (bank); }
/** * Destroy the message queues * * This functions prints all messages remaining in the queues, * then frees all the allocated resources * No other messages interface functions should be called after this one. */ void msg_Destroy (libvlc_int_t *p_libvlc) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); msg_bank_t *bank = libvlc_bank (p_libvlc); if( QUEUE.i_sub ) msg_Err( p_libvlc, "stale interface subscribers (VLC might crash)" ); vlc_mutex_lock( &msg_stack_lock ); assert(banks > 0); if( --banks == 0 ) vlc_threadvar_delete( &msg_context ); vlc_mutex_unlock( &msg_stack_lock ); #ifdef UNDER_CE CloseHandle( QUEUE.logfile ); #endif vlc_dictionary_clear( &priv->msg_enabled_objects, NULL, NULL ); vlc_cond_destroy (&bank->wait); vlc_mutex_destroy (&bank->lock); }