commit 7667bf6696b6150ccf4a28b2da39bddcc30921da
parent ffa9b9c838fc7a02439a70068fc9a04d50c9ada8
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Thu, 6 May 2021 00:05:56 +0200
Improve the thread-pool interface documentation
Diffstat:
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/include/clap/all.h b/include/clap/all.h
@@ -21,6 +21,7 @@
#include "ext/draft/preset-load.h"
#include "ext/draft/remote-controls.h"
#include "ext/draft/thread-check.h"
+#include "ext/draft/thread-pool.h"
#include "ext/draft/track-info.h"
#include "ext/draft/tuning.h"
#include "ext/draft/vst2-convert.h"
diff --git a/include/clap/ext/draft/thread-pool.h b/include/clap/ext/draft/thread-pool.h
@@ -8,7 +8,7 @@ extern "C" {
/// @page
///
-/// This extension let the plugin use the host's thread pool
+/// This extension let the plugin use the host's thread pool.
///
/// The plugin must provide @ref clap_plugin_thread_pool, and the host may provide @ref
/// clap_host_thread_pool. If it doesn't, the plugin should process its data by its own mean. In the
@@ -22,12 +22,14 @@ extern "C" {
/// compute_voice(plugin, voice_index);
/// }
///
-/// void myplud_process(clap_plugin *plugin, const clap_process *process)
+/// void myplug_process(clap_plugin *plugin, const clap_process *process)
/// {
/// ...
+/// bool didComputeVoices = false;
/// if (host_thread_pool && host_thread_pool.exec)
-/// host_thread_pool.exec(host, plugin, N);
-/// else
+/// didComputeVoices = host_thread_pool.request_exec(host, plugin, N);
+///
+/// if (!didComputeVoices)
/// for (uint32_t i = 0; i < N; ++i)
/// myplug_thread_pool_exec(plugin, N);
/// ...
@@ -45,7 +47,12 @@ typedef struct clap_host_thread_pool {
// Schedule num_tasks jobs in the host thread pool.
// It can't be called concurrently or from the thread pool.
// Will block until all the tasks are processed.
- void (*exec)(clap_host *host, clap_plugin *plugin, uint32_t num_tasks);
+ // This must be used exclusively for realtime processing within the process call.
+ // Returns true if the host did execute all the tasks, false if it rejected the request.
+ // The host should check that the plugin is within the process call, and if not, reject the exec
+ // request.
+ // [audio-thread]
+ bool (*request_exec)(clap_host *host, clap_plugin *plugin, uint32_t num_tasks);
} clap_host_thread_pool;
#ifdef __cplusplus