File: thread-check.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (51 lines) | stat: -rw-r--r-- 2,308 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include "../plugin.h"

static CLAP_CONSTEXPR const char CLAP_EXT_THREAD_CHECK[] = "clap.thread-check";

#ifdef __cplusplus
extern "C" {
#endif

/// @page thread-check
///
/// CLAP defines two symbolic threads:
///
/// main-thread:
///    This is the thread in which most of the interaction between the plugin and host happens.
///    It is usually the thread on which the GUI receives its events.
///    It isn't a realtime thread, yet this thread needs to respond fast enough to user interaction,
///    so it is recommended to run long and expensive tasks such as preset indexing or asset loading
///    in dedicated background threads.
///
/// audio-thread:
///    This thread is used for realtime audio processing. Its execution should be as deterministic
///    as possible to meet the audio interface's deadline (can be <1ms). In other words, there is a
///    known set of operations that should be avoided: malloc() and free(), mutexes (spin mutexes
///    are worse), I/O, waiting, ...
///    The audio-thread is something symbolic, there isn't one OS thread that remains the
///    audio-thread for the plugin lifetime. As you may guess, the host is likely to have a
///    thread pool and the plugin.process() call may be scheduled on different OS threads over time.
///    The most important thing is that there can't be two audio-threads at the same time. All the
///    functions marked with [audio-thread] **ARE NOT CONCURRENT**. The host may mark any OS thread,
///    including the main-thread as the audio-thread, as long as it can guarentee that only one OS
///    thread is the audio-thread at a time. The audio-thread can be seen as a concurrency guard for
///    all functions marked with [audio-thread].

// This interface is useful to do runtime checks and make
// sure that the functions are called on the correct threads.
// It is highly recommended that hosts implement this extension.
typedef struct clap_host_thread_check {
   // Returns true if "this" thread is the main thread.
   // [thread-safe]
   bool(CLAP_ABI *is_main_thread)(const clap_host_t *host);

   // Returns true if "this" thread is one of the audio threads.
   // [thread-safe]
   bool(CLAP_ABI *is_audio_thread)(const clap_host_t *host);
} clap_host_thread_check_t;

#ifdef __cplusplus
}
#endif