From cec47afae217cea36779d7dea4437b35dee63be2 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 29 Sep 2010 17:49:49 -0400 Subject: Make parts of the progress API internal. --- libdimension/progress.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'libdimension/progress.c') diff --git a/libdimension/progress.c b/libdimension/progress.c index aeac2ac..f7a8b62 100644 --- a/libdimension/progress.c +++ b/libdimension/progress.c @@ -65,29 +65,6 @@ dmnsn_new_progress() return progress; } -/* Delete a dmnsn_progress*, which has not yet been associated with a thread */ -void -dmnsn_delete_progress(dmnsn_progress *progress) -{ - if (progress) { - if (pthread_rwlock_destroy(progress->rwlock) != 0) { - dmnsn_error(DMNSN_SEVERITY_LOW, "Leaking rwlock."); - } - if (pthread_mutex_destroy(progress->mutex) != 0) { - dmnsn_error(DMNSN_SEVERITY_LOW, "Leaking mutex."); - } - if (pthread_cond_destroy(progress->cond) != 0) { - dmnsn_error(DMNSN_SEVERITY_LOW, "Leaking condition variable."); - } - - dmnsn_free(progress->rwlock); - dmnsn_free(progress->mutex); - dmnsn_free(progress->cond); - dmnsn_delete_array(progress->elements); - dmnsn_free(progress); - } -} - /* Join the worker thread and delete `progress'. */ int dmnsn_finish_progress(dmnsn_progress *progress) @@ -96,6 +73,7 @@ dmnsn_finish_progress(dmnsn_progress *progress) int retval = -1; if (progress) { + /* Get the thread's return value */ if (pthread_join(progress->thread, &ptr) != 0) { /* Medium severity because an unjoined thread likely means that the thread is incomplete or invalid */ @@ -103,10 +81,23 @@ dmnsn_finish_progress(dmnsn_progress *progress) } else if (ptr) { retval = *(int *)ptr; dmnsn_free(ptr); - /* Wake up all waiters */ - dmnsn_done_progress(progress); } - dmnsn_delete_progress(progress); + + /* Free the progress object */ + if (pthread_rwlock_destroy(progress->rwlock) != 0) { + dmnsn_error(DMNSN_SEVERITY_LOW, "Leaking rwlock."); + } + if (pthread_mutex_destroy(progress->mutex) != 0) { + dmnsn_error(DMNSN_SEVERITY_LOW, "Leaking mutex."); + } + if (pthread_cond_destroy(progress->cond) != 0) { + dmnsn_error(DMNSN_SEVERITY_LOW, "Leaking condition variable."); + } + dmnsn_free(progress->rwlock); + dmnsn_free(progress->mutex); + dmnsn_free(progress->cond); + dmnsn_delete_array(progress->elements); + dmnsn_free(progress); } return retval; -- cgit v1.2.3