return c;
}
-void
-svm_fifo_add_chunk (svm_fifo_t * f, svm_fifo_chunk_t * c)
-{
- svm_fifo_chunk_t *cur, *prev;
-
- cur = c;
- prev = f->end_chunk;
-
- while (cur)
- {
- cur->start_byte = prev->start_byte + prev->length;
- cur->enq_rb_index = RBTREE_TNIL_INDEX;
- cur->deq_rb_index = RBTREE_TNIL_INDEX;
-
- prev = cur;
- cur = cur->next;
- }
-
- prev->next = 0;
- f->end_chunk->next = c;
- f->end_chunk = prev;
-
- if (!f->tail_chunk)
- f->tail_chunk = c;
-
- return;
-}
-
void
svm_fifo_free_chunk_lookup (svm_fifo_t * f)
{
}
static int
-f_try_grow (svm_fifo_t * f, u32 head, u32 tail, u32 len)
+f_try_chunk_alloc (svm_fifo_t * f, u32 head, u32 tail, u32 len)
{
- svm_fifo_chunk_t *c;
+ svm_fifo_chunk_t *c, *cur, *prev;
u32 alloc_size, free_alloced;
free_alloced = f_chunk_end (f->end_chunk) - tail;
- ASSERT (free_alloced < len);
alloc_size = clib_min (f->min_alloc, f->size - (tail - head));
alloc_size = clib_max (alloc_size, len - free_alloced);
if (PREDICT_FALSE (!c))
return -1;
- svm_fifo_add_chunk (f, c);
+ cur = c;
+ prev = f->end_chunk;
+
+ while (cur)
+ {
+ cur->start_byte = prev->start_byte + prev->length;
+ cur->enq_rb_index = RBTREE_TNIL_INDEX;
+ cur->deq_rb_index = RBTREE_TNIL_INDEX;
+
+ prev = cur;
+ cur = cur->next;
+ }
+
+ prev->next = 0;
+ f->end_chunk->next = c;
+ f->end_chunk = prev;
+
+ if (!f->tail_chunk)
+ f->tail_chunk = c;
+
return 0;
}
if (f_pos_gt (tail + len, f_chunk_end (f->end_chunk)))
{
- if (PREDICT_FALSE (f_try_grow (f, head, tail, len)))
+ if (PREDICT_FALSE (f_try_chunk_alloc (f, head, tail, len)))
{
len = f_chunk_end (f->end_chunk) - tail;
if (!len)
if (f_pos_gt (enq_pos + len, f_chunk_end (f->end_chunk)))
{
- if (PREDICT_FALSE (f_try_grow (f, head, tail, offset + len)))
+ if (PREDICT_FALSE (f_try_chunk_alloc (f, head, tail, offset + len)))
return SVM_FIFO_EGROW;
}
/**
* Drop all data from fifo
*
- * Should be called only from vpp side because of lookup cleanup
*/
void
svm_fifo_dequeue_drop_all (svm_fifo_t * f)
if (f_chunk_end (f->end_chunk) - head >= f->size)
return 0;
- if (f_try_grow (f, head, tail, f->size - (tail - head)))
+ if (f_try_chunk_alloc (f, head, tail, f->size - (tail - head)))
return SVM_FIFO_EGROW;
return 0;
u8 *data = 0;
svm_fifo_trace_elem_t *trace;
u32 offset;
- svm_fifo_t *dummy_fifo;
+ svm_fifo_t *placeholder_fifo;
if (!f)
return s;
trace_len = 0;
#endif
- dummy_fifo = svm_fifo_alloc (f->size);
+ placeholder_fifo = svm_fifo_alloc (f->size);
svm_fifo_init (f, f->size);
clib_memset (f->head_chunk->data, 0xFF, f->size);
vec_validate (data, f->size);
if (verbose)
s = format (s, "adding [%u, %u]:", trace[i].offset,
(trace[i].offset + trace[i].len));
- svm_fifo_enqueue_with_offset (dummy_fifo, trace[i].offset,
+ svm_fifo_enqueue_with_offset (placeholder_fifo, trace[i].offset,
trace[i].len, &data[offset]);
}
else if (trace[i].action == 2)
{
if (verbose)
s = format (s, "adding [%u, %u]:", 0, trace[i].len);
- svm_fifo_enqueue (dummy_fifo, trace[i].len, &data[offset]);
+ svm_fifo_enqueue (placeholder_fifo, trace[i].len, &data[offset]);
}
else if (!no_read)
{
if (verbose)
s = format (s, "read: %u", trace[i].len);
- svm_fifo_dequeue_drop (dummy_fifo, trace[i].len);
+ svm_fifo_dequeue_drop (placeholder_fifo, trace[i].len);
}
if (verbose)
- s = format (s, "%U", format_svm_fifo, dummy_fifo, 1);
+ s = format (s, "%U", format_svm_fifo, placeholder_fifo, 1);
}
- s = format (s, "result: %U", format_svm_fifo, dummy_fifo, 1);
+ s = format (s, "result: %U", format_svm_fifo, placeholder_fifo, 1);
return s;
}