VLC  4.0.0-dev
Macros | Typedefs | Functions

Thread-safe block queue functions. More...

Collaboration diagram for Block FIFO:

Macros

#define vlc_fifo_CleanupPush(fifo)   vlc_cleanup_push(vlc_fifo_Cleanup, fifo)
 

Typedefs

typedef struct block_fifo_t vlc_fifo_t
 

Functions

block_fifo_tblock_FifoNew (void)
 Creates a thread-safe FIFO queue of blocks. More...
 
void block_FifoRelease (block_fifo_t *)
 Destroys a FIFO created by block_FifoNew(). More...
 
block_tblock_FifoGet (block_fifo_t *)
 Dequeue the first block from the FIFO. More...
 
block_tblock_FifoShow (block_fifo_t *)
 Peeks the first block in the FIFO. More...
 
static vlc_queue_tvlc_fifo_queue (const vlc_fifo_t *fifo)
 
static void vlc_fifo_Lock (vlc_fifo_t *fifo)
 Locks a block FIFO. More...
 
static void vlc_fifo_Unlock (vlc_fifo_t *fifo)
 Unlocks a block FIFO. More...
 
static void vlc_fifo_Signal (vlc_fifo_t *fifo)
 Wakes up one thread waiting on the FIFO, if any. More...
 
static void vlc_fifo_Wait (vlc_fifo_t *fifo)
 Waits on the FIFO. More...
 
static void vlc_fifo_WaitCond (vlc_fifo_t *fifo, vlc_cond_t *condvar)
 
void vlc_fifo_QueueUnlocked (vlc_fifo_t *fifo, block_t *block)
 Queues a linked-list of blocks into a locked FIFO. More...
 
block_tvlc_fifo_DequeueUnlocked (vlc_fifo_t *)
 Dequeues the first block from a locked FIFO, if any. More...
 
block_tvlc_fifo_DequeueAllUnlocked (vlc_fifo_t *)
 Dequeues the all blocks from a locked FIFO. More...
 
size_t vlc_fifo_GetCount (const vlc_fifo_t *)
 Counts blocks in a FIFO. More...
 
size_t vlc_fifo_GetBytes (const vlc_fifo_t *)
 Counts bytes in a FIFO. More...
 
static bool vlc_fifo_IsEmpty (const vlc_fifo_t *fifo)
 
static void vlc_fifo_Cleanup (void *fifo)
 
static void block_FifoEmpty (block_fifo_t *fifo)
 Clears all blocks in a FIFO. More...
 
static void block_FifoPut (block_fifo_t *fifo, block_t *block)
 Immediately queue one block at the end of a FIFO. More...
 
static size_t block_FifoSize (block_fifo_t *fifo)
 
static size_t block_FifoCount (block_fifo_t *fifo)
 

Detailed Description

Thread-safe block queue functions.

Macro Definition Documentation

◆ vlc_fifo_CleanupPush

#define vlc_fifo_CleanupPush (   fifo)    vlc_cleanup_push(vlc_fifo_Cleanup, fifo)

Typedef Documentation

◆ vlc_fifo_t

typedef struct block_fifo_t vlc_fifo_t

Function Documentation

◆ block_FifoCount()

static size_t block_FifoCount ( block_fifo_t fifo)
inlinestatic

◆ block_FifoEmpty()

static void block_FifoEmpty ( block_fifo_t fifo)
inlinestatic

◆ block_FifoGet()

block_t* block_FifoGet ( block_fifo_t fifo)

Dequeue the first block from the FIFO.

If necessary, wait until there is one block in the queue. This function is (always) cancellation point.

Returns
a valid block

References vlc_cleanup_pop, vlc_fifo_CleanupPush, vlc_fifo_DequeueUnlocked(), vlc_fifo_IsEmpty(), vlc_fifo_Lock(), vlc_fifo_Unlock(), vlc_fifo_Wait(), and vlc_testcancel().

◆ block_FifoNew()

block_fifo_t* block_FifoNew ( void  )

Creates a thread-safe FIFO queue of blocks.

See also block_FifoPut() and block_FifoGet(). The created queue must be released with block_FifoRelease().

Returns
the FIFO or NULL on memory error

References block_fifo_t::i_depth, block_fifo_t::i_size, likely, block_fifo_t::q, and vlc_queue_Init().

Referenced by CreateDecoder(), and sout_MuxAddStream().

◆ block_FifoPut()

static void block_FifoPut ( block_fifo_t fifo,
block_t block 
)
inlinestatic

Immediately queue one block at the end of a FIFO.

Parameters
fifoqueue
blockhead of a block list to queue (may be NULL)

References vlc_fifo_Lock(), vlc_fifo_QueueUnlocked(), and vlc_fifo_Unlock().

Referenced by DecoderPlayCc(), and sout_MuxSendBuffer().

◆ block_FifoRelease()

void block_FifoRelease ( block_fifo_t p_fifo)

Destroys a FIFO created by block_FifoNew().

Note
Any queued blocks are also destroyed.
Warning
No other threads may be using the FIFO when this function is called. Otherwise, undefined behaviour will occur.

References block_FifoEmpty().

Referenced by DeleteDecoder(), sout_MuxAddStream(), and sout_MuxDeleteStream().

◆ block_FifoShow()

block_t* block_FifoShow ( block_fifo_t p_fifo)

Peeks the first block in the FIFO.

Warning
This function leaves the block in the FIFO. You need to protect against concurrent threads who could dequeue the block. Preferably, there should be only one thread reading from the FIFO.
This function is undefined if the FIFO is empty.
Returns
a valid block.

References vlc_queue::first, block_fifo_t::q, vlc_fifo_Lock(), and vlc_fifo_Unlock().

Referenced by sout_MuxGetStream().

◆ block_FifoSize()

static size_t block_FifoSize ( block_fifo_t fifo)
inlinestatic

◆ vlc_fifo_Cleanup()

static void vlc_fifo_Cleanup ( void *  fifo)
inlinestatic

References vlc_fifo_Unlock().

◆ vlc_fifo_DequeueAllUnlocked()

block_t* vlc_fifo_DequeueAllUnlocked ( vlc_fifo_t fifo)

Dequeues the all blocks from a locked FIFO.

This is equivalent to calling vlc_fifo_DequeueUnlocked() repeatedly until the FIFO is emptied, but this function is much faster.

Note
This function is not a cancellation point.
Warning
The FIFO must be locked by the calling thread using vlc_fifo_Lock(). Otherwise behaviour is undefined.
Returns
a linked-list of all blocks in the FIFO (possibly NULL)

References block_fifo_t::i_depth, block_fifo_t::i_size, block_fifo_t::q, and vlc_queue_DequeueAllUnlocked().

Referenced by block_FifoEmpty(), vlc_input_decoder_Decode(), and vlc_input_decoder_Flush().

◆ vlc_fifo_DequeueUnlocked()

block_t* vlc_fifo_DequeueUnlocked ( vlc_fifo_t fifo)

Dequeues the first block from a locked FIFO, if any.

Note
This function is not a cancellation point.
Warning
The FIFO must be locked by the calling thread using vlc_fifo_Lock(). Otherwise behaviour is undefined.
Returns
the first block in the FIFO or NULL if the FIFO is empty

References block_t::i_buffer, block_fifo_t::i_depth, block_fifo_t::i_size, block_fifo_t::q, and vlc_queue_DequeueUnlocked().

Referenced by block_FifoGet().

◆ vlc_fifo_GetBytes()

size_t vlc_fifo_GetBytes ( const vlc_fifo_t fifo)

Counts bytes in a FIFO.

Checks how many bytes are queued in a locked FIFO.

Note
This function is not cancellation point.
Warning
The FIFO must be locked by the calling thread using vlc_fifo_Lock(). Otherwise behaviour is undefined.
Returns
the total number of bytes
Note
Zero bytes does not necessarily mean that the FIFO is empty since a block could contain zero bytes. Use vlc_fifo_GetCount() to determine if a FIFO is empty.

References block_fifo_t::i_size, vlc_queue::lock, block_fifo_t::q, and vlc_mutex_assert.

Referenced by block_FifoSize(), and vlc_input_decoder_Decode().

◆ vlc_fifo_GetCount()

size_t vlc_fifo_GetCount ( const vlc_fifo_t fifo)

Counts blocks in a FIFO.

Checks how many blocks are queued in a locked FIFO.

Note
This function is not cancellation point.
Warning
The FIFO must be locked by the calling thread using vlc_fifo_Lock(). Otherwise behaviour is undefined.
Returns
the number of blocks in the FIFO (zero if it is empty)

References block_fifo_t::i_depth, vlc_queue::lock, block_fifo_t::q, and vlc_mutex_assert.

Referenced by block_FifoCount(), and vlc_input_decoder_Decode().

◆ vlc_fifo_IsEmpty()

static bool vlc_fifo_IsEmpty ( const vlc_fifo_t fifo)
inlinestatic

◆ vlc_fifo_Lock()

static void vlc_fifo_Lock ( vlc_fifo_t fifo)
inlinestatic

Locks a block FIFO.

No more than one thread can lock the FIFO at any given time, and no other thread can modify the FIFO while it is locked. vlc_fifo_Unlock() releases the lock.

Note
If the FIFO is already locked by another thread, this function waits. This function is not a cancellation point.
Warning
Recursively locking a single FIFO is undefined. Locking more than one FIFO at a time may lead to lock inversion; mind the locking order.

References vlc_fifo_queue(), and vlc_queue_Lock().

Referenced by block_FifoCount(), block_FifoEmpty(), block_FifoGet(), block_FifoPut(), block_FifoShow(), block_FifoSize(), ModuleThread_PlayVideo(), ModuleThread_UpdateAudioFormat(), ModuleThread_UpdateVideoFormat(), vlc_input_decoder_ChangeDelay(), vlc_input_decoder_ChangePause(), vlc_input_decoder_ChangeRate(), vlc_input_decoder_Decode(), vlc_input_decoder_Delete(), vlc_input_decoder_Drain(), vlc_input_decoder_Flush(), vlc_input_decoder_FrameNext(), vlc_input_decoder_IsEmpty(), and vlc_input_decoder_Wait().

◆ vlc_fifo_queue()

static vlc_queue_t* vlc_fifo_queue ( const vlc_fifo_t fifo)
inlinestatic

◆ vlc_fifo_QueueUnlocked()

void vlc_fifo_QueueUnlocked ( vlc_fifo_t fifo,
block_t block 
)

Queues a linked-list of blocks into a locked FIFO.

Parameters
blockthe head of the list of blocks (if NULL, this function has no effects)
Note
This function is not a cancellation point.
Warning
The FIFO must be locked by the calling thread using vlc_fifo_Lock(). Otherwise behaviour is undefined.

References block_fifo_t::i_depth, block_fifo_t::i_size, block_t::p_next, block_fifo_t::q, and vlc_queue_EnqueueUnlocked().

Referenced by block_FifoPut(), and vlc_input_decoder_Decode().

◆ vlc_fifo_Signal()

static void vlc_fifo_Signal ( vlc_fifo_t fifo)
inlinestatic

Wakes up one thread waiting on the FIFO, if any.

Note
This function is not a cancellation point.
Warning
For race-free operations, the FIFO should be locked by the calling thread. The function can be called on a unlocked FIFO however.

References vlc_fifo_queue(), and vlc_queue_Signal().

Referenced by vlc_input_decoder_ChangePause(), vlc_input_decoder_Delete(), vlc_input_decoder_Drain(), vlc_input_decoder_Flush(), and vlc_input_decoder_FrameNext().

◆ vlc_fifo_Unlock()

static void vlc_fifo_Unlock ( vlc_fifo_t fifo)
inlinestatic

◆ vlc_fifo_Wait()

static void vlc_fifo_Wait ( vlc_fifo_t fifo)
inlinestatic

Waits on the FIFO.

Atomically unlocks the FIFO and waits until one thread signals the FIFO, then locks the FIFO again. A signal can be sent by queueing a block to the previously empty FIFO or by calling vlc_fifo_Signal() directly. This function may also return spuriously at any moment.

Note
This function is a cancellation point. In case of cancellation, the the FIFO will be locked before cancellation cleanup handlers are processed.

References vlc_fifo_queue(), and vlc_queue_Wait().

Referenced by block_FifoGet().

◆ vlc_fifo_WaitCond()

static void vlc_fifo_WaitCond ( vlc_fifo_t fifo,
vlc_cond_t condvar 
)
inlinestatic