diff options
author | John Kacur <jkacur@redhat.com> | 2015-06-30 23:46:34 +0200 |
---|---|---|
committer | John Kacur <jkacur@redhat.com> | 2015-06-30 23:46:34 +0200 |
commit | 4010c3bce2a8141d614b11e49780b11b575e6b4d (patch) | |
tree | 813b7349e6e9164b725d6818246614f917a4f9d1 | |
parent | a7eeb3e0a0cc1fe3e2a0cdb4fdafd93067f04b4a (diff) | |
download | rt-tests-4010c3bce2a8141d614b11e49780b11b575e6b4d.tar.gz |
Fix possible exit on error without releasing mutex
Coverage tools indicate that there are two spots where the function
low_priority() could exit without releasing the mutex.
Since the only error that pthread_barrier_wait is supposed to give is
EINVAL when the barrier is not an initialized barrier object, the
chances of this happinning seem remote. However, if we are going to
test for the error and potentially exit, then we should release the
mutex too.
Signed-off-by: John Kacur <jkacur@redhat.com>
-rw-r--r-- | src/pi_tests/pi_stress.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c index aaa36c3..1d1cc58 100644 --- a/src/pi_tests/pi_stress.c +++ b/src/pi_tests/pi_stress.c @@ -727,17 +727,24 @@ void *low_priority(void *arg) status = pthread_barrier_wait(&p->locked_barrier); if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) { pi_error - ("low_priority[%d]: pthread_barrier_wait(locked): %x\n", - p->id, status); + ("low_priority[%d]: pthread_barrier_wait(locked): %x\n", + p->id, status); + /* release the mutex */ + pi_debug("low_priority[%d]: unlocking mutex\n", p->id); + pthread_mutex_unlock(&p->mutex); return NULL; } + /* wait for priority boost */ pi_debug("low_priority[%d]: entering elevated wait\n", p->id); status = pthread_barrier_wait(&p->elevate_barrier); if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) { pi_error - ("low_priority[%d]: pthread_barrier_wait(elevate): %x\n", - p->id, status); + ("low_priority[%d]: pthread_barrier_wait(elevate): %x\n", + p->id, status); + /* release the mutex */ + pi_debug("low_priority[%d]: unlocking mutex\n", p->id); + pthread_mutex_unlock(&p->mutex); return NULL; } |