- * vlc_threads_end: stop threads system
- *****************************************************************************
- * FIXME: This function is far from being threadsafe.
- *****************************************************************************/
-int __vlc_threads_end( vlc_object_t *p_this )
-{
- (void)p_this;
-#if defined( UNDER_CE )
-#elif defined( WIN32 )
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-#elif defined( LIBVLC_USE_PTHREAD )
- pthread_mutex_lock( &once_mutex );
-#endif
-
- if( i_initializations == 0 )
- return VLC_EGENERIC;
-
- i_initializations--;
- if( i_initializations == 0 )
- {
- i_status = VLC_THREADS_UNINITIALIZED;
- vlc_object_destroy( p_root );
- }
-
-#if defined( UNDER_CE )
-#elif defined( WIN32 )
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
-#elif defined( LIBVLC_USE_PTHREAD )
- pthread_mutex_unlock( &once_mutex );
-#endif
- return VLC_SUCCESS;
-}
-
-#ifdef __linux__
-/* This is not prototyped under Linux, though it exists. */
-int pthread_mutexattr_setkind_np( pthread_mutexattr_t *attr, int kind );
-#endif
-
-/*****************************************************************************
- * vlc_mutex_init: initialize a mutex
- *****************************************************************************/
-int __vlc_mutex_init( vlc_mutex_t *p_mutex )
-{
-#if defined( UNDER_CE )
- InitializeCriticalSection( &p_mutex->csection );
- return 0;
-
-#elif defined( WIN32 )
- /* We use mutexes on WinNT/2K/XP because we can use the SignalObjectAndWait
- * 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( pf_SignalObjectAndWait && !b_fast_mutex )
- {
- /* We are running on NT/2K/XP, we can use SignalObjectAndWait */
- p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
- return ( p_mutex->mutex != NULL ? 0 : 1 );
- }
- else
- {
- p_mutex->mutex = NULL;
- InitializeCriticalSection( &p_mutex->csection );
- return 0;
- }
-
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- /* check the arguments and whether it's already been initialized */
- if( p_mutex == NULL )
- {
- return B_BAD_VALUE;
- }
-
- if( p_mutex->init == 9999 )
- {
- return EALREADY;
- }
-
- p_mutex->lock = create_sem( 1, "BeMutex" );
- if( p_mutex->lock < B_NO_ERROR )
- {
- return( -1 );
- }
-
- p_mutex->init = 9999;
- return B_OK;
-
-#elif defined( LIBVLC_USE_PTHREAD )
-# ifndef NDEBUG
- {
- /* Create error-checking mutex to detect problems more easily. */
- pthread_mutexattr_t attr;
- int i_result;
-
- pthread_mutexattr_init( &attr );
-# if defined(SYS_LINUX)
- pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
-# else
- pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
-# endif
-
- i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
- pthread_mutexattr_destroy( &attr );
- return( i_result );
- }
-# endif /* NDEBUG */
- return pthread_mutex_init( &p_mutex->mutex, NULL );
-
-#endif
-}
-
-/*****************************************************************************
- * vlc_mutex_init: initialize a recursive mutex (Do not use)
- *****************************************************************************/
-int __vlc_mutex_init_recursive( vlc_mutex_t *p_mutex )
-{
-#if defined( WIN32 )
- /* Create mutex returns a recursive mutex */
- p_mutex->mutex = CreateMutex( 0, FALSE, 0 );
- return ( p_mutex->mutex != NULL ? 0 : 1 );
-#elif defined( LIBVLC_USE_PTHREAD )
- pthread_mutexattr_t attr;
- int i_result;
-
- pthread_mutexattr_init( &attr );
-# ifndef NDEBUG
- /* Create error-checking mutex to detect problems more easily. */
-# if defined(SYS_LINUX)
- pthread_mutexattr_setkind_np( &attr, PTHREAD_MUTEX_ERRORCHECK_NP );
-# else
- pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
-# endif
-# endif
- pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
- i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
- pthread_mutexattr_destroy( &attr );
- return( i_result );
-#else
-# error Unimplemented!
-#endif
-}
-
-
-/*****************************************************************************
- * vlc_mutex_destroy: destroy a mutex, inner version
- *****************************************************************************/
-void __vlc_mutex_destroy( const char * psz_file, int i_line, vlc_mutex_t *p_mutex )
-{
-#if defined( UNDER_CE )
- DeleteCriticalSection( &p_mutex->csection );
-
-#elif defined( WIN32 )
- if( p_mutex->mutex )
- CloseHandle( p_mutex->mutex );
- else
- DeleteCriticalSection( &p_mutex->csection );
-
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- if( p_mutex->init == 9999 )
- delete_sem( p_mutex->lock );
-
- p_mutex->init = 0;
-
-#elif defined( LIBVLC_USE_PTHREAD )
- int val = pthread_mutex_destroy( &p_mutex->mutex );
- VLC_THREAD_ASSERT ("destroying mutex");
-
-#endif
-}
-
-/*****************************************************************************
- * vlc_cond_init: initialize a condition
- *****************************************************************************/
-int __vlc_cond_init( vlc_cond_t *p_condvar )
-{
-#if defined( UNDER_CE )
- /* Initialize counter */
- p_condvar->i_waiting_threads = 0;
-
- /* Create an auto-reset event. */
- p_condvar->event = CreateEvent( NULL, /* no security */
- FALSE, /* auto-reset event */
- FALSE, /* start non-signaled */
- NULL ); /* unnamed */
- return !p_condvar->event;
-
-#elif defined( WIN32 )
- /* Initialize counter */
- p_condvar->i_waiting_threads = 0;
-
- /* Misc init */
- p_condvar->i_win9x_cv = i_win9x_cv;
- p_condvar->SignalObjectAndWait = pf_SignalObjectAndWait;
-
- if( (p_condvar->SignalObjectAndWait && !b_fast_mutex)
- || p_condvar->i_win9x_cv == 0 )
- {
- /* Create an auto-reset event. */
- p_condvar->event = CreateEvent( NULL, /* no security */
- FALSE, /* auto-reset event */
- FALSE, /* start non-signaled */
- NULL ); /* unnamed */
-
- p_condvar->semaphore = NULL;
- return !p_condvar->event;
- }
- else
- {
- p_condvar->semaphore = CreateSemaphore( NULL, /* no security */
- 0, /* initial count */
- 0x7fffffff, /* max count */
- NULL ); /* unnamed */
-
- if( p_condvar->i_win9x_cv == 1 )
- /* Create a manual-reset event initially signaled. */
- p_condvar->event = CreateEvent( NULL, TRUE, TRUE, NULL );
- else
- /* Create a auto-reset event. */
- p_condvar->event = CreateEvent( NULL, FALSE, FALSE, NULL );
-
- InitializeCriticalSection( &p_condvar->csection );
-
- return !p_condvar->semaphore || !p_condvar->event;
- }
-
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- if( !p_condvar )
- {
- return B_BAD_VALUE;
- }
-
- if( p_condvar->init == 9999 )
- {
- return EALREADY;
- }
-
- p_condvar->thread = -1;
- p_condvar->init = 9999;
- return 0;
-
-#elif defined( LIBVLC_USE_PTHREAD )
- pthread_condattr_t attr;
- int ret;
-
- ret = pthread_condattr_init (&attr);
- if (ret)
- return ret;
-
-# if !defined (_POSIX_CLOCK_SELECTION)
- /* Fairly outdated POSIX support (that was defined in 2001) */
-# define _POSIX_CLOCK_SELECTION (-1)
-# endif
-# if (_POSIX_CLOCK_SELECTION >= 0)
- /* NOTE: This must be the same clock as the one in mtime.c */
- pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
-# endif
-
- ret = pthread_cond_init (&p_condvar->cond, &attr);
- pthread_condattr_destroy (&attr);
- return ret;
-
-#endif
-}
-
-/*****************************************************************************
- * vlc_cond_destroy: destroy a condition, inner version
- *****************************************************************************/
-void __vlc_cond_destroy( const char * psz_file, int i_line, vlc_cond_t *p_condvar )
-{
-#if defined( UNDER_CE )
- CloseHandle( p_condvar->event );
-
-#elif defined( WIN32 )
- if( !p_condvar->semaphore )
- CloseHandle( p_condvar->event );
- else
- {
- CloseHandle( p_condvar->event );
- CloseHandle( p_condvar->semaphore );
- }
-
- if( p_condvar->semaphore != NULL )
- DeleteCriticalSection( &p_condvar->csection );
-
-#elif defined( HAVE_KERNEL_SCHEDULER_H )
- p_condvar->init = 0;
-
-#elif defined( LIBVLC_USE_PTHREAD )
- int val = pthread_cond_destroy( &p_condvar->cond );
- VLC_THREAD_ASSERT ("destroying condition");
-
-#endif
-}
-
-/*****************************************************************************
- * vlc_tls_create: create a thread-local variable
- *****************************************************************************/
-int __vlc_threadvar_create( vlc_threadvar_t *p_tls )
-{
- int i_ret = -1;
-
-#if defined( HAVE_KERNEL_SCHEDULER_H )
-# error Unimplemented!
-#elif defined( UNDER_CE ) || defined( WIN32 )
-#elif defined( WIN32 )
- p_tls->handle = TlsAlloc();
- i_ret = !( p_tls->handle == 0xFFFFFFFF );
-
-#elif defined( LIBVLC_USE_PTHREAD )
- i_ret = pthread_key_create( &p_tls->handle, NULL );
-#endif
- return i_ret;
-}
-
-/*****************************************************************************
- * vlc_thread_create: create a thread, inner version