summaryrefslogtreecommitdiffstats
path: root/daemons/clvmd
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2011-10-11 09:26:04 +0000
committerZdenek Kabelac <zkabelac@redhat.com>2011-10-11 09:26:04 +0000
commit96de8adcc9388b84d7d1ecbea19d36cae17bb071 (patch)
tree0e2364d702951d79a0939abf4526aa3cded3facf /daemons/clvmd
parent61a45c7b3a8570ee1fe54669bdfeadb731d3e712 (diff)
downloadlvm2-96de8adcc9388b84d7d1ecbea19d36cae17bb071.tar.gz
lvm2-96de8adcc9388b84d7d1ecbea19d36cae17bb071.tar.xz
lvm2-96de8adcc9388b84d7d1ecbea19d36cae17bb071.zip
Use barrier instead of mutex
Barrier is supposed to be used in situation like this and replace tricky mutex usage, where mutex has been unlocked by a different thread than the locking thread.
Diffstat (limited to 'daemons/clvmd')
-rw-r--r--daemons/clvmd/clvmd.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 9e97eb64..c61ca9e8 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -89,7 +89,7 @@ static const size_t STACK_SIZE = 128 * 1024;
static pthread_attr_t stack_attr;
static pthread_mutex_t lvm_thread_mutex;
static pthread_cond_t lvm_thread_cond;
-static pthread_mutex_t lvm_start_mutex;
+static pthread_barrier_t lvm_start_barrier;
static struct dm_list lvm_cmd_head;
static volatile sig_atomic_t quit = 0;
static volatile sig_atomic_t reread_config = 0;
@@ -505,7 +505,7 @@ int main(int argc, char *argv[])
}
pthread_mutex_init(&lvm_thread_mutex, NULL);
pthread_cond_init(&lvm_thread_cond, NULL);
- pthread_mutex_init(&lvm_start_mutex, NULL);
+ pthread_barrier_init(&lvm_start_barrier, NULL, 2);
init_lvhash();
/* Start the cluster interface */
@@ -584,9 +584,11 @@ int main(int argc, char *argv[])
DEBUGLOG("starting LVM thread\n");
/* Don't let anyone else to do work until we are started */
- pthread_mutex_lock(&lvm_start_mutex);
pthread_create(&lvm_thread, &stack_attr, lvm_thread_fn, &lvm_params);
+ /* Don't start until the LVM thread is ready */
+ pthread_barrier_wait(&lvm_start_barrier);
+
/* Tell the rest of the cluster our version number */
if (clops->cluster_init_completed)
clops->cluster_init_completed();
@@ -1633,11 +1635,6 @@ static __attribute__ ((noreturn)) void *pre_and_post_thread(void *arg)
DEBUGLOG("in sub thread: client = %p\n", client);
pthread_mutex_lock(&client->bits.localsock.mutex);
- /* Don't start until the LVM thread is ready */
- pthread_mutex_lock(&lvm_start_mutex);
- pthread_mutex_unlock(&lvm_start_mutex);
- DEBUGLOG("Sub thread ready for work.\n");
-
/* Ignore SIGUSR1 (handled by master process) but enable
SIGUSR2 (kills subthreads) */
sigemptyset(&ss);
@@ -2004,7 +2001,8 @@ static void *lvm_thread_fn(void *arg)
init_clvm(lvm_params->excl_uuid);
/* Allow others to get moving */
- pthread_mutex_unlock(&lvm_start_mutex);
+ pthread_barrier_wait(&lvm_start_barrier);
+ DEBUGLOG("Sub thread ready for work.\n");
/* Now wait for some actual work */
while (!quit) {