host stack: update stale copyright
[vpp.git] / src / svm / svm_fifo.c
index fb942a6..7aecbb8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Cisco and/or its affiliates.
+ * Copyright (c) 2016-2019 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
@@ -218,6 +218,7 @@ svm_fifo_create (u32 data_size_in_bytes)
   f->nitems = data_size_in_bytes;
   f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX;
   f->ct_session_index = SVM_FIFO_INVALID_SESSION_INDEX;
+  f->segment_index = SVM_FIFO_INVALID_INDEX;
   f->refcnt = 1;
   return (f);
 }
@@ -519,7 +520,7 @@ CLIB_MARCH_FN (svm_fifo_enqueue_nowait, int, svm_fifo_t * f, u32 max_bytes,
 
   /* Atomically increase the queue length */
   ASSERT (cursize + total_copy_bytes <= nitems);
-  clib_atomic_fetch_add (&f->cursize, total_copy_bytes);
+  clib_atomic_fetch_add_rel (&f->cursize, total_copy_bytes);
 
   return (total_copy_bytes);
 }
@@ -666,7 +667,7 @@ CLIB_MARCH_FN (svm_fifo_dequeue_nowait, int, svm_fifo_t * f, u32 max_bytes,
 
   ASSERT (f->head <= nitems);
   ASSERT (cursize >= total_copy_bytes);
-  clib_atomic_fetch_sub (&f->cursize, total_copy_bytes);
+  clib_atomic_fetch_sub_rel (&f->cursize, total_copy_bytes);
 
   return (total_copy_bytes);
 }
@@ -764,7 +765,7 @@ svm_fifo_dequeue_drop (svm_fifo_t * f, u32 max_bytes)
 
   ASSERT (f->head <= nitems);
   ASSERT (cursize >= total_drop_bytes);
-  clib_atomic_fetch_sub (&f->cursize, total_drop_bytes);
+  clib_atomic_fetch_sub_rel (&f->cursize, total_drop_bytes);
 
   return total_drop_bytes;
 }
@@ -773,7 +774,7 @@ void
 svm_fifo_dequeue_drop_all (svm_fifo_t * f)
 {
   f->head = f->tail;
-  clib_atomic_fetch_sub (&f->cursize, f->cursize);
+  clib_atomic_fetch_sub_rel (&f->cursize, f->cursize);
 }
 
 int
@@ -820,7 +821,7 @@ svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_segment_t * fs)
       f->head = (f->head + fs[0].len) % f->nitems;
       total_drop_bytes = fs[0].len;
     }
-  clib_atomic_fetch_sub (&f->cursize, total_drop_bytes);
+  clib_atomic_fetch_sub_rel (&f->cursize, total_drop_bytes);
 }
 
 u32
@@ -844,6 +845,29 @@ svm_fifo_init_pointers (svm_fifo_t * f, u32 pointer)
   f->head = f->tail = pointer % f->nitems;
 }
 
+void
+svm_fifo_add_subscriber (svm_fifo_t * f, u8 subscriber)
+{
+  if (f->n_subscribers >= SVM_FIFO_MAX_EVT_SUBSCRIBERS)
+    return;
+  f->subscribers[f->n_subscribers++] = subscriber;
+}
+
+void
+svm_fifo_del_subscriber (svm_fifo_t * f, u8 subscriber)
+{
+  int i;
+
+  for (i = 0; i < f->n_subscribers; i++)
+    {
+      if (f->subscribers[i] != subscriber)
+       continue;
+      f->subscribers[i] = f->subscribers[f->n_subscribers - 1];
+      f->n_subscribers--;
+      break;
+    }
+}
+
 #endif
 /*
  * fd.io coding-style-patch-verification: ON