mirror of
https://code.videolan.org/videolan/vlc
synced 2024-09-12 13:44:56 +02:00
Encapsulation des pthread qui sont maintenant remplac�es par les vlc_thread.
Toutes les r�f�rences aux pthread que ce soit les thread, les mutex ou les variables conditionnelles, ont �t� remplac�es par leur �quivalent vlc_thread. Les vlc_thread sont une version tr�s simplifi�e des pthread et fonctionnent exactement de la m�me fa�on. Ceci devrait grandement faciliter le portage vers d'autres OS. Polux
This commit is contained in:
parent
1e0d8c908a
commit
1d620095e8
@ -12,7 +12,6 @@
|
||||
*******************************************************************************/
|
||||
|
||||
/* System headers */
|
||||
#include <pthread.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/soundcard.h>
|
||||
#include <sys/uio.h>
|
||||
@ -23,6 +22,7 @@
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#include "mtime.h"
|
||||
#include "vlc_thread.h"
|
||||
|
||||
/* Input */
|
||||
#include "input.h"
|
||||
|
@ -5,8 +5,8 @@
|
||||
* = Prototyped functions are implemented in audio_decoder/audio_decoder.c
|
||||
*
|
||||
* = Required headers :
|
||||
* - <pthread.h> ( pthread_t )
|
||||
* - "common.h" ( u32, byte_t, boolean_t )
|
||||
* - "vlc_thread.h" ( vlc_thread_t )
|
||||
* - "input.h" ( ts_packet_t, input_thread_t )
|
||||
* - "decoder_fifo.h" ( decoder_fifo_t )
|
||||
* - "audio_output.h" ( aout_fifo_t, aout_thread_t )
|
||||
@ -48,7 +48,7 @@ typedef struct adec_thread_s
|
||||
/*
|
||||
* Thread properties
|
||||
*/
|
||||
pthread_t thread_id; /* id for pthread functions */
|
||||
vlc_thread_t thread_id; /* id for thread functions */
|
||||
boolean_t b_die; /* `die' flag */
|
||||
boolean_t b_error; /* `error' flag */
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
* (c)1999 VideoLAN
|
||||
******************************************************************************
|
||||
* Required headers:
|
||||
* - <pthread.h> ( pthread_t )
|
||||
* - <sys/soundcard.h> ( audio_buf_info )
|
||||
* - "common.h" ( boolean_t )
|
||||
* - "mtime.h" ( mtime_t )
|
||||
* - "vlc_thread.h" ( vlc_thread_t )
|
||||
******************************************************************************/
|
||||
|
||||
/* TODO :
|
||||
@ -131,8 +131,8 @@ typedef struct
|
||||
boolean_t b_stereo;
|
||||
long l_rate;
|
||||
|
||||
pthread_mutex_t data_lock;
|
||||
pthread_cond_t data_wait;
|
||||
vlc_mutex_t data_lock;
|
||||
vlc_cond_t data_wait;
|
||||
|
||||
void * buffer;
|
||||
mtime_t * date;
|
||||
@ -169,12 +169,12 @@ typedef struct
|
||||
******************************************************************************/
|
||||
typedef struct aout_thread_s
|
||||
{
|
||||
pthread_t thread_id;
|
||||
vlc_thread_t thread_id;
|
||||
boolean_t b_die;
|
||||
|
||||
aout_dsp_t dsp;
|
||||
|
||||
pthread_mutex_t fifos_lock;
|
||||
vlc_mutex_t fifos_lock;
|
||||
aout_fifo_t fifo[ AOUT_MAX_FIFOS ];
|
||||
|
||||
void * buffer;
|
||||
|
@ -7,13 +7,13 @@
|
||||
* to read or write informations from other threads.
|
||||
*******************************************************************************
|
||||
* Required headers:
|
||||
* <pthread.h>
|
||||
* <sys/uio.h>
|
||||
* <sys/uio.h>
|
||||
* <X11/Xlib.h>
|
||||
* <X11/extensions/XShm.h>
|
||||
* "config.h"
|
||||
* "common.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
* "input.h"
|
||||
* "video.h"
|
||||
* "video_output.h"
|
||||
|
@ -3,9 +3,9 @@
|
||||
* (c)1999 VideoLAN
|
||||
******************************************************************************
|
||||
* Required headers:
|
||||
* - <pthread.h>
|
||||
* - "config.h"
|
||||
* - "common.h"
|
||||
* - "vlc_thread.h"
|
||||
* - "input.h"
|
||||
******************************************************************************/
|
||||
|
||||
@ -31,8 +31,8 @@
|
||||
******************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutex_t data_lock; /* fifo data lock */
|
||||
pthread_cond_t data_wait; /* fifo data conditional variable */
|
||||
vlc_mutex_t data_lock; /* fifo data lock */
|
||||
vlc_cond_t data_wait; /* fifo data conditional variable */
|
||||
|
||||
/* buffer is an array of PES packets pointers */
|
||||
pes_packet_t * buffer[FIFO_SIZE + 1];
|
||||
@ -120,7 +120,7 @@ static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
|
||||
/* We are going to read/write the start and end indexes of the
|
||||
* decoder fifo and to use the fifo's conditional variable,
|
||||
* that's why we need to take the lock before */
|
||||
pthread_mutex_lock( &p_bit_stream->p_decoder_fifo->data_lock );
|
||||
vlc_mutex_lock( &p_bit_stream->p_decoder_fifo->data_lock );
|
||||
/* We should increase the start index of the decoder fifo, but
|
||||
* if we do this now, the input thread could overwrite the
|
||||
* pointer to the current PES packet, and we weren't able to
|
||||
@ -131,11 +131,11 @@ static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
|
||||
|
||||
while ( DECODER_FIFO_ISEMPTY(*p_bit_stream->p_decoder_fifo) )
|
||||
{
|
||||
pthread_cond_wait( &p_bit_stream->p_decoder_fifo->data_wait,
|
||||
vlc_cond_wait( &p_bit_stream->p_decoder_fifo->data_wait,
|
||||
&p_bit_stream->p_decoder_fifo->data_lock );
|
||||
if ( p_bit_stream->p_input->b_die )
|
||||
{
|
||||
pthread_mutex_unlock( &(p_bit_stream->p_decoder_fifo->data_lock) );
|
||||
vlc_mutex_unlock( &(p_bit_stream->p_decoder_fifo->data_lock) );
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
@ -144,7 +144,7 @@ static __inline__ byte_t GetByte( bit_stream_t * p_bit_stream )
|
||||
p_bit_stream->p_ts = DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->p_first_ts;
|
||||
|
||||
/* We can release the fifo's data lock */
|
||||
pthread_mutex_unlock( &p_bit_stream->p_decoder_fifo->data_lock );
|
||||
vlc_mutex_unlock( &p_bit_stream->p_decoder_fifo->data_lock );
|
||||
}
|
||||
/* Perhaps the next TS packet of the current PES packet contains
|
||||
* real data (ie its payload's size is greater than 0) */
|
||||
|
@ -3,10 +3,10 @@
|
||||
* (c)1999 VideoLAN
|
||||
*******************************************************************************
|
||||
* Requires:
|
||||
* <pthread.h>
|
||||
* "config.h"
|
||||
* "common.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
* "input.h"
|
||||
* "decoder_fifo.h"
|
||||
* ??
|
||||
@ -41,7 +41,7 @@ typedef struct gdec_thread_s
|
||||
boolean_t b_die; /* `die' flag */
|
||||
boolean_t b_error; /* `error' flag */
|
||||
boolean_t b_active; /* `active' flag */
|
||||
pthread_t thread_id; /* id for pthread functions */
|
||||
vlc_thread_t thread_id; /* id for thread functions */
|
||||
|
||||
/* Thread configuration */
|
||||
int i_actions; /* decoder actions */
|
||||
|
@ -207,7 +207,7 @@ typedef struct
|
||||
|
||||
typedef struct pcr_descriptor_struct
|
||||
{
|
||||
pthread_mutex_t lock; /* pcr modification lock */
|
||||
vlc_mutex_t lock; /* pcr modification lock */
|
||||
|
||||
mtime_t delta_clock;
|
||||
mtime_t delta_decode;
|
||||
@ -268,7 +268,7 @@ typedef struct
|
||||
*******************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutex_t lock; /* netlist modification lock */
|
||||
vlc_mutex_t lock; /* netlist modification lock */
|
||||
struct iovec p_ts_free[INPUT_MAX_TS + INPUT_TS_READ_ONCE];
|
||||
/* FIFO or LIFO of free TS packets */
|
||||
ts_packet_t * p_ts_packets;
|
||||
@ -317,9 +317,9 @@ typedef struct input_thread_struct
|
||||
/* Thread properties and locks */
|
||||
boolean_t b_die; /* 'die' flag */
|
||||
boolean_t b_error; /* deadlock */
|
||||
pthread_t thread_id; /* id for pthread functions */
|
||||
pthread_mutex_t programs_lock; /* programs modification lock */
|
||||
pthread_mutex_t es_lock; /* es modification lock */
|
||||
vlc_thread_t thread_id; /* id for thread functions */
|
||||
vlc_mutex_t programs_lock; /* programs modification lock */
|
||||
vlc_mutex_t es_lock; /* es modification lock */
|
||||
|
||||
/* Input method description */
|
||||
int i_method; /* input method */
|
||||
|
@ -36,7 +36,7 @@ static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
|
||||
ASSERT(p_pes_packet);
|
||||
|
||||
/* We will be playing with indexes, so we take a lock. */
|
||||
pthread_mutex_lock( &p_input->netlist.lock );
|
||||
vlc_mutex_lock( &p_input->netlist.lock );
|
||||
|
||||
/* Free all TS packets in this PES structure. */
|
||||
p_ts_packet = p_pes_packet->p_first_ts;
|
||||
@ -67,7 +67,7 @@ static __inline__ void input_NetlistFreePES( input_thread_t *p_input,
|
||||
p_input->netlist.i_pes_end &= INPUT_MAX_PES; /* loop */
|
||||
#endif
|
||||
|
||||
pthread_mutex_unlock( &p_input->netlist.lock );
|
||||
vlc_mutex_unlock( &p_input->netlist.lock );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@ -83,7 +83,7 @@ static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
|
||||
ASSERT(p_ts_packet);
|
||||
|
||||
/* We will be playing with indexes, so we take a lock. */
|
||||
pthread_mutex_lock( &p_input->netlist.lock );
|
||||
vlc_mutex_lock( &p_input->netlist.lock );
|
||||
|
||||
/* Free the TS structure. */
|
||||
#ifdef INPUT_LIFO_TS_NETLIST
|
||||
@ -95,7 +95,7 @@ static __inline__ void input_NetlistFreeTS( input_thread_t *p_input,
|
||||
p_input->netlist.i_ts_end &= INPUT_MAX_TS; /* loop */
|
||||
#endif
|
||||
|
||||
pthread_mutex_unlock( &p_input->netlist.lock );
|
||||
vlc_mutex_unlock( &p_input->netlist.lock );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@ -112,7 +112,7 @@ static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
|
||||
#ifdef INPUT_LIFO_PES_NETLIST
|
||||
/* i_pes_index might be accessed by a decoder thread to give back a
|
||||
* packet. */
|
||||
pthread_mutex_lock( &p_input->netlist.lock );
|
||||
vlc_mutex_lock( &p_input->netlist.lock );
|
||||
|
||||
/* Verify that we still have PES packet in the netlist */
|
||||
if( (INPUT_MAX_PES - p_input->netlist.i_pes_index ) <= 1 )
|
||||
@ -124,7 +124,7 @@ static __inline__ pes_packet_t* input_NetlistGetPES( input_thread_t *p_input )
|
||||
/* Fetch a new PES packet */
|
||||
p_pes_packet = p_input->netlist.p_pes_free[p_input->netlist.i_pes_index];
|
||||
p_input->netlist.i_pes_index++;
|
||||
pthread_mutex_unlock( &p_input->netlist.lock );
|
||||
vlc_mutex_unlock( &p_input->netlist.lock );
|
||||
|
||||
#else /* FIFO */
|
||||
/* No need to lock, since we are the only ones accessing i_pes_start. */
|
||||
|
@ -6,6 +6,7 @@
|
||||
*******************************************************************************
|
||||
* Required headers:
|
||||
* <netinet/in.h>
|
||||
* "vlc_thread.h"
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
@ -87,7 +88,7 @@ typedef struct
|
||||
*******************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutex_t lock; /* library lock */
|
||||
vlc_mutex_t lock; /* library lock */
|
||||
|
||||
/* Server */
|
||||
input_vlan_server_t server; /* vlan server */
|
||||
|
@ -6,13 +6,13 @@
|
||||
* interface, such as message output.
|
||||
******************************************************************************
|
||||
* Required headers:
|
||||
* <pthread.h>
|
||||
* <sys/uio.h>
|
||||
* <X11/Xlib.h>
|
||||
* <X11/extensions/XShm.h>
|
||||
* "config.h"
|
||||
* "common.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
* "input.h"
|
||||
* "video.h"
|
||||
* "video_output.h"
|
||||
|
@ -10,9 +10,9 @@
|
||||
* If INTF_MSG_QUEUE is not defined, output is directly performed on stderr.
|
||||
*******************************************************************************
|
||||
* required headers:
|
||||
* <pthread.h>
|
||||
* config.h
|
||||
* mtime.h
|
||||
* "config.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
*******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
@ -53,7 +53,7 @@ typedef struct
|
||||
{
|
||||
#ifdef INTF_MSG_QUEUE
|
||||
/* Message queue */
|
||||
pthread_mutex_t lock; /* message queue lock */
|
||||
vlc_mutex_t lock; /* message queue lock */
|
||||
int i_count; /* number of messages stored */
|
||||
interface_msg_message_t msg[INTF_MSG_QSIZE]; /* message queue */
|
||||
#endif
|
||||
|
@ -6,7 +6,6 @@
|
||||
* only be used by interface.
|
||||
*******************************************************************************
|
||||
* Required headers:
|
||||
* <pthread.h>
|
||||
* <netinet/in.h>
|
||||
* <sys/soundcard.h>
|
||||
* <sys/uio.h>
|
||||
@ -15,6 +14,7 @@
|
||||
* "config.h"
|
||||
* "common.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
* "input.h"
|
||||
* "input_vlan.h"
|
||||
* "audio_output.h"
|
||||
|
@ -4,10 +4,10 @@
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
* Requires:
|
||||
* <pthread.h>
|
||||
* "config.h"
|
||||
* "common.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
* "input.h"
|
||||
* "video.h"
|
||||
* "video_output.h"
|
||||
@ -26,7 +26,7 @@ typedef struct vdec_thread_s
|
||||
boolean_t b_run; /* `run' flag */
|
||||
boolean_t b_error; /* `error' flag */
|
||||
boolean_t b_active; /* `active' flag */
|
||||
pthread_t thread_id; /* id for pthread functions */
|
||||
vlc_thread_t thread_id; /* id for thread functions */
|
||||
|
||||
/* Thread configuration */
|
||||
/* ?? */
|
||||
|
@ -7,10 +7,10 @@
|
||||
* thread, and destroy a previously oppenned video output thread.
|
||||
*******************************************************************************
|
||||
* Requires:
|
||||
* <pthread.h>
|
||||
* "config.h"
|
||||
* "common.h"
|
||||
* "mtime.h"
|
||||
* "vlc_thread.h"
|
||||
* "video.h"
|
||||
*******************************************************************************/
|
||||
|
||||
@ -65,9 +65,9 @@ typedef struct vout_thread_s
|
||||
boolean_t b_die; /* `die' flag */
|
||||
boolean_t b_error; /* `error' flag */
|
||||
boolean_t b_active; /* `active' flag */
|
||||
pthread_t thread_id; /* id for pthread functions */
|
||||
pthread_mutex_t streams_lock; /* streams modification lock */
|
||||
pthread_mutex_t pictures_lock; /* pictures modification lock */
|
||||
vlc_thread_t thread_id; /* id for thread functions */
|
||||
vlc_mutex_t streams_lock; /* streams modification lock */
|
||||
vlc_mutex_t pictures_lock; /* pictures modification lock */
|
||||
int * pi_status; /* temporary status flag */
|
||||
|
||||
/* Common display properties */
|
||||
|
@ -6,7 +6,6 @@
|
||||
* not be needed by any other module than video_output.c.
|
||||
*******************************************************************************
|
||||
* Required headers:
|
||||
* <pthread.h>
|
||||
* <X11/Xlib.h>
|
||||
* <X11/Xutil.h>
|
||||
* <X11/extensions/XShm.h>
|
||||
|
120
include/vlc_thread.h
Normal file
120
include/vlc_thread.h
Normal file
@ -0,0 +1,120 @@
|
||||
/*******************************************************************************
|
||||
* vlc_thread.h : thread implementation for vieolan client
|
||||
* (c)1999 VideoLAN
|
||||
******************************************************************************/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/*******************************************************************************
|
||||
* types definition
|
||||
******************************************************************************/
|
||||
|
||||
typedef pthread_t vlc_thread_t;
|
||||
typedef pthread_mutex_t vlc_mutex_t;
|
||||
typedef pthread_cond_t vlc_cond_t;
|
||||
|
||||
typedef void *(*vlc_thread_func)(void *data);
|
||||
|
||||
/******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_thread_create ( vlc_thread_t * thread, char * name,
|
||||
vlc_thread_func func, void * data );
|
||||
static __inline__ void vlc_thread_exit ( );
|
||||
static __inline__ void vlc_thread_join ( vlc_thread_t thread );
|
||||
|
||||
static __inline__ int vlc_mutex_init ( vlc_mutex_t * mutex );
|
||||
static __inline__ int vlc_mutex_lock ( vlc_mutex_t * mutex );
|
||||
static __inline__ int vlc_mutex_unlock ( vlc_mutex_t * mtex );
|
||||
|
||||
static __inline__ int vlc_cond_init ( vlc_cond_t * condvar );
|
||||
static __inline__ int vlc_cond_signal ( vlc_cond_t * condvar );
|
||||
static __inline__ int vlc_cond_wait ( vlc_cond_t * condvar, vlc_mutex_t * mutex );
|
||||
|
||||
//static _inline__ int vlc_cond_timedwait ( vlc_cond_t * condvar, vlc_mutex_t * mutex,
|
||||
// mtime_t absoute_timeout_time );
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_thread_create
|
||||
******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_thread_create(
|
||||
vlc_thread_t * thread,
|
||||
char * name,
|
||||
vlc_thread_func func,
|
||||
void * data)
|
||||
{
|
||||
return pthread_create( thread, NULL, func, data );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* vlc_thread_exit
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ void vlc_thread_exit()
|
||||
{
|
||||
pthread_exit( 0 );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_thread_exit
|
||||
******************************************************************************/
|
||||
|
||||
static __inline__ void vlc_thread_join( vlc_thread_t thread )
|
||||
{
|
||||
pthread_join( thread, NULL );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_mutex_init
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_mutex_init( vlc_mutex_t * mutex )
|
||||
{
|
||||
return pthread_mutex_init( mutex, NULL );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_mutex_lock
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_mutex_lock( vlc_mutex_t * mutex )
|
||||
{
|
||||
return pthread_mutex_lock( mutex );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_mutex_unlock
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_mutex_unlock( vlc_mutex_t * mutex )
|
||||
{
|
||||
return pthread_mutex_unlock( mutex );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_cond_init
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_cond_init( vlc_cond_t * condvar )
|
||||
{
|
||||
return pthread_cond_init( condvar, NULL );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* vlc_cond_signal
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_cond_signal( vlc_cond_t * condvar )
|
||||
{
|
||||
return pthread_cond_signal( condvar );
|
||||
}
|
||||
/*******************************************************************************
|
||||
* vlc_cond_wait
|
||||
*******************************************************************************/
|
||||
|
||||
static __inline__ int vlc_cond_wait( vlc_cond_t * condvar, vlc_mutex_t * mutex )
|
||||
{
|
||||
return pthread_cond_wait( condvar, mutex );
|
||||
}
|
Loading…
Reference in New Issue
Block a user