summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
Diffstat (limited to 'libhb')
-rw-r--r--libhb/fifo.c15
-rw-r--r--libhb/internal.h1
-rw-r--r--libhb/reader.c9
-rw-r--r--libhb/work.c18
4 files changed, 40 insertions, 3 deletions
diff --git a/libhb/fifo.c b/libhb/fifo.c
index 781c9400b..c72b4e10b 100644
--- a/libhb/fifo.c
+++ b/libhb/fifo.c
@@ -374,6 +374,21 @@ hb_buffer_t * hb_fifo_see2( hb_fifo_t * f )
return b;
}
+int hb_fifo_full_wait( hb_fifo_t * f )
+{
+ int result;
+
+ hb_lock( f->lock );
+ if( f->size >= f->capacity )
+ {
+ f->wait_full = 1;
+ hb_cond_timedwait( f->cond_full, f->lock, FIFO_TIMEOUT );
+ }
+ result = ( f->size < f->capacity );
+ hb_unlock( f->lock );
+ return result;
+}
+
void hb_fifo_push_wait( hb_fifo_t * f, hb_buffer_t * b )
{
if( !b )
diff --git a/libhb/internal.h b/libhb/internal.h
index 808537448..efe18fa44 100644
--- a/libhb/internal.h
+++ b/libhb/internal.h
@@ -96,6 +96,7 @@ hb_buffer_t * hb_fifo_see_wait( hb_fifo_t * );
hb_buffer_t * hb_fifo_see2( hb_fifo_t * );
void hb_fifo_push( hb_fifo_t *, hb_buffer_t * );
void hb_fifo_push_wait( hb_fifo_t *, hb_buffer_t * );
+int hb_fifo_full_wait( hb_fifo_t * f );
void hb_fifo_push_head( hb_fifo_t *, hb_buffer_t * );
void hb_fifo_close( hb_fifo_t ** );
void hb_fifo_flush( hb_fifo_t * f );
diff --git a/libhb/reader.c b/libhb/reader.c
index 6b7d4cd80..928d8696b 100644
--- a/libhb/reader.c
+++ b/libhb/reader.c
@@ -69,7 +69,14 @@ hb_thread_t * hb_reader_init( hb_job_t * job )
static void push_buf( const hb_reader_t *r, hb_fifo_t *fifo, hb_buffer_t *buf )
{
- hb_fifo_push_wait( fifo, buf );
+ while ( !*r->die )
+ {
+ if ( hb_fifo_full_wait( fifo ) )
+ {
+ hb_fifo_push( fifo, buf );
+ break;
+ }
+ }
}
static int is_audio( hb_reader_t *r, int id )
diff --git a/libhb/work.c b/libhb/work.c
index 05bf6a1f3..7a923a192 100644
--- a/libhb/work.c
+++ b/libhb/work.c
@@ -944,7 +944,14 @@ static void do_job( hb_job_t * job, int cpu_count )
}
if( buf_out )
{
- hb_fifo_push_wait( w->fifo_out, buf_out );
+ while ( !*job->die )
+ {
+ if ( hb_fifo_full_wait( w->fifo_out ) )
+ {
+ hb_fifo_push( w->fifo_out, buf_out );
+ break;
+ }
+ }
}
}
hb_list_rem( job->list_work, w );
@@ -1160,7 +1167,14 @@ static void work_loop( void * _w )
}
if( buf_out )
{
- hb_fifo_push_wait( w->fifo_out, buf_out );
+ while ( !*w->done )
+ {
+ if ( hb_fifo_full_wait( w->fifo_out ) )
+ {
+ hb_fifo_push( w->fifo_out, buf_out );
+ break;
+ }
+ }
}
}
}