diff options
author | Florin Coras <fcoras@cisco.com> | 2018-10-12 16:55:14 -0700 |
---|---|---|
committer | Florin Coras <fcoras@cisco.com> | 2018-10-12 17:00:16 -0700 |
commit | 83ea669b2193a112ff1e3440efb9df78085b4616 (patch) | |
tree | 6ff7ee82b9c7a7a684ac9c33e3f3ed6a10a109a8 /src/vnet/session | |
parent | e78bca16af86014b2340a1561ad8eacff86cbbaf (diff) |
session: don't wait indefinitely for apps to consume evts (VPP-1454)
Change-Id: I544b24d2b2c4a09829773cf180d1747f4b087d4c
Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/session')
-rwxr-xr-x | src/vnet/session/session_api.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index fc63428277e..e82be560b1f 100755 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -422,6 +422,23 @@ static session_cb_vft_t session_cb_vft = { }; static int +mq_try_lock_and_alloc_msg (svm_msg_q_t * app_mq, svm_msg_q_msg_t * msg) +{ + int rv; + u8 try = 0; + while (try < 100) + { + rv = svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, + SESSION_MQ_CTRL_EVT_RING, + SVM_Q_NOWAIT, msg); + if (!rv) + return 0; + try++; + } + return -1; +} + +static int mq_send_session_accepted_cb (stream_session_t * s) { app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); @@ -436,8 +453,8 @@ mq_send_session_accepted_cb (stream_session_t * s) app = application_get (app_wrk->app_index); app_mq = app_wrk->event_queue; - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return -1; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); @@ -523,8 +540,8 @@ mq_send_session_disconnected_cb (stream_session_t * s) app = application_get (app_wrk->app_index); app_mq = app_wrk->event_queue; - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_DISCONNECTED; @@ -544,8 +561,8 @@ mq_send_session_reset_cb (stream_session_t * s) session_event_t *evt; app_mq = app->event_queue; - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_RESET; @@ -576,8 +593,8 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, return -1; } - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return -1; evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_CONNECTED; @@ -656,8 +673,9 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context, return -1; } - svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, - SVM_Q_WAIT, msg); + if (mq_try_lock_and_alloc_msg (app_mq, msg)) + return -1; + evt = svm_msg_q_msg_data (app_mq, msg); memset (evt, 0, sizeof (*evt)); evt->event_type = SESSION_CTRL_EVT_BOUND; |