Add config option to use dlmalloc instead of mheap
[vpp.git] / src / vcl / vppcom.c
index 1fd138e..60c649d 100644 (file)
@@ -367,25 +367,20 @@ int
 vppcom_app_create (char *app_name)
 {
   vppcom_cfg_t *vcl_cfg = &vcm->cfg;
-  u8 *heap;
-  mheap_t *h;
   int rv;
 
   if (!vcm->init)
     {
       vcm->init = 1;
+      vppcom_cfg (&vcm->cfg);
+
       clib_spinlock_init (&vcm->session_fifo_lockp);
       clib_fifo_validate (vcm->client_session_index_fifo,
                          vcm->cfg.listen_queue_size);
       clib_spinlock_init (&vcm->sessions_lockp);
 
-      vppcom_cfg (&vcm->cfg);
 
       vcm->main_cpu = os_get_thread_index ();
-      heap = clib_mem_get_per_cpu_heap ();
-      h = mheap_header (heap);
-      /* make the main heap thread-safe */
-      h->flags |= MHEAP_FLAG_THREAD_SAFE;
 
       vcm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
 
@@ -1164,16 +1159,19 @@ vppcom_session_read_ready (vcl_session_t * session, u32 session_index)
     }
   rv = ready;
 
-  if (vcm->app_event_queue->cursize &&
-      !pthread_mutex_trylock (&vcm->app_event_queue->mutex))
+  if (!svm_msg_q_is_empty (vcm->app_event_queue) &&
+      !pthread_mutex_trylock (&vcm->app_event_queue->q->mutex))
     {
-      u32 i, n_to_dequeue = vcm->app_event_queue->cursize;
-      session_fifo_event_t e;
+      u32 i, n_to_dequeue = vcm->app_event_queue->q->cursize;
+      svm_msg_q_msg_t msg;
 
       for (i = 0; i < n_to_dequeue; i++)
-       svm_queue_sub_raw (vcm->app_event_queue, (u8 *) & e);
+       {
+         svm_queue_sub_raw (vcm->app_event_queue->q, (u8 *) & msg);
+         svm_msg_q_free_msg (vcm->app_event_queue, &msg);
+       }
 
-      pthread_mutex_unlock (&vcm->app_event_queue->mutex);
+      pthread_mutex_unlock (&vcm->app_event_queue->q->mutex);
     }
 done:
   return rv;
@@ -1184,8 +1182,7 @@ vppcom_session_write (uint32_t session_index, void *buf, size_t n)
 {
   vcl_session_t *session = 0;
   svm_fifo_t *tx_fifo = 0;
-  svm_queue_t *q;
-  session_fifo_event_t evt;
+  svm_msg_q_t *mq;
   session_state_t state;
   int rv, n_write, is_nonblocking;
   u32 poll_et;
@@ -1241,18 +1238,15 @@ vppcom_session_write (uint32_t session_index, void *buf, size_t n)
 
   if ((n_write > 0) && svm_fifo_set_event (tx_fifo))
     {
-      /* Fabricate TX event, send to vpp */
-      evt.fifo = tx_fifo;
-      evt.event_type = FIFO_EVENT_APP_TX;
-
+      /* Send TX event to vpp */
       VCL_SESSION_LOCK_AND_GET (session_index, &session);
-      q = session->vpp_evt_q;
-      ASSERT (q);
-      svm_queue_add (q, (u8 *) & evt, 0 /* do wait for mutex */ );
+      mq = session->vpp_evt_q;
+      ASSERT (mq);
+      app_send_io_evt_to_vpp (mq, tx_fifo, FIFO_EVENT_APP_TX, SVM_Q_WAIT);
       VCL_SESSION_UNLOCK ();
       VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: added FIFO_EVENT_APP_TX "
            "to vpp_event_q %p, n_write %d", getpid (),
-           vpp_handle, session_index, q, n_write);
+           vpp_handle, session_index, mq, n_write);
     }
 
   if (n_write <= 0)