1 /* $Id: fifo.c,v 1.17 2005/10/15 18:05:03 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
13 hb_buffer_t * hb_buffer_init( int size )
17 if( !( b = calloc( sizeof( hb_buffer_t ), 1 ) ) )
19 hb_log( "out of memory" );
25 #if defined( SYS_DARWIN ) || defined( SYS_FREEBSD )
26 b->data = malloc( size );
27 #elif defined( SYS_CYGWIN )
29 b->data = malloc( size + 17 );
31 b->data = memalign( 16, size );
36 hb_log( "out of memory" );
43 void hb_buffer_realloc( hb_buffer_t * b, int size )
45 /* No more alignment, but we don't care */
46 b->data = realloc( b->data, size );
50 void hb_buffer_close( hb_buffer_t ** _b )
52 hb_buffer_t * b = *_b;
73 hb_fifo_t * hb_fifo_init( int capacity )
76 f = calloc( sizeof( hb_fifo_t ), 1 );
77 f->lock = hb_lock_init();
78 f->capacity = capacity;
82 int hb_fifo_size( hb_fifo_t * f )
93 int hb_fifo_is_full( hb_fifo_t * f )
98 ret = ( f->size >= f->capacity );
104 hb_buffer_t * hb_fifo_get( hb_fifo_t * f )
111 hb_unlock( f->lock );
118 hb_unlock( f->lock );
123 hb_buffer_t * hb_fifo_see( hb_fifo_t * f )
130 hb_unlock( f->lock );
134 hb_unlock( f->lock );
139 void hb_fifo_push( hb_fifo_t * f, hb_buffer_t * b )
157 while( f->last->next )
160 f->last = f->last->next;
162 hb_unlock( f->lock );
165 void hb_fifo_close( hb_fifo_t ** _f )
170 hb_log( "fifo_close: trashing %d buffer(s)", hb_fifo_size( f ) );
171 while( ( b = hb_fifo_get( f ) ) )
173 hb_buffer_close( &b );
176 hb_lock_close( &f->lock );