diff options
author | Florin Coras <fcoras@cisco.com> | 2020-11-27 09:49:10 -0800 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2020-11-30 16:05:59 +0000 |
commit | 2440a8a6e72a1fb156fce3f38ef3ae8cd2a527d8 (patch) | |
tree | da054371c94e55e691458f30b2279214d25ec01d | |
parent | 7d8a956287e2b19059f041c77a57480f437fe2bf (diff) |
svm: make svm queue mutex robust
Type: improvement
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I256774c25b3c4105139a4728724a1a0c775e740f
-rw-r--r-- | src/svm/message_queue.h | 5 | ||||
-rw-r--r-- | src/svm/queue.c | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/svm/message_queue.h b/src/svm/message_queue.h index 37293fc29d1..13f4d80d215 100644 --- a/src/svm/message_queue.h +++ b/src/svm/message_queue.h @@ -311,7 +311,10 @@ svm_msg_q_try_lock (svm_msg_q_t * mq) static inline int svm_msg_q_lock (svm_msg_q_t * mq) { - return pthread_mutex_lock (&mq->q->mutex); + int rv = pthread_mutex_lock (&mq->q->mutex); + if (PREDICT_FALSE (rv == EOWNERDEAD)) + rv = pthread_mutex_consistent (&mq->q->mutex); + return rv; } /** diff --git a/src/svm/queue.c b/src/svm/queue.c index 8d70dda61a3..96383d44f3d 100644 --- a/src/svm/queue.c +++ b/src/svm/queue.c @@ -51,6 +51,8 @@ svm_queue_init (void *base, int nels, int elsize) clib_unix_warning ("mutexattr_init"); if (pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED)) clib_unix_warning ("pthread_mutexattr_setpshared"); + if (pthread_mutexattr_setrobust (&attr, PTHREAD_MUTEX_ROBUST)) + clib_unix_warning ("setrobust"); if (pthread_mutex_init (&q->mutex, &attr)) clib_unix_warning ("mutex_init"); if (pthread_mutexattr_destroy (&attr)) @@ -96,7 +98,9 @@ svm_queue_free (svm_queue_t * q) void svm_queue_lock (svm_queue_t * q) { - pthread_mutex_lock (&q->mutex); + int rv = pthread_mutex_lock (&q->mutex); + if (PREDICT_FALSE (rv == EOWNERDEAD)) + pthread_mutex_consistent (&q->mutex); } void |