<div class="gmail_quote">On Sun, Feb 17, 2013 at 3:57 AM, M Donalies <span dir="ltr"><<a href="mailto:ingeniousnebbish@cox.net" target="_blank">ingeniousnebbish@cox.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
No locks or mutexes in a callback function. I need to think about that one.<br></blockquote><div>This is indeed a "lovely" topic for debate. I'm bound to say that, I'm currently doing a final-year project for college on the topic.<br>
I've came up with a solution, which I feel is the best balance between C++-y style Event classes, and C-style simple code. Simple is great for<br>RT situations: its easy to see if something is RT or not. <br><br>In essence it boils down to this:<br>
<span style="font-family:courier new,monospace">-Create an "EventBase" class            with pure virtual type() and size() functions<br>-Derive actual events like "EventPlay"  overriding type() and size()<br>
-Create a ringbuffer                    checkout the example, it uses the JACK ringbuffer<br>-Create events *on the stack*           ie EventPlay eventPlay();<br>-Write events into the ringbuffer using jack_ringbuffer_write();</span><br>
<br>The last two steps are key, as they enfore the event gets *copied* into the ringbuffer, and the original goes out<br>of scope (and gets destroyed).<br><br>This solution is very workable, on the condition that only fundamental C datatypes are passed trough the Event class. <br>
Things will get nasty if you pass std::shared_ptr<> objects trough it, I've made that mistake already :)<br><br>The following code shows communication from the GUI thread to the RT thread. Create another ringbuffer and functions<br>
for communicating in the other direction.<br><br><a href="https://github.com/harryhaaren/realtimeAudioThreading">https://github.com/harryhaaren/realtimeAudioThreading</a><br><br>HTH, -Harry<br></div></div>