diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2011-10-11 09:54:39 +0000 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2011-10-11 09:54:39 +0000 |
commit | 8a706f836d76154e2f65922d29c0e4acf7da5aa2 (patch) | |
tree | 5dba2c0bcd8cb4f5fe7684c9f862b5624a689d9d /daemons/clvmd/clvmd.c | |
parent | 96de8adcc9388b84d7d1ecbea19d36cae17bb071 (diff) | |
download | lvm2-8a706f836d76154e2f65922d29c0e4acf7da5aa2.tar.gz lvm2-8a706f836d76154e2f65922d29c0e4acf7da5aa2.tar.xz lvm2-8a706f836d76154e2f65922d29c0e4acf7da5aa2.zip |
Simplify worker loop
Do not reacquire mutex several times without a real reason.
Code readability is also better.
Diffstat (limited to 'daemons/clvmd/clvmd.c')
-rw-r--r-- | daemons/clvmd/clvmd.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c index c61ca9e8..1bb7995d 100644 --- a/daemons/clvmd/clvmd.c +++ b/daemons/clvmd/clvmd.c @@ -1988,6 +1988,7 @@ static void *lvm_thread_fn(void *arg) struct dm_list *cmdl, *tmp; sigset_t ss; struct lvm_startup_params *lvm_params = arg; + struct lvm_thread_cmd *cmd; DEBUGLOG("LVM thread function started\n"); @@ -2005,18 +2006,15 @@ static void *lvm_thread_fn(void *arg) DEBUGLOG("Sub thread ready for work.\n"); /* Now wait for some actual work */ - while (!quit) { - DEBUGLOG("LVM thread waiting for work\n"); + pthread_mutex_lock(&lvm_thread_mutex); - pthread_mutex_lock(&lvm_thread_mutex); - if (dm_list_empty(&lvm_cmd_head)) + while (!quit) { + if (dm_list_empty(&lvm_cmd_head)) { + DEBUGLOG("LVM thread waiting for work\n"); pthread_cond_wait(&lvm_thread_cond, &lvm_thread_mutex); - - dm_list_iterate_safe(cmdl, tmp, &lvm_cmd_head) { - struct lvm_thread_cmd *cmd; - - cmd = - dm_list_struct_base(cmdl, struct lvm_thread_cmd, list); + } else { + cmd = dm_list_item(dm_list_first(&lvm_cmd_head), + struct lvm_thread_cmd); dm_list_del(&cmd->list); pthread_mutex_unlock(&lvm_thread_mutex); @@ -2026,9 +2024,10 @@ static void *lvm_thread_fn(void *arg) pthread_mutex_lock(&lvm_thread_mutex); } - pthread_mutex_unlock(&lvm_thread_mutex); } + pthread_mutex_unlock(&lvm_thread_mutex); + pthread_exit(NULL); } |