summaryrefslogtreecommitdiffstats
path: root/libhb/fifo.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2009-12-15 01:28:55 +0000
committerjstebbins <[email protected]>2009-12-15 01:28:55 +0000
commiteecac51cfcbc412f5d2f7510a1dd4179fbb406f4 (patch)
tree995b82b3c6d0e022d6f5bca9865f0f3ce32d3a5b /libhb/fifo.c
parentb4487bf6de437d77ebdd2cc137f54631b22fc9c8 (diff)
fix potential runaway buffer usage
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://svn.handbrake.fr/HandBrake/trunk@3030 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/fifo.c')
-rw-r--r--libhb/fifo.c15
1 files changed, 15 insertions, 0 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 )