Commit 757ce256 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

block: rewrite block_Fifo(Empty,Get,Put) with the new functions

parent 26d23afc
......@@ -313,7 +313,7 @@ VLC_API block_fifo_t *block_FifoNew( void ) VLC_USED VLC_MALLOC;
VLC_API void block_FifoRelease( block_fifo_t * );
VLC_API void block_FifoPace( block_fifo_t *fifo, size_t max_depth, size_t max_size );
VLC_API void block_FifoEmpty( block_fifo_t * );
VLC_API size_t block_FifoPut( block_fifo_t *, block_t * );
VLC_API void block_FifoPut( block_fifo_t *, block_t * );
VLC_API void block_FifoWake( block_fifo_t * );
VLC_API block_t * block_FifoGet( block_fifo_t * ) VLC_USED;
VLC_API block_t * block_FifoShow( block_fifo_t * );
......
......@@ -276,29 +276,17 @@ void block_FifoRelease( block_fifo_t *p_fifo )
free( p_fifo );
}
void block_FifoEmpty( block_fifo_t *p_fifo )
/**
* Clears all blocks in a FIFO.
*/
void block_FifoEmpty(block_fifo_t *fifo)
{
block_t *block;
vlc_mutex_lock( &p_fifo->lock );
block = p_fifo->p_first;
if (block != NULL)
{
p_fifo->i_depth = p_fifo->i_size = 0;
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
}
vlc_cond_broadcast( &p_fifo->wait_room );
vlc_mutex_unlock( &p_fifo->lock );
while (block != NULL)
{
block_t *buf;
buf = block->p_next;
block_Release (block);
block = buf;
}
vlc_fifo_Lock(fifo);
block = vlc_fifo_DequeueAllUnlocked(fifo);
vlc_fifo_Unlock(fifo);
block_ChainRelease(block);
}
/**
......@@ -336,33 +324,12 @@ void block_FifoPace (block_fifo_t *fifo, size_t max_depth, size_t max_size)
* Immediately queue one block at the end of a FIFO.
* @param fifo queue
* @param block head of a block list to queue (may be NULL)
* @return total number of bytes appended to the queue
*/
size_t block_FifoPut( block_fifo_t *p_fifo, block_t *p_block )
void block_FifoPut(block_fifo_t *fifo, block_t *block)
{
size_t i_size = 0, i_depth = 0;
block_t *p_last;
if (p_block == NULL)
return 0;
for (p_last = p_block; ; p_last = p_last->p_next)
{
i_size += p_last->i_buffer;
i_depth++;
if (!p_last->p_next)
break;
}
vlc_mutex_lock (&p_fifo->lock);
*p_fifo->pp_last = p_block;
p_fifo->pp_last = &p_last->p_next;
p_fifo->i_depth += i_depth;
p_fifo->i_size += i_size;
/* We queued at least one block: wake up one read-waiting thread */
vlc_cond_signal( &p_fifo->wait );
vlc_mutex_unlock( &p_fifo->lock );
return i_size;
vlc_fifo_Lock(fifo);
vlc_fifo_QueueUnlocked(fifo, block);
vlc_fifo_Unlock(fifo);
}
void block_FifoWake( block_fifo_t *p_fifo )
......@@ -380,46 +347,24 @@ void block_FifoWake( block_fifo_t *p_fifo )
*
* @return a valid block, or NULL if block_FifoWake() was called.
*/
block_t *block_FifoGet( block_fifo_t *p_fifo )
block_t *block_FifoGet(block_fifo_t *fifo)
{
block_t *b;
vlc_testcancel( );
vlc_mutex_lock( &p_fifo->lock );
mutex_cleanup_push( &p_fifo->lock );
/* Remember vlc_cond_wait() may cause spurious wakeups
* (on both Win32 and POSIX) */
while( ( p_fifo->p_first == NULL ) && !p_fifo->b_force_wake )
vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
vlc_cleanup_pop();
b = p_fifo->p_first;
p_fifo->b_force_wake = false;
if( b == NULL )
{
/* Forced wakeup */
vlc_mutex_unlock( &p_fifo->lock );
return NULL;
}
block_t *block;
p_fifo->p_first = b->p_next;
p_fifo->i_depth--;
p_fifo->i_size -= b->i_buffer;
vlc_testcancel();
if( p_fifo->p_first == NULL )
vlc_fifo_Lock(fifo);
while (vlc_fifo_IsEmpty(fifo) && !fifo->b_force_wake)
{
p_fifo->pp_last = &p_fifo->p_first;
vlc_fifo_CleanupPush(fifo);
vlc_fifo_Wait(fifo);
vlc_cleanup_pop();
}
fifo->b_force_wake = false;
block = vlc_fifo_DequeueUnlocked(fifo);
vlc_fifo_Unlock(fifo);
/* We don't know how many threads can queue new packets now. */
vlc_cond_broadcast( &p_fifo->wait_room );
vlc_mutex_unlock( &p_fifo->lock );
b->p_next = NULL;
return b;
return block;
}
/**
......
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