summaryrefslogtreecommitdiffstats
path: root/libdimension/future.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-04-26 15:08:09 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-04-26 15:08:09 -0400
commit12c4a5eb07f346083a59bc7d18567b2df3ed94ee (patch)
tree638017b057b81d34935048d1b4c4bb7472614d88 /libdimension/future.c
parent0acff566213fdddbc8f4561887aced121f82dc26 (diff)
downloaddimension-12c4a5eb07f346083a59bc7d18567b2df3ed94ee.tar.xz
future: Add a dmnsn_future_is_done() function.
Diffstat (limited to 'libdimension/future.c')
-rw-r--r--libdimension/future.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/libdimension/future.c b/libdimension/future.c
index 8d9c0c8..622d40e 100644
--- a/libdimension/future.c
+++ b/libdimension/future.c
@@ -114,6 +114,20 @@ dmnsn_future_progress(const dmnsn_future *future)
return progress;
}
+/* Find out whether the task is complete. */
+bool
+dmnsn_future_is_done(const dmnsn_future *future)
+{
+ dmnsn_future *mfuture = MUTATE(future);
+ bool result;
+
+ dmnsn_lock_mutex(&mfuture->mutex);
+ result = future->progress == future->total;
+ dmnsn_unlock_mutex(&mfuture->mutex);
+
+ return result;
+}
+
/* Wait until dmnsn_future_progress(future) >= progress */
void
dmnsn_future_wait(const dmnsn_future *future, double progress)
@@ -217,7 +231,7 @@ dmnsn_future_increment(dmnsn_future *future)
/* Immediately set to 100% completion */
void
-dmnsn_future_done(dmnsn_future *future)
+dmnsn_future_finish(dmnsn_future *future)
{
dmnsn_lock_mutex(&future->mutex);
future->progress = future->total;
@@ -241,15 +255,15 @@ dmnsn_future_set_nthreads(dmnsn_future *future, unsigned int nthreads)
/* Notify completion of a worker thread */
void
-dmnsn_future_thread_done(dmnsn_future *future)
+dmnsn_future_finish_thread(dmnsn_future *future)
{
dmnsn_lock_mutex(&future->mutex);
dmnsn_assert(future->nthreads > 0,
- "dmnsn_future_thread_done() called with no threads");
+ "dmnsn_future_finish_thread() called with no threads");
--future->nthreads;
dmnsn_assert(future->nrunning > 0,
- "dmnsn_future_thread_done() called with no running threads");
+ "dmnsn_future_finish_thread() called with no running threads");
if (--future->nrunning == 0) {
dmnsn_cond_broadcast(&future->none_running_cond);
}