summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2019-12-27 13:35:33 +0300
committerMOHIT AGRAWAL <moagrawa@redhat.com>2020-01-01 14:12:27 +0000
commit7555ebc629774b95a878678f8ab0946c3bcf2f32 (patch)
tree85d5c4bf69994e63130b33894cc1b5d1b018d554
parent33453ec69af1070dd5e15dd99c14ebb43c4e88c2 (diff)
cli, libglusterfs: rely on libpthread static initializers
cli-cmd.c: drop cli_cmd_cond_init() because static mutex and condition variable are initialized with PTHREAD_xxx_INITIALIZERs. syncop-utils.c: since assignment PTHREAD_xxx_INITIALIZERs are never failed, a few overengineered bits may be simplified. Change-Id: Ic4d250a1697047386989f73f058b0abc8b55627b Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Updates: bz#1193929
-rw-r--r--cli/src/cli-cmd.c12
-rw-r--r--cli/src/cli-cmd.h3
-rw-r--r--cli/src/cli.c4
-rw-r--r--libglusterfs/src/syncop-utils.c37
4 files changed, 11 insertions, 45 deletions
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index c8a8447..af00975 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -232,18 +232,6 @@ out:
}
int
-cli_cmd_cond_init()
-{
- pthread_mutex_init(&cond_mutex, NULL);
- pthread_cond_init(&cond, NULL);
-
- pthread_mutex_init(&conn_mutex, NULL);
- pthread_cond_init(&conn, NULL);
-
- return 0;
-}
-
-int
cli_cmd_lock()
{
pthread_mutex_lock(&cond_mutex);
diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h
index b6bc565..c1c068c 100644
--- a/cli/src/cli-cmd.h
+++ b/cli/src/cli-cmd.h
@@ -102,9 +102,6 @@ int
cli_cmd_broadcast_response(int32_t status);
int
-cli_cmd_cond_init();
-
-int
cli_cmd_lock();
int
diff --git a/cli/src/cli.c b/cli/src/cli.c
index fac32d3..cb425c8 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -854,10 +854,6 @@ main(int argc, char *argv[])
if (ret)
goto out;
- ret = cli_cmd_cond_init();
- if (ret)
- goto out;
-
ret = cli_input_init(&state);
if (ret)
goto out;
diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c
index 4167db4..d9f1723 100644
--- a/libglusterfs/src/syncop-utils.c
+++ b/libglusterfs/src/syncop-utils.c
@@ -345,10 +345,8 @@ syncop_mt_dir_scan(call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
gf_dirent_t *tmp = NULL;
uint32_t jobs_running = 0;
uint32_t qlen = 0;
- pthread_cond_t cond;
- pthread_mutex_t mut;
- gf_boolean_t cond_init = _gf_false;
- gf_boolean_t mut_init = _gf_false;
+ pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+ pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
gf_dirent_t entries;
xlator_t *this = NULL;
@@ -378,15 +376,6 @@ syncop_mt_dir_scan(call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
INIT_LIST_HEAD(&entries.list);
INIT_LIST_HEAD(&q.list);
- ret = pthread_mutex_init(&mut, NULL);
- if (ret)
- goto out;
- mut_init = _gf_true;
-
- ret = pthread_cond_init(&cond, NULL);
- if (ret)
- goto out;
- cond_init = _gf_true;
while ((ret = syncop_readdir(subvol, fd, 131072, offset, &entries, xdata,
NULL))) {
@@ -452,21 +441,17 @@ syncop_mt_dir_scan(call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid,
out:
if (fd)
fd_unref(fd);
- if (mut_init && cond_init) {
- pthread_mutex_lock(&mut);
- {
- while (jobs_running)
- pthread_cond_wait(&cond, &mut);
- }
- pthread_mutex_unlock(&mut);
- gf_dirent_free(&q);
- gf_dirent_free(&entries);
+
+ pthread_mutex_lock(&mut);
+ {
+ while (jobs_running)
+ pthread_cond_wait(&cond, &mut);
}
+ pthread_mutex_unlock(&mut);
+
+ gf_dirent_free(&q);
+ gf_dirent_free(&entries);
- if (mut_init)
- pthread_mutex_destroy(&mut);
- if (cond_init)
- pthread_cond_destroy(&cond);
return ret | retval;
}