Commit 2935b320 authored by Sam Hocevar's avatar Sam Hocevar

  * ./include/threads.h: support for the State Threads Library, a userland
    threads library (http://state-threads.sourceforge.net/). Useless to most
    people, but can be handy to debug stuff. Activate with `--enable-st'.
parent 83bd9d36
This diff is collapsed.
......@@ -759,6 +759,20 @@ AC_ARG_ENABLE(pth,
fi])
])
dnl
dnl State Threads
dnl
AC_ARG_ENABLE(st,
[ --enable-st Enable State Threads (default disabled)],
[ if test x$enableval = xyes; then
AC_CHECK_LIB(st,st_init)
AC_EGREP_HEADER(st_init,st.h,[
AC_DEFINE(ST_INIT_IN_ST_H, 1,
Define if <st.h> defines st_init)
THREAD_LIB="-lst"
fi])
])
LIB="${LIB} ${THREAD_LIB}"
dnl
......
......@@ -313,6 +313,9 @@
/* Define if you have the pth library (-lpth). */
#undef HAVE_LIBPTH
/* Define if you have the st library (-lst). */
#undef HAVE_LIBST
/* css decryption with player keys */
#undef HAVE_CSSKEYS
......@@ -413,6 +416,9 @@
/* Define if <pth.h> defines pth_init */
#undef PTH_INIT_IN_PTH_H
/* Define if <st.h> defines st_init */
#undef ST_INIT_IN_ST_H
/* Indicate whether we should use SDL/SDL.h or SDL11/SDL.h */
#undef SDL_INCLUDE_FILE
......@@ -3,7 +3,7 @@
* This header provides a portable threads implementation.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: threads.h,v 1.34 2002/01/04 14:01:34 sam Exp $
* $Id: threads.h,v 1.35 2002/02/25 23:59:07 sam Exp $
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@via.ecp.fr>
......@@ -32,6 +32,9 @@
#if defined( PTH_INIT_IN_PTH_H ) /* GNU Pth */
# include <pth.h>
#elif defined( ST_INIT_IN_ST_H ) /* State threads */
# include <st.h>
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H ) /* pthreads (like Linux & BSD) */
# include <pthread.h>
/* This is not prototyped under Linux, though it exists. */
......@@ -92,6 +95,11 @@ typedef pth_t vlc_thread_t;
typedef pth_mutex_t vlc_mutex_t;
typedef pth_cond_t vlc_cond_t;
#elif defined( ST_INIT_IN_ST_H )
typedef st_thread_t * vlc_thread_t;
typedef st_mutex_t * vlc_mutex_t;
typedef st_cond_t * vlc_cond_t;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
typedef pthread_t vlc_thread_t;
typedef pthread_mutex_t vlc_mutex_t;
......@@ -200,6 +208,9 @@ static __inline__ int vlc_threads_init( void )
#if defined( PTH_INIT_IN_PTH_H )
return pth_init();
#elif defined( ST_INIT_IN_ST_H )
return st_init();
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
return 0;
......@@ -223,6 +234,9 @@ static __inline__ int vlc_threads_end( void )
#if defined( PTH_INIT_IN_PTH_H )
return pth_kill();
#elif defined( ST_INIT_IN_ST_H )
return 0;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
return 0;
......@@ -246,6 +260,10 @@ static __inline__ int vlc_mutex_init( vlc_mutex_t *p_mutex )
#if defined( PTH_INIT_IN_PTH_H )
return pth_mutex_init( p_mutex );
#elif defined( ST_INIT_IN_ST_H )
*p_mutex = st_mutex_new();
return ( *p_mutex == NULL ) ? errno : 0;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
# if defined(DEBUG) && defined(SYS_LINUX)
/* Create error-checking mutex to detect threads problems more easily. */
......@@ -311,6 +329,9 @@ static __inline__ int _vlc_mutex_lock( char * psz_file, int i_line,
#if defined( PTH_INIT_IN_PTH_H )
return pth_mutex_acquire( p_mutex, TRUE, NULL );
#elif defined( ST_INIT_IN_ST_H )
return st_mutex_lock( *p_mutex );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
int i_return = pthread_mutex_lock( p_mutex );
if( i_return )
......@@ -364,6 +385,9 @@ static __inline__ int _vlc_mutex_unlock( char * psz_file, int i_line,
#if defined( PTH_INIT_IN_PTH_H )
return pth_mutex_release( p_mutex );
#elif defined( ST_INIT_IN_ST_H )
return st_mutex_unlock( *p_mutex );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
int i_return = pthread_mutex_unlock( p_mutex );
if( i_return )
......@@ -415,6 +439,9 @@ static __inline__ int _vlc_mutex_destroy( char * psz_file, int i_line,
#if defined( PTH_INIT_IN_PTH_H )
return 0;
#elif defined( ST_INIT_IN_ST_H )
return st_mutex_destroy( *p_mutex );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
int i_return = pthread_mutex_destroy( p_mutex );
if( i_return )
......@@ -451,6 +478,10 @@ static __inline__ int vlc_cond_init( vlc_cond_t *p_condvar )
#if defined( PTH_INIT_IN_PTH_H )
return pth_cond_init( p_condvar );
#elif defined( ST_INIT_IN_ST_H )
*p_condvar = st_cond_new();
return ( *p_condvar == NULL ) ? errno : 0;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
return pthread_cond_init( p_condvar, NULL );
......@@ -501,6 +532,9 @@ static __inline__ int vlc_cond_signal( vlc_cond_t *p_condvar )
#if defined( PTH_INIT_IN_PTH_H )
return pth_cond_notify( p_condvar, FALSE );
#elif defined( ST_INIT_IN_ST_H )
return st_cond_signal( *p_condvar );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
return pthread_cond_signal( p_condvar );
......@@ -577,6 +611,9 @@ static __inline__ int vlc_cond_broadcast( vlc_cond_t *p_condvar )
#if defined( PTH_INIT_IN_PTH_H )
return pth_cond_notify( p_condvar, FALSE );
#elif defined( ST_INIT_IN_ST_H )
return st_cond_broadcast( p_condvar );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
return pthread_cond_broadcast( p_condvar );
......@@ -656,6 +693,15 @@ static __inline__ int _vlc_cond_wait( char * psz_file, int i_line,
#if defined( PTH_INIT_IN_PTH_H )
return pth_cond_await( p_condvar, p_mutex, NULL );
#elif defined( ST_INIT_IN_ST_H )
int i_ret;
st_mutex_unlock( *p_mutex );
i_ret = st_cond_wait( *p_condvar );
st_mutex_lock( *p_mutex );
return i_ret;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
#ifndef DEBUG
......@@ -762,6 +808,9 @@ static __inline__ int _vlc_cond_destroy( char * psz_file, int i_line,
#if defined( PTH_INIT_IN_PTH_H )
return 0;
#elif defined( ST_INIT_IN_ST_H )
return st_cond_destroy( *p_condvar );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
int i_result = pthread_cond_destroy( p_condvar );
if( i_result )
......@@ -824,6 +873,10 @@ static __inline__ int _vlc_thread_create( char * psz_file, int i_line,
*p_thread = pth_spawn( PTH_ATTR_DEFAULT, func, p_data );
i_ret = ( p_thread == NULL );
#elif defined( ST_INIT_IN_ST_H )
*p_thread = st_thread_create( func, p_data, 1, 0 );
i_ret = ( p_thread == NULL );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_ret = pthread_create( p_thread, NULL, func, p_data );
......@@ -888,6 +941,10 @@ static __inline__ void vlc_thread_exit( void )
#if defined( PTH_INIT_IN_PTH_H )
pth_exit( 0 );
#elif defined( ST_INIT_IN_ST_H )
int result;
st_thread_exit( &result );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_exit( 0 );
......@@ -928,6 +985,9 @@ static __inline__ void _vlc_thread_join( char * psz_file, int i_line,
#if defined( PTH_INIT_IN_PTH_H )
i_ret = pth_join( thread, NULL );
#elif defined( ST_INIT_IN_ST_H )
i_ret = st_thread_join( thread, NULL );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
i_ret = pthread_join( thread, NULL );
......
......@@ -4,7 +4,7 @@
* decoders.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: input.c,v 1.176 2002/02/24 20:51:10 gbazin Exp $
* $Id: input.c,v 1.177 2002/02/25 23:59:07 sam Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
......@@ -76,7 +76,7 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static void RunThread ( input_thread_t *p_input );
static int RunThread ( input_thread_t *p_input );
static int InitThread ( input_thread_t *p_input );
static void ErrorThread ( input_thread_t *p_input );
static void CloseThread ( input_thread_t *p_input );
......@@ -206,8 +206,8 @@ input_thread_t *input_CreateThread ( playlist_item_t *p_item, int *pi_status )
intf_WarnMsg( 1, "input: playlist item `%s'", p_input->p_source );
/* Create thread. */
if( vlc_thread_create( &p_input->thread_id, "input", (void *) RunThread,
(void *) p_input ) )
if( vlc_thread_create( &p_input->thread_id, "input",
(vlc_thread_func_t)RunThread, (void *) p_input ) )
{
intf_ErrMsg( "input error: can't create input thread (%s)",
strerror(errno) );
......@@ -271,6 +271,7 @@ void input_DestroyThread( input_thread_t *p_input )
/* Destroy Mutex locks */
vlc_mutex_destroy( &p_input->stream.control.control_lock );
vlc_cond_destroy( &p_input->stream.stream_wait );
vlc_mutex_destroy( &p_input->stream.stream_lock );
/* Free input structure */
......@@ -282,7 +283,7 @@ void input_DestroyThread( input_thread_t *p_input )
*****************************************************************************
* Thread in charge of processing the network packets and demultiplexing.
*****************************************************************************/
static void RunThread( input_thread_t *p_input )
static int RunThread( input_thread_t *p_input )
{
if( InitThread( p_input ) )
{
......@@ -291,7 +292,7 @@ static void RunThread( input_thread_t *p_input )
p_input->b_error = 1;
ErrorThread( p_input );
DestroyThread( p_input );
return;
return 0;
}
p_input->i_status = THREAD_READY;
......@@ -440,6 +441,8 @@ static void RunThread( input_thread_t *p_input )
EndThread( p_input );
DestroyThread( p_input );
return 0;
}
/*****************************************************************************
......
......@@ -3,7 +3,7 @@
* Functions are prototyped in mtime.h.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: mtime.c,v 1.27 2001/12/30 07:09:56 sam Exp $
* $Id: mtime.c,v 1.28 2002/02/25 23:59:07 sam Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
......@@ -166,6 +166,9 @@ void mwait( mtime_t date )
# if defined( PTH_INIT_IN_PTH_H )
pth_usleep( delay );
# elif defined( ST_INIT_IN_ST_H )
st_usleep( delay );
# elif defined( HAVE_USLEEP )
usleep( delay );
......@@ -191,10 +194,10 @@ void msleep( mtime_t delay )
snooze( delay );
#elif defined( PTH_INIT_IN_PTH_H )
struct timeval tv_delay;
tv_delay.tv_sec = delay / 1000000;
tv_delay.tv_usec = delay % 1000000;
pth_select( 0, NULL, NULL, NULL, &tv_delay );
pth_usleep( delay );
#elif defined( ST_INIT_IN_ST_H )
st_usleep( delay );
#elif defined( HAVE_USLEEP )
usleep( delay );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment