/*****************************************************************************
* threads.c : threads implementation for the VideoLAN client
*****************************************************************************
- * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
- * $Id: threads.c,v 1.41 2003/08/28 17:19:41 sam Exp $
+ * Copyright (C) 1999, 2000, 2001, 2002, 2003 VideoLAN
+ * $Id: threads.c,v 1.44 2003/11/22 00:41:07 titer Exp $
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
#elif defined( ST_INIT_IN_ST_H )
#elif defined( UNDER_CE )
#elif defined( WIN32 )
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
#elif defined( HAVE_CTHREADS_H )
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
#endif
/*****************************************************************************
#elif defined( UNDER_CE )
#elif defined( WIN32 )
HINSTANCE hInstLib;
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_mutex_lock( &once_mutex );
#elif defined( HAVE_CTHREADS_H )
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
#endif
if( i_status == VLC_THREADS_UNINITIALIZED )
p_libvlc->b_fast_mutex = 0;
p_libvlc->i_win9x_cv = 0;
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
#elif defined( HAVE_CTHREADS_H )
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
#endif
vlc_object_create( p_libvlc, VLC_OBJECT_ROOT );
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( WIN32 )
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+ while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_mutex_unlock( &once_mutex );
#elif defined( HAVE_CTHREADS_H )
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#endif
if( i_status != VLC_THREADS_READY )
#elif defined( WIN32 )
i_initializations--;
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+ i_initializations--;
+
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_mutex_lock( &once_mutex );
i_initializations--;
#elif defined( HAVE_CTHREADS_H )
i_initializations--;
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- i_initializations--;
-
#endif
return VLC_SUCCESS;
}
return 0;
}
-#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
-# if defined(DEBUG) && defined(SYS_LINUX)
- {
- /* Create error-checking mutex to detect problems more easily. */
- pthread_mutexattr_t attr;
- int i_result;
-
- pthread_mutexattr_init( &attr );
- pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
- i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
- pthread_mutexattr_destroy( &attr );
- return( i_result );
- }
-# endif
- return pthread_mutex_init( &p_mutex->mutex, NULL );
-
-#elif defined( HAVE_CTHREADS_H )
- mutex_init( p_mutex );
- return 0;
-
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* check the arguments and whether it's already been initialized */
if( p_mutex == NULL )
p_mutex->init = 9999;
return B_OK;
+#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
+# if defined(DEBUG) && defined(SYS_LINUX)
+ {
+ /* Create error-checking mutex to detect problems more easily. */
+ pthread_mutexattr_t attr;
+ int i_result;
+
+ pthread_mutexattr_init( &attr );
+ pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
+ i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
+ pthread_mutexattr_destroy( &attr );
+ return( i_result );
+ }
+# endif
+ return pthread_mutex_init( &p_mutex->mutex, NULL );
+
+#elif defined( HAVE_CTHREADS_H )
+ mutex_init( p_mutex );
+ return 0;
+
#endif
}
}
return 0;
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+ if( p_mutex->init == 9999 )
+ {
+ delete_sem( p_mutex->lock );
+ }
+
+ p_mutex->init = 0;
+ return B_OK;
+
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_result = pthread_mutex_destroy( &p_mutex->mutex );
if ( i_result )
#elif defined( HAVE_CTHREADS_H )
return 0;
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- if( p_mutex->init == 9999 )
- {
- delete_sem( p_mutex->lock );
- }
-
- p_mutex->init = 0;
- return B_OK;
#endif
if( i_result )
return !p_condvar->semaphore || !p_condvar->event;
}
-#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
- return pthread_cond_init( &p_condvar->cond, NULL );
-
-#elif defined( HAVE_CTHREADS_H )
- /* condition_init() */
- spin_lock_init( &p_condvar->lock );
- cthread_queue_init( &p_condvar->queue );
- p_condvar->name = 0;
- p_condvar->implications = 0;
-
- return 0;
-
#elif defined( HAVE_KERNEL_SCHEDULER_H )
if( !p_condvar )
{
p_condvar->thread = -1;
p_condvar->init = 9999;
return 0;
+
+#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
+ return pthread_cond_init( &p_condvar->cond, NULL );
+
+#elif defined( HAVE_CTHREADS_H )
+ /* condition_init() */
+ spin_lock_init( &p_condvar->lock );
+ cthread_queue_init( &p_condvar->queue );
+ p_condvar->name = 0;
+ p_condvar->implications = 0;
+
+ return 0;
+
#endif
}
i_result = !CloseHandle( p_condvar->event )
|| !CloseHandle( p_condvar->semaphore );
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+ p_condvar->init = 0;
+ return 0;
+
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_result = pthread_cond_destroy( &p_condvar->cond );
if ( i_result )
#elif defined( HAVE_CTHREADS_H )
return 0;
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- p_condvar->init = 0;
- return 0;
#endif
if( i_result )
i_ret = ( p_this->thread_id ? 0 : 1 );
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+ p_this->thread_id = spawn_thread( (thread_func)func, psz_name,
+ i_priority, p_data );
+ i_ret = resume_thread( p_this->thread_id );
+
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_ret = pthread_create( &p_this->thread_id, NULL, func, p_data );
-#ifdef SYS_DARWIN
- if ( i_priority )
+ if ( i_priority
+#ifndef SYS_DARWIN
+ && config_GetInt( p_this, "rt-priority" )
+#endif
+ )
{
int i_error, i_policy;
struct sched_param param;
i_priority = 0;
}
}
-#endif
+ else
+ {
+ i_priority = 0;
+ }
#elif defined( HAVE_CTHREADS_H )
p_this->thread_id = cthread_fork( (cthread_fn_t)func, (any_t)p_data );
i_ret = 0;
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- p_this->thread_id = spawn_thread( (thread_func)func, psz_name,
- i_priority, p_data );
- i_ret = resume_thread( p_this->thread_id );
-
#endif
if( i_ret == 0 )
if ( (i_error = pthread_setschedparam( pthread_self(),
i_policy, ¶m )) )
{
- msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
+ msg_Warn( p_this, "couldn't set thread priority (%s:%d): %s",
psz_file, i_line, strerror(i_error) );
i_priority = 0;
}
#elif defined( WIN32 )
WaitForSingleObject( p_this->thread_id, INFINITE );
+#elif defined( HAVE_KERNEL_SCHEDULER_H )
+ int32_t exit_value;
+ wait_for_thread( p_this->thread_id, &exit_value );
+
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_ret = pthread_join( p_this->thread_id, NULL );
cthread_join( p_this->thread_id );
i_ret = 1;
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- int32 exit_value;
- wait_for_thread( p_this->thread_id, &exit_value );
-
#endif
if( i_ret )