You should not need to make a copy (mData=*foobar;) like that... rather you could simply use the shared object directly; the whole point of this class is to make such direct sharing safe. Note that even though usually the advice is that "critical sections should be short" this thing is specifically designed with the intention that you can perfectly well call rtLock() once at the very beginning of your DSP process-function and then rtRelease() at the very end.Code:
// dspFoobar *foobar = shared_foobar.rtLock();if (foobar) {if (foobar->mDirtyGUI) {mData = *foobar;foobar->mDirtyGUI = false;}}shared_foobar.rtRelease(); // let GUI thread know we don't need it anymore
Locking for a longer time will potentially make swapAndWait() in the GUI thread potentially "slow" as it'll have to wait for one full DSP process call in the worst case, but unless the DSP blocksize is completely ridiculous (even 4k buffers at 44.1kHz is only 100ms), this is not a huge deal for something only called once in a while.
For actually sending messages at regular basis (ie. if you don't need to share an allocated object), just use a queue instead.
Statistics: Posted by mystran — Fri Jul 12, 2024 12:42 pm