Ejemplo n.º 1
0
int acquire_slot(memblock_t *mb, void **slot)
{
  assert(NULL != mb);

  assert(is_valid_memblock(mb));

  if (!slot_available(mb))
    return 0;

  // retrieve a pointer to a free slot from the stack
  *slot = *mb->stack_top;

  // get a free slot from the stack

  // remove that slot from the stack (it's no longer free)
  
  if (mb->stack == mb->stack_top)
    {
      mb->stack_empty = 1;
    }
  else
    {
      mb->stack_top--;
    }

  return 1;
}
Ejemplo n.º 2
0
gboolean
gst_ts_cache_push (GstTSCache * cache, guint8 * data, gsize size)
{
  Slot *tail;
  gsize avail;

#if DEBUG_RINGBUFFER
  dump_cache_state (cache, "pre-push");
#endif

  while (size) {
#if DEBUG_RINGBUFFER
    GST_DEBUG ("remaining size %d", size);
    dump_cache_state (cache, "pre-push");
#endif
    tail = &cache->slots[cache->tail];
    gst_ts_cache_recycle (cache, tail);
    if (slot_available (tail, &avail)) {
      avail = MIN (avail, size);
      if (slot_write (tail, data, avail, cache->h_rb_offset)) {
        /* Move the tail when the slot is full */
        cache->tail = (cache->tail + 1) % cache->nslots;
        cache->h_rb_offset += CACHE_SLOT_SIZE;
        g_atomic_int_inc (&cache->fslots);
      }
      data += avail;
      size -= avail;
      cache->h_offset += avail;
    } else {
      return FALSE;
    }
  }
#if DEBUG_RINGBUFFER
  dump_cache_state (cache, "post-push");
#endif

  return TRUE;
}