diff options
author | Paul Irofti <pirofti@cvs.openbsd.org> | 2012-04-23 08:30:34 +0000 |
---|---|---|
committer | Paul Irofti <pirofti@cvs.openbsd.org> | 2012-04-23 08:30:34 +0000 |
commit | 26a31b20226a49e9bbdd8fc56a225187e51f26d3 (patch) | |
tree | 40d6a5918cdc103074b92099d61a7278c1af5b01 | |
parent | 799ac7ff7d33af37a298b666e4c6847e0e9073d4 (diff) |
Honor subsystem style.
`Visual inspection looks ok' kurt@.
>From Brad
-rw-r--r-- | lib/librthread/rthread_barrier.c | 83 | ||||
-rw-r--r-- | lib/librthread/rthread_barrier_attr.c | 43 |
2 files changed, 55 insertions, 71 deletions
diff --git a/lib/librthread/rthread_barrier.c b/lib/librthread/rthread_barrier.c index f205b0c9f40..9643cb893b3 100644 --- a/lib/librthread/rthread_barrier.c +++ b/lib/librthread/rthread_barrier.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_barrier.c,v 1.1 2012/04/11 10:18:46 pirofti Exp $ */ +/* $OpenBSD: rthread_barrier.c,v 1.2 2012/04/23 08:30:33 pirofti Exp $ */ /* * Copyright (c) 2012 Paul Irofti <pirofti@openbsd.org> * @@ -28,47 +28,42 @@ pthread_barrier_init(pthread_barrier_t *barrier, pthread_barrierattr_t *attr, int rc = 0; pthread_barrier_t b = NULL; - if (barrier == NULL) { - return EINVAL; - } + if (barrier == NULL) + return (EINVAL); + if (attr != NULL) { - if (*attr == NULL) { - return EINVAL; - } - if ((*attr)->pshared != PTHREAD_PROCESS_PRIVATE) { - return ENOTSUP; - } + if (*attr == NULL) + return (EINVAL); + + if ((*attr)->pshared != PTHREAD_PROCESS_PRIVATE) + return (ENOTSUP); } b = calloc(1, sizeof *b); - if (b == NULL) { - return ENOMEM; - } + if (b == NULL) + return (ENOMEM); - if ((rc = pthread_mutex_init(&b->mutex, NULL))) { + if ((rc = pthread_mutex_init(&b->mutex, NULL))) goto err; - } - if ((rc = pthread_cond_init(&b->cond, NULL))) { + if ((rc = pthread_cond_init(&b->cond, NULL))) goto err; - } b->threshold = count; *barrier = b; - return 0; + return (0); err: if (b) { - if (b->mutex) { + if (b->mutex) pthread_mutex_destroy(&b->mutex); - } - if (b->cond) { + if (b->cond) pthread_cond_destroy(&b->cond); - } free(b); } - return rc; + + return (rc); } int @@ -76,21 +71,19 @@ pthread_barrier_destroy(pthread_barrier_t *barrier) { pthread_barrier_t b; - if (barrier == NULL || *barrier == NULL) { - return EINVAL; - } + if (barrier == NULL || *barrier == NULL) + return (EINVAL); b = *barrier; - if (b->sofar > 0) { - return EBUSY; - } + if (b->sofar > 0) + return (EBUSY); *barrier = NULL; pthread_mutex_destroy(&b->mutex); pthread_cond_destroy(&b->cond); free(b); - return 0; + return (0); } int @@ -100,46 +93,40 @@ pthread_barrier_wait(pthread_barrier_t *barrier) int rc, old_state, gen; int done = 0; - if (barrier == NULL || *barrier == NULL) { - return EINVAL; - } + if (barrier == NULL || *barrier == NULL) + return (EINVAL); - if ((rc = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state))) { - return rc; - } + if ((rc = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state))) + return (rc); b = *barrier; - if ((rc = pthread_mutex_lock(&b->mutex))) { + if ((rc = pthread_mutex_lock(&b->mutex))) goto cancel; - } _rthread_debug(6, "sofar: %d, threshold: %d\n", b->sofar, b->threshold); if (++b->sofar == b->threshold) { b->sofar = 0; b->generation++; - if ((rc = pthread_cond_broadcast(&b->cond))) { + if ((rc = pthread_cond_broadcast(&b->cond))) goto err; - } done = 1; _rthread_debug(6, "threshold reached\n"); } else { gen = b->generation; _rthread_debug(6, "waiting on condition\n"); do { - if ((rc = pthread_cond_wait(&b->cond, &b->mutex))) { + if ((rc = pthread_cond_wait(&b->cond, &b->mutex))) goto err; - } } while (gen == b->generation); } err: - if ((rc = pthread_mutex_unlock(&b->mutex))) { - return rc; - } + if ((rc = pthread_mutex_unlock(&b->mutex))) + return (rc); cancel: rc = pthread_setcancelstate(old_state, NULL); - if (rc == 0 && done) { + if (rc == 0 && done) rc = PTHREAD_BARRIER_SERIAL_THREAD; - } - return rc; + + return (rc); } diff --git a/lib/librthread/rthread_barrier_attr.c b/lib/librthread/rthread_barrier_attr.c index 54f44ed232c..5d51e1dc5e7 100644 --- a/lib/librthread/rthread_barrier_attr.c +++ b/lib/librthread/rthread_barrier_attr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_barrier_attr.c,v 1.1 2012/04/11 10:18:46 pirofti Exp $ */ +/* $OpenBSD: rthread_barrier_attr.c,v 1.2 2012/04/23 08:30:33 pirofti Exp $ */ /* * Copyright (c) 2012 Paul Irofti <pirofti@openbsd.org> * @@ -25,52 +25,49 @@ int pthread_barrierattr_init(pthread_barrierattr_t *attr) { - if (attr == NULL) { - return EINVAL; - } + if (attr == NULL) + return (EINVAL); *attr = calloc(1, sizeof **attr); - if (*attr == NULL) { - return ENOMEM; - } + if (*attr == NULL) + return (ENOMEM); (*attr)->pshared = PTHREAD_PROCESS_PRIVATE; - return 0; + return (0); } int pthread_barrierattr_destroy(pthread_barrierattr_t *attr) { - if (attr == NULL || *attr == NULL) { - return EINVAL; - } + if (attr == NULL || *attr == NULL) + return (EINVAL); + free(*attr); - return 0; + return (0); } int pthread_barrierattr_getpshared(pthread_barrierattr_t *attr, int *pshared) { - if (attr == NULL || *attr == NULL) { - return EINVAL; - } + if (attr == NULL || *attr == NULL) + return (EINVAL); + *pshared = (*attr)->pshared; - return 0; + + return (0); } int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared) { - if (attr == NULL || *attr == NULL) { - return EINVAL; - } + if (attr == NULL || *attr == NULL) + return (EINVAL); - if (pshared != PTHREAD_PROCESS_PRIVATE) { - return ENOTSUP; - } + if (pshared != PTHREAD_PROCESS_PRIVATE) + return (ENOTSUP); (*attr)->pshared = pshared; - return 0; + return (0); } |