remove libvlib from libvlibmemoryclient libs
[vpp.git] / src / vcl / vppcom.c
index 1991e3e..3acd1c4 100644 (file)
@@ -285,6 +285,8 @@ vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp)
       vcl_wait_for_memory (session->vpp_evt_q);
       rx_fifo->master_session_index = session->session_index;
       tx_fifo->master_session_index = session->session_index;
+      rx_fifo->master_thread_index = vcl_get_worker_index ();
+      tx_fifo->master_thread_index = vcl_get_worker_index ();
       vec_validate (wrk->vpp_event_queues, 0);
       evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *);
       wrk->vpp_event_queues[0] = evt_q;
@@ -295,7 +297,8 @@ vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp)
                                             svm_msg_q_t *);
       rx_fifo->client_session_index = session->session_index;
       tx_fifo->client_session_index = session->session_index;
-
+      rx_fifo->client_thread_index = vcl_get_worker_index ();
+      tx_fifo->client_thread_index = vcl_get_worker_index ();
       vpp_wrk_index = tx_fifo->master_thread_index;
       vec_validate (wrk->vpp_event_queues, vpp_wrk_index);
       wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q;
@@ -349,8 +352,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
   if (mp->retval)
     {
       clib_warning ("VCL<%d>: ERROR: sid %u: connect failed! %U", getpid (),
-                   mp->handle, session_index, format_api_error,
-                   ntohl (mp->retval));
+                   session_index, format_api_error, ntohl (mp->retval));
       session->session_state = STATE_FAILED;
       session->vpp_handle = mp->handle;
       return session_index;
@@ -361,6 +363,8 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
   vcl_wait_for_memory (rx_fifo);
   rx_fifo->client_session_index = session_index;
   tx_fifo->client_session_index = session_index;
+  rx_fifo->client_thread_index = vcl_get_worker_index ();
+  tx_fifo->client_thread_index = vcl_get_worker_index ();
 
   if (mp->client_event_queue_address)
     {
@@ -648,6 +652,9 @@ vppcom_session_disconnect (u32 session_handle)
   u64 vpp_handle;
 
   session = vcl_session_get_w_handle (wrk, session_handle);
+  if (!session)
+    return VPPCOM_EBADFD;
+
   vpp_handle = session->vpp_handle;
   state = session->session_state;
 
@@ -700,6 +707,7 @@ vppcom_app_create (char *app_name)
       svm_fifo_segment_main_init (vcl_cfg->segment_baseva,
                                  20 /* timeout in secs */ );
       pool_init_fixed (vcm->workers, vcl_cfg->max_workers);
+      clib_spinlock_init (&vcm->workers_lock);
       vcl_worker_alloc_and_init ();
     }
 
@@ -1580,6 +1588,14 @@ vcl_mq_dequeue_batch (vcl_worker_t * wrk, svm_msg_q_t * mq)
   return n_msgs;
 }
 
+#define vcl_fifo_rx_evt_valid_or_break(_fifo)                  \
+if (PREDICT_FALSE (svm_fifo_is_empty (_fifo)))                 \
+  {                                                            \
+    svm_fifo_unset_event (_fifo);                              \
+    if (svm_fifo_is_empty (_fifo))                             \
+       break;                                                  \
+  }                                                            \
+
 static int
 vcl_select_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq,
                      unsigned long n_bits, unsigned long *read_map,
@@ -1633,6 +1649,7 @@ vcl_select_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq,
       switch (e->event_type)
        {
        case FIFO_EVENT_APP_RX:
+         vcl_fifo_rx_evt_valid_or_break (e->fifo);
          sid = e->fifo->client_session_index;
          session = vcl_session_get (wrk, sid);
          if (!session)
@@ -1655,12 +1672,7 @@ vcl_select_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq,
            }
          break;
        case SESSION_IO_EVT_CT_TX:
-         if (svm_fifo_is_empty (e->fifo))
-           {
-             svm_fifo_unset_event (e->fifo);
-             if (svm_fifo_is_empty (e->fifo))
-               break;
-           }
+         vcl_fifo_rx_evt_valid_or_break (e->fifo);
          session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 0);
          if (!session)
            break;
@@ -2228,6 +2240,8 @@ vcl_epoll_wait_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq,
       switch (e->event_type)
        {
        case FIFO_EVENT_APP_RX:
+         ASSERT (e->fifo->client_thread_index == vcl_get_worker_index ());
+         vcl_fifo_rx_evt_valid_or_break (e->fifo);
          sid = e->fifo->client_session_index;
          session = vcl_session_get (wrk, sid);
          session_events = session->vep.ev.events;
@@ -2248,6 +2262,7 @@ vcl_epoll_wait_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq,
          session_evt_data = session->vep.ev.data.u64;
          break;
        case SESSION_IO_EVT_CT_TX:
+         vcl_fifo_rx_evt_valid_or_break (e->fifo);
          session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 0);
          sid = session->session_index;
          session_events = session->vep.ev.events;
@@ -3156,7 +3171,7 @@ vppcom_session_index (uint32_t session_handle)
 int
 vppcom_worker_register (void)
 {
-  if (!vcl_worker_alloc_and_init ())
+  if (vcl_worker_alloc_and_init ())
     return VPPCOM_OK;
   return VPPCOM_EEXIST;
 }