summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar K <pkarampu@redhat.com>2018-04-23 21:04:58 +0530
committerPranith Kumar K <pkarampu@redhat.com>2018-04-23 21:24:31 +0530
commit93464ffd6dcbe2a2f91c0e35f933f814f523e9be (patch)
tree815ee9db505cd8dd5fd81652dfe8981f94ebc1b3
parentafadc4d6f4cd52651c2849bc8337fc66ce8c72e6 (diff)
libglusterfs/syncop: Handle barrier_{init/destroy} in error cases
BUG: 1568521 updates: bz#1568521 Change-Id: I53e60cfcaa7f8edfa5eca47307fa99f10ee64505 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
-rw-r--r--libglusterfs/src/syncop.c30
-rw-r--r--libglusterfs/src/syncop.h1
2 files changed, 27 insertions, 4 deletions
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
index 5cae4fbb3a0..58477770368 100644
--- a/libglusterfs/src/syncop.c
+++ b/libglusterfs/src/syncop.c
@@ -1087,30 +1087,52 @@ synclock_unlock (synclock_t *lock)
int
syncbarrier_init (struct syncbarrier *barrier)
{
+ int ret = 0;
if (!barrier) {
errno = EINVAL;
return -1;
}
- pthread_cond_init (&barrier->cond, 0);
+ ret = pthread_cond_init (&barrier->cond, 0);
+ if (ret) {
+ errno = ret;
+ return -1;
+ }
barrier->count = 0;
barrier->waitfor = 0;
INIT_LIST_HEAD (&barrier->waitq);
- return pthread_mutex_init (&barrier->guard, 0);
+ ret = pthread_mutex_init (&barrier->guard, 0);
+ if (ret) {
+ (void)pthread_cond_destroy (&barrier->cond);
+ errno = ret;
+ return -1;
+ }
+ barrier->initialized = _gf_true;
+ return 0;
}
int
syncbarrier_destroy (struct syncbarrier *barrier)
{
+ int ret = 0;
+ int ret1 = 0;
if (!barrier) {
errno = EINVAL;
return -1;
}
- pthread_cond_destroy (&barrier->cond);
- return pthread_mutex_destroy (&barrier->guard);
+ if (barrier->initialized) {
+ ret = pthread_cond_destroy (&barrier->cond);
+ ret1 = pthread_mutex_destroy (&barrier->guard);
+ barrier->initialized = _gf_false;
+ }
+ if (ret || ret1) {
+ errno = ret?ret:ret1;
+ return -1;
+ }
+ return 0;
}
diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h
index 682191f0243..367204d05b7 100644
--- a/libglusterfs/src/syncop.h
+++ b/libglusterfs/src/syncop.h
@@ -134,6 +134,7 @@ typedef struct synclock synclock_t;
struct syncbarrier {
+ gf_boolean_t initialized; /*Set on successful initialization*/
pthread_mutex_t guard; /* guard the remaining members, pair @cond */
pthread_cond_t cond; /* waiting non-synctasks */
struct list_head waitq; /* waiting synctasks */