lb: fix intermittent per-port-vip idx lookup failure
[vpp.git] / src / svm / message_queue.h
index 1ef773d..4473c44 100644 (file)
@@ -125,6 +125,11 @@ uword svm_msg_q_size_to_alloc (svm_msg_q_cfg_t *cfg);
 
 void svm_msg_q_attach (svm_msg_q_t *mq, void *smq_base);
 
+/**
+ * Cleanup mq's private data
+ */
+void svm_msg_q_cleanup (svm_msg_q_t *mq);
+
 /**
  * Free message queue
  *
@@ -185,6 +190,17 @@ int svm_msg_q_lock_and_alloc_msg_w_ring (svm_msg_q_t * mq, u32 ring_index,
  */
 void svm_msg_q_free_msg (svm_msg_q_t * mq, svm_msg_q_msg_t * msg);
 
+/**
+ * Producer enqueue one message to queue
+ *
+ * Must be called with mq locked. Prior to calling this, the producer should've
+ * obtained a message buffer from one of the rings.
+ *
+ * @param mq           message queue
+ * @param msg          message to be enqueued
+ */
+void svm_msg_q_add_raw (svm_msg_q_t *mq, svm_msg_q_msg_t *msg);
+
 /**
  * Producer enqueue one message to queue
  *
@@ -323,6 +339,12 @@ svm_msg_q_ring_is_full (svm_msg_q_t * mq, u32 ring_index)
   return (clib_atomic_load_relax_n (&ring->shr->cursize) >= ring->nitems);
 }
 
+static inline u8
+svm_msg_q_or_ring_is_full (svm_msg_q_t *mq, u32 ring_index)
+{
+  return (svm_msg_q_is_full (mq) || svm_msg_q_ring_is_full (mq, ring_index));
+}
+
 /**
  * Check if message queue is empty
  */
@@ -399,11 +421,27 @@ svm_msg_q_unlock (svm_msg_q_t * mq)
 /**
  * Wait for message queue event
  *
- * Must be called with mutex held. The queue only works non-blocking
- * with eventfds, so handle blocking calls as an exception here.
+ * When eventfds are not configured, the shared memory mutex is locked
+ * before waiting on the condvar. Typically called by consumers.
  */
 int svm_msg_q_wait (svm_msg_q_t *mq, svm_msg_q_wait_type_t type);
 
+/**
+ * Wait for message queue event as producer
+ *
+ * Similar to @ref svm_msg_q_wait but lock (mutex or spinlock) must
+ * be held. Should only be called by producers.
+ */
+int svm_msg_q_wait_prod (svm_msg_q_t *mq);
+
+/**
+ * Wait for message queue or ring event as producer
+ *
+ * Similar to @ref svm_msg_q_wait but lock (mutex or spinlock) must
+ * be held. Should only be called by producers.
+ */
+int svm_msg_q_or_ring_wait_prod (svm_msg_q_t *mq, u32 ring_index);
+
 /**
  * Timed wait for message queue event
  *