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 */ }
/** * Initialize messages queues * This function initializes all message queues */ void msg_Create (libvlc_int_t *p_libvlc) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); msg_bank_t *bank = libvlc_bank (p_libvlc); vlc_mutex_init (&bank->lock); vlc_cond_init (&bank->wait); vlc_dictionary_init( &priv->msg_enabled_objects, 0 ); priv->msg_all_objects_enabled = true; QUEUE.i_sub = 0; QUEUE.pp_sub = NULL; #ifdef UNDER_CE QUEUE.logfile = CreateFile( L"vlc-log.txt", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL ); SetFilePointer( QUEUE.logfile, 0, NULL, FILE_END ); #endif vlc_mutex_lock( &msg_stack_lock ); if( banks++ == 0 ) vlc_threadvar_create( &msg_context, cleanup_msg_context ); vlc_mutex_unlock( &msg_stack_lock ); }
/** * Initializes an interruption context. */ void vlc_interrupt_init(vlc_interrupt_t *ctx) { vlc_rwlock_wrlock(&vlc_interrupt_lock); assert(vlc_interrupt_refs < UINT_MAX); if (vlc_interrupt_refs++ == 0) #ifndef NDEBUG vlc_threadvar_create(&vlc_interrupt_var, vlc_interrupt_destructor); #else vlc_threadvar_create(&vlc_interrupt_var, NULL); #endif vlc_rwlock_unlock(&vlc_interrupt_lock); vlc_mutex_init(&ctx->lock); ctx->interrupted = false; atomic_init(&ctx->killed, false); #ifndef NDEBUG ctx->attached = false; #endif ctx->callback = NULL; }
/***************************************************************************** * vlc_threads_init: initialize threads system ***************************************************************************** * This function requires lazy initialization of a global lock in order to * keep the library really thread-safe. Some architectures don't support this * and thus do not guarantee the complete reentrancy. *****************************************************************************/ int vlc_threads_init( void ) { int i_ret = VLC_SUCCESS; /* If we have lazy mutex initialization, use it. Otherwise, we just * hope nothing wrong happens. */ #if defined( LIBVLC_USE_PTHREAD ) pthread_mutex_lock( &once_mutex ); #endif if( i_initializations == 0 ) { p_root = vlc_custom_create( (vlc_object_t *)NULL, sizeof( *p_root ), VLC_OBJECT_GENERIC, "root" ); if( p_root == NULL ) { i_ret = VLC_ENOMEM; goto out; } /* We should be safe now. Do all the initialization stuff we want. */ #ifndef NDEBUG vlc_threadvar_create( &thread_object_key, NULL ); #endif vlc_threadvar_create( &msg_context_global_key, msg_StackDestroy ); } i_initializations++; out: /* If we have lazy mutex initialization support, unlock the mutex. * Otherwize, we are screwed. */ #if defined( LIBVLC_USE_PTHREAD ) pthread_mutex_unlock( &once_mutex ); #endif return i_ret; }
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; }
/** * Initialize messages queues * This function initializes all message queues */ msg_bank_t *msg_Create (void) { msg_bank_t *bank = malloc (sizeof (*bank)); vlc_rwlock_init (&bank->lock); vlc_dictionary_init (&bank->enabled_objects, 0); bank->all_objects_enabled = true; bank->i_sub = 0; bank->pp_sub = NULL; /* C locale to get error messages in English in the logs */ bank->locale = newlocale (LC_MESSAGES_MASK, "C", (locale_t)0); vlc_mutex_lock( &msg_stack_lock ); if( banks++ == 0 ) vlc_threadvar_create( &msg_context, cleanup_msg_context ); vlc_mutex_unlock( &msg_stack_lock ); return bank; }
/************************************************************************** * libvlc_event_async_init (private) : * * Destroy what might have been created by. **************************************************************************/ static void libvlc_event_async_init(libvlc_event_manager_t * p_em) { p_em->async_event_queue = calloc(1, sizeof(struct libvlc_event_async_queue)); int error = vlc_threadvar_create(&queue(p_em)->is_asynch_dispatch_thread_var, NULL); assert(!error); vlc_mutex_init(&queue(p_em)->lock); vlc_cond_init(&queue(p_em)->signal); vlc_cond_init(&queue(p_em)->signal_idle); error = vlc_clone (&queue(p_em)->thread, event_async_loop, p_em, VLC_THREAD_PRIORITY_LOW); if(error) { free(p_em->async_event_queue); p_em->async_event_queue = NULL; return; } }