summaryrefslogtreecommitdiffstats
path: root/libdimension/threads.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-02-21 15:50:59 -0500
committerTavian Barnes <tavianator@gmail.com>2011-02-21 15:50:59 -0500
commitf69c955c28b7e5c2eaf4af036cb88480a8e433f3 (patch)
treea569fa4efcdddca8263c4c0e48a8b5eb9e17ca38 /libdimension/threads.h
parentbdaa9b42526cea72b30b400c1f40891a9204126d (diff)
downloaddimension-f69c955c28b7e5c2eaf4af036cb88480a8e433f3.tar.xz
New dmnsn_execute_concurrently internal API.
This gets all pthread code out of raytrace.c.
Diffstat (limited to 'libdimension/threads.h')
-rw-r--r--libdimension/threads.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/libdimension/threads.h b/libdimension/threads.h
index 7ae6288..fdf2df7 100644
--- a/libdimension/threads.h
+++ b/libdimension/threads.h
@@ -34,6 +34,16 @@
typedef int dmnsn_thread_fn(void *ptr);
/**
+ * Thread callback type for parallel tasks.
+ * @param[in,out] ptr An arbitrary pointer.
+ * @param[in] thread An ID for this thread, in [0, \p nthreads).
+ * @param[in] nthreads The number of concurrent threads.
+ * @return 0 on success, non-zero on failure.
+ */
+typedef int dmnsn_concurrent_thread_fn(void *ptr, unsigned int thread,
+ unsigned int nthreads);
+
+/**
* Create a thread that cleans up after itself on errors.
* @param[in,out] progress The progress object to associate with the thread.
* @param[in] thread_fn The thread callback.
@@ -42,4 +52,14 @@ typedef int dmnsn_thread_fn(void *ptr);
void dmnsn_new_thread(dmnsn_progress *progress, dmnsn_thread_fn *thread_fn,
void *arg);
+/**
+ * Run \p nthreads threads in parallel.
+ * @param[in] thread_fn The routine to run in each concurrent thread.
+ * @param[in,out] arg The pointer to pass to the thread callbacks.
+ * @param[in] nthreads The number of concurrent threads to run.
+ * @return 0 if all threads were successful, and an error code otherwise.
+ */
+int dmnsn_execute_concurrently(dmnsn_concurrent_thread_fn *thread_fn,
+ void *arg, unsigned int nthreads);
+
#endif /* DIMENSION_IMPL_THREADS_H */