From f895e611df0ed22fefe5f71853f18bccbf67f65d Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 25 Mar 2010 13:45:59 -0400 Subject: [PATCH] Add recursive locks This patch adds recursive locks necessary due to the processing of network filter XML that can reference other network filters, including references that cause looks. Loops in the XML are prevented but their detection requires recursive locks. Signed-off-by: Stefan Berger --- src/util/threads-pthread.c | 13 +++++++++++++ src/util/threads-win32.c | 5 +++++ src/util/threads.h | 1 + 3 files changed, 19 insertions(+) diff --git a/src/util/threads-pthread.c b/src/util/threads-pthread.c index 2f0746bb26..030b33fcaf 100644 --- a/src/util/threads-pthread.c +++ b/src/util/threads-pthread.c @@ -46,6 +46,19 @@ int virMutexInit(virMutexPtr m) return 0; } +int virMutexInitRecursive(virMutexPtr m) +{ + int ret; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if ((ret = pthread_mutex_init(&m->lock, &attr)) != 0) { + errno = ret; + return -1; + } + return 0; +} + void virMutexDestroy(virMutexPtr m) { pthread_mutex_destroy(&m->lock); diff --git a/src/util/threads-win32.c b/src/util/threads-win32.c index ef3f2ef2c0..b1d15712cb 100644 --- a/src/util/threads-win32.c +++ b/src/util/threads-win32.c @@ -68,6 +68,11 @@ void virThreadOnExit(void) int virMutexInit(virMutexPtr m) +{ + virMutexInitRecursive(m); +} + +int virMutexInitRecursive(virMutexPtr m) { if (!(m->lock = CreateMutex(NULL, FALSE, NULL))) { errno = ESRCH; diff --git a/src/util/threads.h b/src/util/threads.h index 36fc6002be..6e010829ff 100644 --- a/src/util/threads.h +++ b/src/util/threads.h @@ -38,6 +38,7 @@ int virThreadInitialize(void) ATTRIBUTE_RETURN_CHECK; void virThreadOnExit(void); int virMutexInit(virMutexPtr m) ATTRIBUTE_RETURN_CHECK; +int virMutexInitRecursive(virMutexPtr m) ATTRIBUTE_RETURN_CHECK; void virMutexDestroy(virMutexPtr m); void virMutexLock(virMutexPtr m); -- GitLab