X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fthreads.c;h=fd84ad7270cc94de9779719290817947eacda60b;hb=f210514c93fdd60103f2c203d656b83da1ecda51;hp=1999c9ec4c91725d82499c83ecd1f0786be4e1cd;hpb=7f12470415d98e9e0ac725f2bb96b5fa74ef27f1;p=vlc diff --git a/src/misc/threads.c b/src/misc/threads.c index 1999c9ec4c..fd84ad7270 100644 --- a/src/misc/threads.c +++ b/src/misc/threads.c @@ -33,6 +33,7 @@ #include "libvlc.h" #include +#include #ifdef HAVE_UNISTD_H # include #endif @@ -41,7 +42,6 @@ # include #endif - struct vlc_thread_boot { void * (*entry) (vlc_object_t *); @@ -84,17 +84,6 @@ int vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line, /* Make sure we don't re-create a thread if the object has already one */ assert( !p_priv->b_thread ); -#if defined( LIBVLC_USE_PTHREAD ) -#ifndef __APPLE__ - if( config_GetInt( p_this, "rt-priority" ) > 0 ) -#endif - { - /* Hack to avoid error msg */ - if( config_GetType( p_this, "rt-offset" ) ) - i_priority += config_GetInt( p_this, "rt-offset" ); - } -#endif - p_priv->b_thread = true; i_ret = vlc_clone( &p_priv->thread_id, thread_entry, boot, i_priority ); if( i_ret == 0 ) @@ -111,12 +100,13 @@ int vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line, return i_ret; } +#undef vlc_thread_set_priority /***************************************************************************** * vlc_thread_set_priority: set the priority of the current thread when we * couldn't set it in vlc_thread_create (for instance for the main thread) *****************************************************************************/ -int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, - int i_line, int i_priority ) +int vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, + int i_line, int i_priority ) { vlc_object_internals_t *p_priv = vlc_internals( p_this ); @@ -128,7 +118,7 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, #if defined( LIBVLC_USE_PTHREAD ) # ifndef __APPLE__ - if( config_GetInt( p_this, "rt-priority" ) > 0 ) + if( var_InheritBool( p_this, "rt-priority" ) ) # endif { int i_error, i_policy; @@ -136,7 +126,7 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, memset( ¶m, 0, sizeof(struct sched_param) ); if( config_GetType( p_this, "rt-offset" ) ) - i_priority += config_GetInt( p_this, "rt-offset" ); + i_priority += var_InheritInteger( p_this, "rt-offset" ); if( i_priority <= 0 ) { param.sched_priority = (-1) * i_priority; @@ -160,7 +150,11 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, #elif defined( WIN32 ) || defined( UNDER_CE ) VLC_UNUSED( psz_file); VLC_UNUSED( i_line ); +#ifndef UNDER_CE + if( !SetThreadPriority(p_priv->thread_id, i_priority) ) +#else if( !SetThreadPriority(p_priv->thread_id->handle, i_priority) ) +#endif { msg_Warn( p_this, "couldn't set a faster priority" ); return 1; @@ -171,24 +165,21 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, return 0; } +#undef vlc_thread_join /***************************************************************************** * vlc_thread_join: wait until a thread exits, inner version *****************************************************************************/ -void __vlc_thread_join( vlc_object_t *p_this ) +void vlc_thread_join( vlc_object_t *p_this ) { vlc_object_internals_t *p_priv = vlc_internals( p_this ); -#if defined( LIBVLC_USE_PTHREAD ) - vlc_join (p_priv->thread_id, NULL); - -#elif defined( UNDER_CE ) || defined( WIN32 ) +#if defined( WIN32 ) && !defined( UNDER_CE ) HANDLE hThread; FILETIME create_ft, exit_ft, kernel_ft, user_ft; int64_t real_time, kernel_time, user_time; -#ifndef UNDER_CE if( ! DuplicateHandle(GetCurrentProcess(), - p_priv->thread_id->handle, + p_priv->thread_id, GetCurrentProcess(), &hThread, 0, @@ -198,12 +189,13 @@ void __vlc_thread_join( vlc_object_t *p_this ) p_priv->b_thread = false; return; /* We have a problem! */ } -#else - hThread = p_priv->thread_id->handle; #endif vlc_join( p_priv->thread_id, NULL ); +#if defined( WIN32 ) && !defined( UNDER_CE ) + /* FIXME: this could work on WinCE too... except that it seems always to + * return 0 for exit_ft and kernel_ft */ if( GetThreadTimes( hThread, &create_ft, &exit_ft, &kernel_ft, &user_ft ) ) { real_time = @@ -229,10 +221,6 @@ void __vlc_thread_join( vlc_object_t *p_this ) (double)((user_time%(60*1000000))/1000000.0) ); } CloseHandle( hThread ); - -#else - vlc_join( p_priv->thread_id, NULL ); - #endif p_priv->b_thread = false; @@ -245,3 +233,25 @@ void vlc_thread_cancel (vlc_object_t *obj) if (priv->b_thread) vlc_cancel (priv->thread_id); } + +/*** Global locks ***/ + +void vlc_global_mutex (unsigned n, bool acquire) +{ + static vlc_mutex_t locks[] = { + VLC_STATIC_MUTEX, + VLC_STATIC_MUTEX, + VLC_STATIC_MUTEX, + }; + assert (n < (sizeof (locks) / sizeof (locks[0]))); + vlc_mutex_t *lock = locks + n; + + if (acquire) + vlc_mutex_lock (lock); + else + vlc_mutex_unlock (lock); + + /* Compile-time assertion ;-) */ + char enough_locks[(sizeof (locks) / sizeof (locks[0])) - VLC_MAX_MUTEX]; + (void) enough_locks; +}