summaryrefslogtreecommitdiffstats
path: root/libdimension/future-internal.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-04-23 18:12:53 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-04-23 22:41:21 -0400
commit0acff566213fdddbc8f4561887aced121f82dc26 (patch)
tree97620a5ef72efc783d35817e4349a9f8a1d8cff8 /libdimension/future-internal.h
parent3ce3ed46f5cd95bfca4f9303c93859fac54476bb (diff)
downloaddimension-0acff566213fdddbc8f4561887aced121f82dc26.tar.xz
future: Add a race-free way to examine a partial computation.
This allows safe OpenGL previews, for example. dmnsn_future* learned the dmnsn_future_{pause,resume}() functions which cause all worker threads to block. render.test now survives Helgrind with no errors.
Diffstat (limited to 'libdimension/future-internal.h')
-rw-r--r--libdimension/future-internal.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/libdimension/future-internal.h b/libdimension/future-internal.h
index 4ec6f75..644a486 100644
--- a/libdimension/future-internal.h
+++ b/libdimension/future-internal.h
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2010-2013 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2010-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Library. *
* *
@@ -34,6 +34,11 @@ DMNSN_INTERNAL void dmnsn_future_set_total(dmnsn_future *future, size_t total);
DMNSN_INTERNAL void dmnsn_future_increment(dmnsn_future *future);
/** Instantly complete the background teask. */
DMNSN_INTERNAL void dmnsn_future_done(dmnsn_future *future);
+/** Set the number of worker threads. */
+DMNSN_INTERNAL void dmnsn_future_set_nthreads(dmnsn_future *future,
+ unsigned int nthreads);
+/** Notify completion of a worker thread. */
+DMNSN_INTERNAL void dmnsn_future_thread_done(dmnsn_future *future);
struct dmnsn_future {
size_t progress; /**< Completed loop iterations. */
@@ -50,4 +55,17 @@ struct dmnsn_future {
/** Minimum waited-on value. */
double min_wait;
+
+ /** Number of threads working on the future's background task. */
+ unsigned int nthreads;
+ /** Number of threads not yet paused. */
+ unsigned int nrunning;
+ /** Count of threads holding the future paused. */
+ unsigned int npaused;
+ /** Condition variable for waiting for nrunning == 0. */
+ pthread_cond_t none_running_cond;
+ /** Condition variable for waiting for nrunning == nthreads. */
+ pthread_cond_t all_running_cond;
+ /** Condition variable for waiting for npaused == 0. */
+ pthread_cond_t resume_cond;
};