X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fthreads.c;h=c2c8ef9788dd95c0f4418e7b878d5e8169a7aa0f;hb=267cd7f9b7dac986e6d2bc490f778107be95a8fc;hp=dbe7c590f3995009e67c1514eaf960d8092650f1;hpb=0894ff443403be47932a6b0dedbaefa9114b36a6;p=vlc diff --git a/src/misc/threads.c b/src/misc/threads.c index dbe7c590f3..c2c8ef9788 100644 --- a/src/misc/threads.c +++ b/src/misc/threads.c @@ -20,7 +20,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #include @@ -49,19 +49,6 @@ static vlc_object_t *p_root; #elif defined( HAVE_CTHREADS_H ) #endif -/***************************************************************************** - * Global variable for named mutexes - *****************************************************************************/ -typedef struct vlc_namedmutex_t vlc_namedmutex_t; -struct vlc_namedmutex_t -{ - vlc_mutex_t lock; - - char *psz_name; - int i_usage; - vlc_namedmutex_t *p_next; -}; - /***************************************************************************** * vlc_threads_init: initialize threads system ***************************************************************************** @@ -71,7 +58,7 @@ struct vlc_namedmutex_t *****************************************************************************/ int __vlc_threads_init( vlc_object_t *p_this ) { - libvlc_t *p_libvlc = (libvlc_t *)p_this; + libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_this; int i_ret = VLC_SUCCESS; /* If we have lazy mutex initialization, use it. Otherwise, we just @@ -91,7 +78,7 @@ int __vlc_threads_init( vlc_object_t *p_this ) i_status = VLC_THREADS_PENDING; /* We should be safe now. Do all the initialization stuff we want. */ - p_libvlc->b_ready = VLC_FALSE; + p_libvlc_global->b_ready = VLC_FALSE; #if defined( PTH_INIT_IN_PTH_H ) i_ret = ( pth_init() == FALSE ); @@ -112,25 +99,25 @@ int __vlc_threads_init( vlc_object_t *p_this ) hInstLib = LoadLibrary( "kernel32" ); if( hInstLib ) { - p_libvlc->SignalObjectAndWait = + p_libvlc_global->SignalObjectAndWait = (SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib, "SignalObjectAndWait" ); } } else { - p_libvlc->SignalObjectAndWait = NULL; + p_libvlc_global->SignalObjectAndWait = NULL; } - p_libvlc->b_fast_mutex = 0; - p_libvlc->i_win9x_cv = 0; + p_libvlc_global->b_fast_mutex = 0; + p_libvlc_global->i_win9x_cv = 0; #elif defined( HAVE_KERNEL_SCHEDULER_H ) #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) #elif defined( HAVE_CTHREADS_H ) #endif - p_root = vlc_object_create( p_libvlc, VLC_OBJECT_ROOT ); + p_root = vlc_object_create( p_libvlc_global, VLC_OBJECT_GLOBAL ); if( p_root == NULL ) i_ret = VLC_ENOMEM; @@ -243,8 +230,8 @@ int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex ) * function and have a 100% correct vlc_cond_wait() implementation. * As this function is not available on Win9x, we can use the faster * CriticalSections */ - if( p_this->p_libvlc->SignalObjectAndWait && - !p_this->p_libvlc->b_fast_mutex ) + if( p_this->p_libvlc_global->SignalObjectAndWait && + !p_this->p_libvlc_global->b_fast_mutex ) { /* We are running on NT/2K/XP, we can use SignalObjectAndWait */ p_mutex->mutex = CreateMutex( 0, FALSE, 0 ); @@ -304,7 +291,7 @@ int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex ) /***************************************************************************** * vlc_mutex_destroy: destroy a mutex, inner version *****************************************************************************/ -int __vlc_mutex_destroy( char * psz_file, int i_line, vlc_mutex_t *p_mutex ) +int __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex ) { int i_result; /* In case of error : */ @@ -393,10 +380,11 @@ int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar ) p_condvar->i_waiting_threads = 0; /* Misc init */ - p_condvar->i_win9x_cv = p_this->p_libvlc->i_win9x_cv; - p_condvar->SignalObjectAndWait = p_this->p_libvlc->SignalObjectAndWait; + p_condvar->i_win9x_cv = p_this->p_libvlc_global->i_win9x_cv; + p_condvar->SignalObjectAndWait = p_this->p_libvlc_global->SignalObjectAndWait; - if( (p_condvar->SignalObjectAndWait && !p_this->p_libvlc->b_fast_mutex) + if( (p_condvar->SignalObjectAndWait && + !p_this->p_libvlc_global->b_fast_mutex) || p_condvar->i_win9x_cv == 0 ) { /* Create an auto-reset event. */ @@ -460,7 +448,7 @@ int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar ) /***************************************************************************** * vlc_cond_destroy: destroy a condition, inner version *****************************************************************************/ -int __vlc_cond_destroy( char * psz_file, int i_line, vlc_cond_t *p_condvar ) +int __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar ) { int i_result; /* In case of error : */ @@ -518,8 +506,8 @@ int __vlc_cond_destroy( char * psz_file, int i_line, vlc_cond_t *p_condvar ) * Note that i_priority is only taken into account on platforms supporting * userland real-time priority threads. *****************************************************************************/ -int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line, - char *psz_name, void * ( *func ) ( void * ), +int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line, + const char *psz_name, void * ( *func ) ( void * ), int i_priority, vlc_bool_t b_wait ) { int i_ret; @@ -571,13 +559,18 @@ int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line, #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) i_ret = pthread_create( &p_this->thread_id, NULL, func, p_data ); - if( config_GetType( p_this, "rt-priority" ) && config_GetInt( p_this, "rt-priority" ) ) +#ifndef __APPLE__ + if( config_GetInt( p_this, "rt-priority" ) ) +#endif { int i_error, i_policy; struct sched_param param; memset( ¶m, 0, sizeof(struct sched_param) ); - i_priority += config_GetInt( p_this, "rt-offset" ); + if( config_GetType( p_this, "rt-offset" ) ) + { + i_priority += config_GetInt( p_this, "rt-offset" ); + } if( i_priority <= 0 ) { param.sched_priority = (-1) * i_priority; @@ -596,10 +589,12 @@ int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line, i_priority = 0; } } +#ifndef __APPLE__ else { i_priority = 0; } +#endif #elif defined( HAVE_CTHREADS_H ) p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_data ); @@ -625,13 +620,8 @@ int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line, } else { -#ifdef HAVE_STRERROR msg_Err( p_this, "%s thread could not be created at %s:%d (%s)", psz_name, psz_file, i_line, strerror(i_ret) ); -#else - msg_Err( p_this, "%s thread could not be created at %s:%d", - psz_name, psz_file, i_line ); -#endif vlc_mutex_unlock( &p_this->object_lock ); } @@ -642,7 +632,7 @@ int __vlc_thread_create( vlc_object_t *p_this, char * psz_file, int i_line, * 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, char * psz_file, +int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file, int i_line, int i_priority ) { #if defined( PTH_INIT_IN_PTH_H ) || defined( ST_INIT_IN_ST_H ) @@ -654,13 +644,18 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, char * psz_file, } #elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) - if( config_GetType( p_this, "rt-priority" ) && config_GetInt( p_this, "rt-priority" ) ) +#ifndef __APPLE__ + if( config_GetInt( p_this, "rt-priority" ) ) +#endif { int i_error, i_policy; struct sched_param param; memset( ¶m, 0, sizeof(struct sched_param) ); - i_priority += config_GetInt( p_this, "rt-offset" ); + if( config_GetType( p_this, "rt-offset" ) ) + { + i_priority += config_GetInt( p_this, "rt-offset" ); + } if( i_priority <= 0 ) { param.sched_priority = (-1) * i_priority; @@ -699,7 +694,7 @@ void __vlc_thread_ready( vlc_object_t *p_this ) /***************************************************************************** * vlc_thread_join: wait until a thread exits, inner version *****************************************************************************/ -void __vlc_thread_join( vlc_object_t *p_this, char * psz_file, int i_line ) +void __vlc_thread_join( vlc_object_t *p_this, const char * psz_file, int i_line ) { int i_ret = 0; @@ -770,14 +765,9 @@ void __vlc_thread_join( vlc_object_t *p_this, char * psz_file, int i_line ) if( i_ret ) { -#ifdef HAVE_STRERROR msg_Err( p_this, "thread_join(%u) failed at %s:%d (%s)", (unsigned int)p_this->thread_id, psz_file, i_line, strerror(i_ret) ); -#else - msg_Err( p_this, "thread_join(%u) failed at %s:%d", - (unsigned int)p_this->thread_id, psz_file, i_line ); -#endif } else {