This is an automated email from the ASF dual-hosted git repository. rymek pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 4b5c5ef468ba0840ba22e3bc13e55c6e1736d0b1 Author: Mehul Hirpara <mehul.hirp...@inedasystems.com> AuthorDate: Wed Oct 24 17:56:11 2018 +0530 [porting][linux] Added timeout support to Eventq Get API This change helps to get event from eventq with 0 timeout period. --- porting/npl/linux/src/os_eventq.cc | 7 +++++-- porting/npl/linux/src/wqueue.h | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/porting/npl/linux/src/os_eventq.cc b/porting/npl/linux/src/os_eventq.cc index 2ede70b..a3c4b96 100644 --- a/porting/npl/linux/src/os_eventq.cc +++ b/porting/npl/linux/src/os_eventq.cc @@ -83,8 +83,11 @@ struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq, struct ble_npl_event *ev; wqueue_t *q = static_cast<wqueue_t *>(evq->q); - ev = q->get(); - ev->ev_queued = 0; + ev = q->get(tmo); + + if (ev) { + ev->ev_queued = 0; + } return ev; } diff --git a/porting/npl/linux/src/wqueue.h b/porting/npl/linux/src/wqueue.h index 8eb23b7..0a1e7cc 100644 --- a/porting/npl/linux/src/wqueue.h +++ b/porting/npl/linux/src/wqueue.h @@ -54,13 +54,21 @@ public: pthread_mutex_unlock(&m_mutex); } - T get() { + T get(uint32_t tmo) { pthread_mutex_lock(&m_mutex); - while (m_queue.size() == 0) { - pthread_cond_wait(&m_condv, &m_mutex); + if (tmo) { + while (m_queue.size() == 0) { + pthread_cond_wait(&m_condv, &m_mutex); + } } - T item = m_queue.front(); - m_queue.pop_front(); + + T item = NULL; + + if (m_queue.size() != 0) { + item = m_queue.front(); + m_queue.pop_front(); + } + pthread_mutex_unlock(&m_mutex); return item; }