diff options
author | Florin Coras <fcoras@cisco.com> | 2020-12-02 07:57:00 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2020-12-03 16:05:27 +0000 |
commit | 1d56ac423ce25da14dce69194ceebaeda6f47f18 (patch) | |
tree | 4711975b7396a46c0c2e24a75045d455ac3deaf0 /src/svm/queue.c | |
parent | d7adc293d377f4691b0285f62363c3958c68d235 (diff) |
svm: fix mutex consistency on trylock
Type: fix
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I1370943935b460a1a1a22847fed2c97b1272a5e1
Diffstat (limited to 'src/svm/queue.c')
-rw-r--r-- | src/svm/queue.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/svm/queue.c b/src/svm/queue.c index 96383d44f3d..864d97e3de4 100644 --- a/src/svm/queue.c +++ b/src/svm/queue.c @@ -103,6 +103,15 @@ svm_queue_lock (svm_queue_t * q) pthread_mutex_consistent (&q->mutex); } +static int +svm_queue_trylock (svm_queue_t * q) +{ + int rv = pthread_mutex_trylock (&q->mutex); + if (PREDICT_FALSE (rv == EOWNERDEAD)) + rv = pthread_mutex_consistent (&q->mutex); + return rv; +} + void svm_queue_unlock (svm_queue_t * q) { @@ -256,7 +265,7 @@ svm_queue_add (svm_queue_t * q, u8 * elem, int nowait) if (nowait) { /* zero on success */ - if (pthread_mutex_trylock (&q->mutex)) + if (svm_queue_trylock (q)) { return (-1); } @@ -306,7 +315,7 @@ svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait) if (nowait) { /* zero on success */ - if (pthread_mutex_trylock (&q->mutex)) + if (svm_queue_trylock (q)) { return (-1); } @@ -367,7 +376,7 @@ svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond, if (cond == SVM_Q_NOWAIT) { /* zero on success */ - if (pthread_mutex_trylock (&q->mutex)) + if (svm_queue_trylock (q)) { return (-1); } |