diff options
author | Dmitry Antipov <dmantipov@yandex.ru> | 2019-12-27 13:35:33 +0300 |
---|---|---|
committer | MOHIT AGRAWAL <moagrawa@redhat.com> | 2020-01-01 14:12:27 +0000 |
commit | 7555ebc629774b95a878678f8ab0946c3bcf2f32 (patch) | |
tree | 85d5c4bf69994e63130b33894cc1b5d1b018d554 /libglusterfs/src/syncop-utils.c | |
parent | 33453ec69af1070dd5e15dd99c14ebb43c4e88c2 (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
Diffstat (limited to 'libglusterfs/src/syncop-utils.c')
-rw-r--r-- | libglusterfs/src/syncop-utils.c | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c index 4167db465f4..d9f1723856d 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; } |