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>
This commit is contained in:
Pranith Kumar K 2018-04-23 21:04:58 +05:30
parent afadc4d6f4
commit 93464ffd6d
2 changed files with 27 additions and 4 deletions

View File

@ -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;
}

View File

@ -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 */