pthread_cond_timedwait can wake early. under certain system load conditions, this
happens often. I was going ahead and adding buffers whenever it woke, regardless
of whether the condition had actually been met. so the fifo depth would
increase until memory ran out.
git-svn-id: svn://localhost/HandBrake/trunk@3030
b64f7644-9d1e-0410-96f1-
a4d463321fa5
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 )
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 );
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 )
}
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 );
}
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;
+ }
+ }
}
}
}