summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-09-30 17:28:21 -0400
committerTavian Barnes <tavianator@gmail.com>2010-09-30 17:29:05 -0400
commitc532ad114ef3f9964077522d137e6e1355a1ec1b (patch)
tree0684b85335b79c3756451587ca4a6e5d3175a5ff
parent32ccbb213b2a2d419581690d42611c375c3d22cf (diff)
downloaddimension-c532ad114ef3f9964077522d137e6e1355a1ec1b.tar.xz
Drop rwlock in progress.c on errors.
-rw-r--r--libdimension/progress.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/libdimension/progress.c b/libdimension/progress.c
index f7a8b62..51e7992 100644
--- a/libdimension/progress.c
+++ b/libdimension/progress.c
@@ -28,9 +28,20 @@ typedef struct {
} dmnsn_progress_element;
/* For thread synchronization */
-static void dmnsn_progress_rdlock(const dmnsn_progress *progress);
-static void dmnsn_progress_wrlock(dmnsn_progress *progress);
-static void dmnsn_progress_unlock(const dmnsn_progress *progress);
+
+static void dmnsn_progress_rdlock_impl(const dmnsn_progress *progress);
+static void dmnsn_progress_wrlock_impl(dmnsn_progress *progress);
+static void dmnsn_progress_unlock_impl(void *arg);
+
+#define dmnsn_progress_rdlock(progress) \
+ dmnsn_progress_rdlock_impl(progress); \
+ pthread_cleanup_push(&dmnsn_progress_unlock_impl, (void *)progress);
+#define dmnsn_progress_wrlock(progress) \
+ dmnsn_progress_wrlock_impl(progress); \
+ pthread_cleanup_push(&dmnsn_progress_unlock_impl, (void *)progress);
+#define dmnsn_progress_unlock(progress) \
+ pthread_cleanup_pop(1);
+
/* Allocate a new dmnsn_progress* */
dmnsn_progress *
@@ -222,7 +233,7 @@ dmnsn_done_progress(dmnsn_progress *progress)
/* Thread synchronization */
static void
-dmnsn_progress_rdlock(const dmnsn_progress *progress)
+dmnsn_progress_rdlock_impl(const dmnsn_progress *progress)
{
if (pthread_rwlock_rdlock(progress->rwlock) != 0) {
dmnsn_error(DMNSN_SEVERITY_MEDIUM, "Couldn't acquire read-lock.");
@@ -230,7 +241,7 @@ dmnsn_progress_rdlock(const dmnsn_progress *progress)
}
static void
-dmnsn_progress_wrlock(dmnsn_progress *progress)
+dmnsn_progress_wrlock_impl(dmnsn_progress *progress)
{
if (pthread_rwlock_wrlock(progress->rwlock) != 0) {
dmnsn_error(DMNSN_SEVERITY_MEDIUM, "Couldn't acquire write-lock.");
@@ -238,8 +249,9 @@ dmnsn_progress_wrlock(dmnsn_progress *progress)
}
static void
-dmnsn_progress_unlock(const dmnsn_progress *progress)
+dmnsn_progress_unlock_impl(void *arg)
{
+ const dmnsn_progress *progress = arg;
if (pthread_rwlock_unlock(progress->rwlock) != 0) {
dmnsn_error(DMNSN_SEVERITY_MEDIUM, "Couldn't unlock read-write lock.");
}