From 3dde8d45c13cb979e605e11dc4df58aa70f6afd7 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 29 Oct 2018 13:26:16 +0100 Subject: [PATCH] Add _empty_p & _pop_move_blocking --- m-concurrent.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/m-concurrent.h b/m-concurrent.h index 3c1c0e6c..782c40b8 100644 --- a/m-concurrent.h +++ b/m-concurrent.h @@ -167,6 +167,17 @@ M_CALL_CLEAN(oplist, out->data); \ m_mutex_unlock (out->lock); \ } \ + ,) \ + \ + M_IF_METHOD(TEST_EMPTY, oplist)( \ + static inline bool \ + M_C(name, _empty_p)(concurrent_t out) \ + { \ + m_mutex_lock (out->lock); \ + bool b = M_CALL_TEST_EMPTY(oplist, out->data); \ + m_mutex_unlock (out->lock); \ + return b; \ + } \ ,) \ \ M_IF_METHOD(SET_KEY, oplist)( \ @@ -361,6 +372,25 @@ m_mutex_unlock (out->lock); \ return ret; \ } \ + ,) \ + \ + M_IF_METHOD2(POP_MOVE, TEST_EMPTY, oplist)( \ + static inline bool \ + M_C(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ + { \ + bool ret = false; \ + m_mutex_lock (out->lock); \ + while (blocking) { \ + if (!M_CALL_TEST_EMPTY(oplist, out->data)) { \ + M_CALL_POP_MOVE(oplist, p, out->data); \ + ret = true; \ + break; \ + } \ + m_cond_wait(out->there_is_data, out->lock); \ + } \ + m_mutex_unlock (out->lock); \ + return ret; \ + } \ ,) \ #endif