]> git.sesse.net Git - vlc/blobdiff - src/misc/block.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / misc / block.c
index 580237957da0ca17f751043a1ec8a088cedadef0..efa4fce3271774de7be0585d5545d6dad3b53f51 100644 (file)
@@ -288,7 +288,7 @@ static void block_heap_Release (block_t *self)
  *
  * @param ptr base address of the heap allocation (will be free()'d)
  * @param addr base address of the useful buffer data
- * @param length bytes length of the useful buffer datan
+ * @param length bytes length of the useful buffer data
  * @return NULL in case of error (ptr free()'d in that case), or a valid
  * block_t pointer.
  */
@@ -362,6 +362,7 @@ block_t *block_mmap_Alloc (void *addr, size_t length)
 
 
 #ifdef WIN32
+# include <io.h>
 #ifdef UNDER_CE
 #define _get_osfhandle(a) ((long) (a))
 #endif
@@ -571,18 +572,21 @@ void block_FifoPace (block_fifo_t *fifo, size_t max_depth, size_t max_size)
 size_t block_FifoPut( block_fifo_t *p_fifo, block_t *p_block )
 {
     size_t i_size = 0, i_depth = 0;
+    block_t *p_last;
 
     if (p_block == NULL)
         return 0;
-    for (block_t *b = p_block; b != NULL; b = b->p_next)
+    for (p_last = p_block; ; p_last = p_last->p_next)
     {
-        i_size += b->i_buffer;
+        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_block->p_next;
+    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 */
@@ -601,6 +605,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;
@@ -643,6 +653,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;