summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/svm_fifo.c10
-rw-r--r--src/svm/svm_fifo.h1
-rw-r--r--src/svm/svm_fifo_segment.c5
3 files changed, 14 insertions, 2 deletions
diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c
index fc2189c5176..e478c06e891 100644
--- a/src/svm/svm_fifo.c
+++ b/src/svm/svm_fifo.c
@@ -201,14 +201,20 @@ svm_fifo_create (u32 data_size_in_bytes)
memset (f, 0, sizeof (*f));
f->nitems = data_size_in_bytes;
f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX;
+ f->refcnt = 1;
return (f);
}
void
svm_fifo_free (svm_fifo_t * f)
{
- pool_free (f->ooo_segments);
- clib_mem_free (f);
+ ASSERT (f->refcnt > 0);
+
+ if (--f->refcnt == 0)
+ {
+ pool_free (f->ooo_segments);
+ clib_mem_free (f);
+ }
}
always_inline ooo_segment_t *
diff --git a/src/svm/svm_fifo.h b/src/svm/svm_fifo.h
index a83cd858f83..f10b4d91a2a 100644
--- a/src/svm/svm_fifo.h
+++ b/src/svm/svm_fifo.h
@@ -75,6 +75,7 @@ typedef struct _svm_fifo
#if SVM_FIFO_TRACE
svm_fifo_trace_elem_t *trace;
#endif
+ i8 refcnt;
CLIB_CACHE_LINE_ALIGN_MARK (data);
} svm_fifo_t;
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/svm_fifo_segment.c
index 86661e516a2..c04b9d8ccba 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/svm_fifo_segment.c
@@ -296,6 +296,7 @@ svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
memset (f, 0, sizeof (*f));
f->nitems = data_size_in_bytes;
f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX;
+ f->refcnt = 1;
goto found;
}
/* FALLTHROUGH */
@@ -344,6 +345,10 @@ svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, svm_fifo_t * f,
svm_fifo_segment_header_t *fsh;
void *oldheap;
+ ASSERT (f->refcnt > 0);
+
+ if (--f->refcnt > 0)
+ return;
sh = s->ssvm.sh;
fsh = (svm_fifo_segment_header_t *) sh->opaque[0];