+void *
+vppcom_session_io_thread_fn (void *arg)
+{
+ vppcom_session_io_thread_t *evt = (vppcom_session_io_thread_t *) arg;
+ u32 *session_indexes = 0, *session_index;
+ int i, rv;
+ u32 bytes = 0;
+ session_t *session;
+
+ while (1)
+ {
+ vec_reset_length (session_indexes);
+ clib_spinlock_lock (&evt->io_sessions_lockp);
+ pool_foreach (session_index, evt->active_session_indexes, (
+ {
+ vec_add1
+ (session_indexes,
+ *session_index);
+ }
+ ));
+ clib_spinlock_unlock (&evt->io_sessions_lockp);
+ if (session_indexes)
+ {
+ for (i = 0; i < vec_len (session_indexes); ++i)
+ {
+ VCL_LOCK_AND_GET_SESSION (session_indexes[i], &session);
+ bytes = svm_fifo_max_dequeue (session->rx_fifo);
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+
+ if (bytes)
+ {
+ vppcom_ioevent_t *eio;
+ vce_event_t *ev;
+ u32 ev_idx;
+
+ clib_spinlock_lock (&vcm->event_thread.events_lockp);
+
+ pool_get (vcm->event_thread.vce_events, ev);
+ ev_idx = (u32) (ev - vcm->event_thread.vce_events);
+ eio = vce_get_event_data (ev, sizeof (*eio));
+ ev->evk.eid = VCL_EVENT_IOEVENT_RX_FIFO;
+ ev->evk.session_index = session_indexes[i];
+ eio->bytes = bytes;
+ eio->session_index = session_indexes[i];
+
+ clib_spinlock_unlock (&vcm->event_thread.events_lockp);
+
+ rv = vce_generate_event (&vcm->event_thread, ev_idx);
+ }
+ }
+ }
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000000; /* 1 millisecond */
+ nanosleep (&ts, NULL);
+ }
+done:
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ return NULL;
+}
+
+int
+vppcom_start_io_event_thread (vppcom_session_io_thread_t * evt,
+ u8 max_sessions)
+{
+ pthread_cond_init (&(evt->vce_io_cond), NULL);
+ pthread_mutex_init (&(evt->vce_io_lock), NULL);
+
+ clib_spinlock_init (&(evt->io_sessions_lockp));
+
+ return pthread_create (&(evt->thread), NULL /* attr */ ,
+ vppcom_session_io_thread_fn, evt);
+}
+
+