Nope, I'm not going to suggest a complete threading API here. That -
if it's ever going to be part of XAP - will have to way until we know
what we're doing. (Use pthreads for now. Just don't get any ideas
about toolkits and stuff...)
What I *am* going to suggest is this:
XAP host call:
/*
* Calls a function as a "background job".
* 'context' is the worker call thread ID.
* 'data' is passet to the worker callback
*/
int (*worker_call)(XAP_host *host,
int (*callback)(),
int context, void *data);
XAP event:
/*
* Notify a plugin that one of it's worker
* calls has returned.
*/
XAP_A_WORKER_DONE(int result, void *data)
'context' is used to handle serializing when you want to prevent
multiple workers running at the same time. For example, saying "1"
for all workers you start guarantees that only one of them will run
at a time. If you use different context IDs, the workers may run
concurently on different CPUs, for example.
'data' is user defined data that is passed to the worker thread.
Obviously, you should keep your hands off this data until you get it
back (through XAP_A_WORKER_DONE), since the worker is supposed to be
running in a different thread. You may break this rule if you
*really* know what you're doing. Lock-free FIFOs and similar
constructs that are thread safe by design may be shared. Do note,
however, that hosts are not *required* to actually run worker calls
in another thread!
<maybe>
If this doesn't work for you, you must have a hint
"REQUIRES_WORKER_THREAD" that tells hosts that don't provide
out-of-thread worker calls to stay away from your plugin.
FIXME: Plugins that will work in different ways depending on
whether workers are in a separate thread or not, should
probably be able to tell, preferably during instantiation.
</maybe>
The XAP_A_WORKER_DONE event is sent to the calling plugin as the
worker call returns. 'result' is the return value from the callback,
and 'data' is the 'data' argument passed to the worker call through
host->worker_call().
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`--------------------------->
http://olofson.net/audiality -'
---
http://olofson.net ---
http://www.reologica.se ---