Commit 673ce32a authored by Loren Merritt's avatar Loren Merritt

don't overwrite pthread* namespace, because system headers might define those...

don't overwrite pthread* namespace, because system headers might define those functions even if we don't want them


git-svn-id: svn://svn.videolan.org/x264/trunk@679 df754926-b1dd-0310-bc7b-ec298dee348c
parent 5c49545c
......@@ -236,7 +236,7 @@ struct x264_t
x264_param_t param;
x264_t *thread[X264_THREAD_MAX];
pthread_t thread_handle;
x264_pthread_t thread_handle;
int b_thread_active;
int i_thread_phase; /* which thread to use for the next frame */
......
......@@ -128,8 +128,8 @@ x264_frame_t *x264_frame_new( x264_t *h )
for( j = 0; j < h->param.i_bframe + 2; j++ )
CHECKED_MALLOC( frame->i_row_satds[i][j], i_lines/16 * sizeof(int) );
pthread_mutex_init( &frame->mutex, NULL );
pthread_cond_init( &frame->cv, NULL );
x264_pthread_mutex_init( &frame->mutex, NULL );
x264_pthread_cond_init( &frame->cv, NULL );
return frame;
......@@ -155,8 +155,8 @@ void x264_frame_delete( x264_frame_t *frame )
x264_free( frame->mv[1] );
x264_free( frame->ref[0] );
x264_free( frame->ref[1] );
pthread_mutex_destroy( &frame->mutex );
pthread_cond_destroy( &frame->cv );
x264_pthread_mutex_destroy( &frame->mutex );
x264_pthread_cond_destroy( &frame->cv );
x264_free( frame );
}
......@@ -809,18 +809,18 @@ void x264_deblock_init( int cpu, x264_deblock_function_t *pf )
#ifdef HAVE_PTHREAD
void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed )
{
pthread_mutex_lock( &frame->mutex );
x264_pthread_mutex_lock( &frame->mutex );
frame->i_lines_completed = i_lines_completed;
pthread_cond_broadcast( &frame->cv );
pthread_mutex_unlock( &frame->mutex );
x264_pthread_cond_broadcast( &frame->cv );
x264_pthread_mutex_unlock( &frame->mutex );
}
void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed )
{
pthread_mutex_lock( &frame->mutex );
x264_pthread_mutex_lock( &frame->mutex );
while( frame->i_lines_completed < i_lines_completed )
pthread_cond_wait( &frame->cv, &frame->mutex );
pthread_mutex_unlock( &frame->mutex );
x264_pthread_cond_wait( &frame->cv, &frame->mutex );
x264_pthread_mutex_unlock( &frame->mutex );
}
#else
......
......@@ -73,8 +73,8 @@ typedef struct
/* threading */
int i_lines_completed; /* in pixels */
int i_reference_count; /* number of threads using this frame (not necessarily the number of pointers) */
pthread_mutex_t mutex;
pthread_cond_t cv;
x264_pthread_mutex_t mutex;
x264_pthread_cond_t cv;
} x264_frame_t;
......
......@@ -70,42 +70,53 @@
#endif
/* threads */
#if defined(__WIN32__) && defined(HAVE_PTHREAD)
#include <pthread.h>
#define USE_CONDITION_VAR
#elif defined(SYS_BEOS)
#if defined(SYS_BEOS)
#include <kernel/OS.h>
#define pthread_t thread_id
#define pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \
resume_thread(*(t)); }
#define pthread_join(t,s) { long tmp; \
wait_for_thread(t,(s)?(long*)(s):&tmp); }
#define x264_pthread_t thread_id
#define x264_pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \
resume_thread(*(t)); }
#define x264_pthread_join(t,s) { long tmp; \
wait_for_thread(t,(s)?(long*)(s):&tmp); }
#ifndef usleep
#define usleep(t) snooze(t)
#define usleep(t) snooze(t)
#endif
#define HAVE_PTHREAD 1
#elif defined(HAVE_PTHREAD)
#include <pthread.h>
#define USE_CONDITION_VAR
#define USE_REAL_PTHREAD
#else
#define pthread_t int
#define pthread_create(t,u,f,d)
#define pthread_join(t,s)
#define x264_pthread_t int
#define x264_pthread_create(t,u,f,d)
#define x264_pthread_join(t,s)
#endif //SYS_*
#ifndef USE_CONDITION_VAR
#define pthread_mutex_t int
#define pthread_mutex_init(m,f)
#define pthread_mutex_destroy(m)
#define pthread_mutex_lock(m)
#define pthread_mutex_unlock(m)
#define pthread_cond_t int
#define pthread_cond_init(c,f)
#define pthread_cond_destroy(c)
#define pthread_cond_broadcast(c)
#define pthread_cond_wait(c,m) usleep(100)
#ifdef USE_REAL_PTHREAD
#define x264_pthread_t pthread_t
#define x264_pthread_create pthread_create
#define x264_pthread_join pthread_join
#define x264_pthread_mutex_t pthread_mutex_t
#define x264_pthread_mutex_init pthread_mutex_init
#define x264_pthread_mutex_destroy pthread_mutex_destroy
#define x264_pthread_mutex_lock pthread_mutex_lock
#define x264_pthread_mutex_unlock pthread_mutex_unlock
#define x264_pthread_cond_t pthread_cond_t
#define x264_pthread_cond_init pthread_cond_init
#define x264_pthread_cond_destroy pthread_cond_destroy
#define x264_pthread_cond_broadcast pthread_cond_broadcast
#define x264_pthread_cond_wait pthread_cond_wait
#else
#define x264_pthread_mutex_t int
#define x264_pthread_mutex_init(m,f)
#define x264_pthread_mutex_destroy(m)
#define x264_pthread_mutex_lock(m)
#define x264_pthread_mutex_unlock(m)
#define x264_pthread_cond_t int
#define x264_pthread_cond_init(c,f)
#define x264_pthread_cond_destroy(c)
#define x264_pthread_cond_broadcast(c)
#define x264_pthread_cond_wait(c,m) usleep(100)
#endif
#endif //_OSDEP_H
......@@ -1474,7 +1474,7 @@ do_encode:
/* Write frame */
if( h->param.i_threads > 1 )
{
pthread_create( &h->thread_handle, NULL, (void*)x264_slices_write, h );
x264_pthread_create( &h->thread_handle, NULL, (void*)x264_slices_write, h );
h->b_thread_active = 1;
}
else
......@@ -1594,7 +1594,7 @@ static void x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
if( h->b_thread_active )
{
pthread_join( h->thread_handle, NULL );
x264_pthread_join( h->thread_handle, NULL );
h->b_thread_active = 0;
}
if( !h->out.i_nal )
......@@ -1769,7 +1769,7 @@ void x264_encoder_close ( x264_t *h )
{
// don't strictly have to wait for the other threads, but it's simpler than cancelling them
if( h->thread[i]->b_thread_active )
pthread_join( h->thread[i]->thread_handle, NULL );
x264_pthread_join( h->thread[i]->thread_handle, NULL );
}
#ifdef DEBUG_BENCHMARK
......
......@@ -420,7 +420,7 @@ typedef struct {
int (*p_close_infile)( hnd_t handle );
hnd_t p_handle;
x264_picture_t pic;
pthread_t tid;
x264_pthread_t tid;
int next_frame;
int frame_total;
struct thread_input_arg_t *next_args;
......@@ -469,7 +469,7 @@ int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame )
if( h->next_frame >= 0 )
{
pthread_join( h->tid, &stuff );
x264_pthread_join( h->tid, &stuff );
ret |= h->next_args->status;
}
......@@ -487,7 +487,7 @@ int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame )
h->next_frame =
h->next_args->i_frame = i_frame+1;
h->next_args->pic = &h->pic;
pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args );
x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args );
}
else
h->next_frame = -1;
......
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