]> git.sesse.net Git - vlc/blobdiff - src/misc/block.c
Return 64-bits values for integer object variables
[vlc] / src / misc / block.c
index 18f7b03ef6b45c6e43d94766af1b281de1e46410..1d06fec1467f52d47116daecc8c1d86a11b3d6e3 100644 (file)
@@ -566,25 +566,29 @@ 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 )
 {
-    size_t i_size = 0;
-    vlc_mutex_lock( &p_fifo->lock );
+    size_t i_size = 0, i_depth = 0;
+    block_t *p_last;
 
-    while (p_block != NULL)
+    if (p_block == NULL)
+        return 0;
+    for (p_last = p_block; ; p_last = p_last->p_next)
     {
-        i_size += p_block->i_buffer;
-
-        *p_fifo->pp_last = p_block;
-        p_fifo->pp_last = &p_block->p_next;
-        p_fifo->i_depth++;
-        p_fifo->i_size += p_block->i_buffer;
-
-        p_block = p_block->p_next;
+        i_size += p_last->i_buffer;
+        i_depth++;
+        if (!p_last->p_next)
+            break;
     }
 
-    /* We queued one block: wake up one read-waiting thread */
+    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 );
 
@@ -600,6 +604,12 @@ void block_FifoWake( block_fifo_t *p_fifo )
     vlc_mutex_unlock( &p_fifo->lock );
 }
 
+/**
+ * Dequeue the first block from the FIFO. If necessary, wait until there is
+ * one block in the queue. This function is (always) cancellation point.
+ *
+ * @return a valid block, or NULL if block_FifoWake() was called.
+ */
 block_t *block_FifoGet( block_fifo_t *p_fifo )
 {
     block_t *b;
@@ -642,6 +652,17 @@ block_t *block_FifoGet( block_fifo_t *p_fifo )
     return b;
 }
 
+/**
+ * Peeks the first block in the FIFO.
+ * If necessary, wait until there is one block.
+ * This function is (always) a cancellation point.
+ *
+ * @warning This function leaves the block in the FIFO.
+ * You need to protect against concurrent threads who could dequeue the block.
+ * Preferrably, there should be only one thread reading from the FIFO.
+ *
+ * @return a valid block.
+ */
 block_t *block_FifoShow( block_fifo_t *p_fifo )
 {
     block_t *b;