From 0acff566213fdddbc8f4561887aced121f82dc26 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 23 Apr 2014 18:12:53 -0400 Subject: 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. --- libdimension/future-internal.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'libdimension/future-internal.h') 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 * + * Copyright (C) 2010-2014 Tavian Barnes * * * * 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; }; -- cgit v1.2.3