svm: change fifo pointers to offsets
[vpp.git] / src / svm / svm_fifo.h
index 5845d70..f5b6080 100644 (file)
@@ -171,6 +171,48 @@ f_chunk_includes_pos (svm_fifo_chunk_t * c, u32 pos)
          && f_pos_lt (pos, c->start_byte + c->length));
 }
 
+always_inline svm_fifo_chunk_t *
+f_start_cptr (svm_fifo_t *f)
+{
+  return fs_chunk_ptr (f->fs_hdr, f->shr->start_chunk);
+}
+
+always_inline svm_fifo_chunk_t *
+f_end_cptr (svm_fifo_t *f)
+{
+  return fs_chunk_ptr (f->fs_hdr, f->shr->end_chunk);
+}
+
+always_inline svm_fifo_chunk_t *
+f_head_cptr (svm_fifo_t *f)
+{
+  return fs_chunk_ptr (f->fs_hdr, f->shr->head_chunk);
+}
+
+always_inline svm_fifo_chunk_t *
+f_tail_cptr (svm_fifo_t *f)
+{
+  return fs_chunk_ptr (f->fs_hdr, f->shr->tail_chunk);
+}
+
+always_inline svm_fifo_chunk_t *
+f_cptr (svm_fifo_t *f, svm_fifo_chunk_ptr_t cp)
+{
+  return fs_chunk_ptr (f->fs_hdr, cp);
+}
+
+always_inline svm_fifo_chunk_ptr_t
+f_csptr (svm_fifo_t *f, svm_fifo_chunk_t *c)
+{
+  return fs_chunk_sptr (f->fs_hdr, c);
+}
+
+always_inline void
+f_csptr_link (svm_fifo_t *f, svm_fifo_chunk_ptr_t cp, svm_fifo_chunk_t *c)
+{
+  fs_chunk_ptr (f->fs_hdr, cp)->next = fs_chunk_sptr (f->fs_hdr, c);
+}
+
 /**
  * Create fifo of requested size
  *
@@ -606,7 +648,7 @@ u32 svm_fifo_max_write_chunk (svm_fifo_t * f);
 static inline svm_fifo_chunk_t *
 svm_fifo_head_chunk (svm_fifo_t * f)
 {
-  return f->shr->head_chunk;
+  return f_head_cptr (f);
 }
 
 /**
@@ -618,11 +660,12 @@ svm_fifo_head_chunk (svm_fifo_t * f)
 static inline u8 *
 svm_fifo_head (svm_fifo_t * f)
 {
+  svm_fifo_chunk_t *head_chunk;
   if (!f->shr->head_chunk)
     return 0;
   /* load-relaxed: consumer owned index */
-  return (f->shr->head_chunk->data +
-         (f->shr->head - f->shr->head_chunk->start_byte));
+  head_chunk = f_head_cptr (f);
+  return (head_chunk->data + (f->shr->head - head_chunk->start_byte));
 }
 
 /**
@@ -634,7 +677,7 @@ svm_fifo_head (svm_fifo_t * f)
 static inline svm_fifo_chunk_t *
 svm_fifo_tail_chunk (svm_fifo_t * f)
 {
-  return f->shr->tail_chunk;
+  return f_tail_cptr (f);
 }
 
 /**
@@ -646,9 +689,11 @@ svm_fifo_tail_chunk (svm_fifo_t * f)
 static inline u8 *
 svm_fifo_tail (svm_fifo_t * f)
 {
+  svm_fifo_chunk_t *tail_chunk;
+
   /* load-relaxed: producer owned index */
-  return (f->shr->tail_chunk->data +
-         (f->shr->tail - f->shr->tail_chunk->start_byte));
+  tail_chunk = f_tail_cptr (f);
+  return (tail_chunk->data + (f->shr->tail - tail_chunk->start_byte));
 }
 
 /**