New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin API Extension: SendReply
#5939
Comments
this sounds likea very good idea. The fact that this has been tested for a long time is also nice, so it will be well integrated. More opinions? |
Plugin commands are dispatched on the RT thread, so you definitely need to use the RT allocator. But let's take a step back. I guess what you (and I) really want is the possibility to send arbitrary reply messages back to the client. Now, the async command already has a copy of the reply address (otherwise it wouldn't be able to send a "done" message). Instead of requiring users to make their own (redundant) copies, we only need to pass the reply address to the callback functions. Therefore I would rather propose an extension to the
Then users can just call |
He he! The copying was actually following a suggestion you made in this forum thread, because we have the additional need to dispatch long-running tasks to a worker thread (to avoiding blocking the command queue overly long) and so need to persist a reply address until the job has finished some time later. |
Ha! I certainly did not remember that :-D
Right, makes sense. I guess we could additionally offer |
As a side note, I would also like to add an extension to the Unit command interface:
Then we could also use the new |
😄 FWIW, my reason for not using (Also, I can't remember off-hand if this was an issue, but our buffer processing stuff is also designed to be impervious to cmd-. from the client – And your new post just appeared whilst I was typing this! I see you have a real-time use case... |
I wouldn't worry too much about that. After all, every asynchronous command has to hit the RT memory allocator several times.
I'm not sure what you mean by "little left overs". Every bit of memory should be freed when it is no longer needed, otherwise you have a memory leak :-)
Uhhh, I think this just works by sheer accident. AFAICT, there is no guarantee that the reply address outlives the plugin command callback... |
As another side note, I was wondering whether we should also include a method to send a reply from the RT thread. I know it could be done with Instead, I would like to have something like This would be handy for synchronous plugin/unit commands where you don't need to go through the NRT thread. |
It's the longevity and quantity that concern me. If we have clients batch processing then lots of long-lived small allocations can add up (we already have users running into occasional problems like this if they throw a load of jobs on to the queue, and they start to exhaust the pool).
I mean that if the pool allocator is going to get confounded sooner or later by a lack of contiguous blocks, because lots of little chunks of
Yikes. I see now that the enclosing
But it still would go through the NRT thread under the hood, right? If |
The size of the
I wouldn't worry too much about fragmentation. Think about it: every single Synth occupies RT memory and peoply are using hundreds or thousands of long-lived Synths just fine. If you hit a wall, you can always increase the memory pool size. Also keep in mind that the RT memory pool uses free lists for each size categories. With very small objects chances are very high that you can take an existing slot before hitting the main linear allocator.
Exactly. At least for scsynth. Supernova uses a dedicated thread for sending client replies (see |
Cool, thanks – I'll stop worrying. And fix the existing lifetime bug in FluCoMa in the meantime! |
Motivation
Extending the Plugin API to allow sending OSC replies to clients directly from the Command FIFO thread.
Description of Proposed Feature
The Plugin API allows plugins to run custom jobs on the Command FIFO (i.e. not the audio thread) via
fDoAsyncronousCommand
. However, there is no publicly exposed way to send a reply to clients from this thread – the relevant function (inscsynth
),SendReply
is not in theInterfaceTable
. As a result one has to dispatch a reply back via the audio thread. This then creates problems for clients waiting on replies because an additional asynchronous indirection is introduced.This proposes that the Plugin API is extended with three functions:
SendReply
and two extra to copy and delete aReplyAddr
that is hidden behind avoid*
. Something likeIn FluCoMa we've ended up doing this 'illegally' by linking to the
ReplyAddr
structure and making these functions ourselves, because the pain for users outweighed the pain of doing something brittle and bad. Following some discussion in #5347 and flucoma/flucoma-sc#149, it looks like the coming bump in Boost versions will result in our comeuppance, hence making an official request.Plan for Implementation
The main thing is there being agreement on a mechanism for extending the plugin API robustly. If a mechanism were available, or in flight, I would happily and gratefully do the implementation for these functions.
For
scsynth
the implementation is trivial and FluCoMa's functions, which have been out in the world for some years without problems, can be transplanted directly.SendReply
merely forwards to an already existing internal function inSC_ReplyImpl.hpp
, and the other two functions are just casts and copies. In C++, from our code:(These aren't / mustn't be calle on the audio thread, so no need to use the real-time allocator)
The text was updated successfully, but these errors were encountered: