>Hi LADs, >here is a problem that maybe very common with many rt audio apps, so >hopefully there is a "standard" solution for it? > >assume jack process callback reads audio data from a buffer, while >another thread might alter the >contents of this buffer. In my particular scenario, i will actualy use >doublebuffering. So the only operation that needs to be "mutexed" >is the actual swapping of front and back buffers (well, pointers, of >course, not the contents) > >Now my problem is: How can i make sure that swapping does not accure >during process (playback) callback?
you should use a lock free ringbuffer. we will be adding example code to the example-clients directory soon. existing code is in ardour's source base (for C++). the example code will be in example-clients/capture_client.c. if you are using a design where there are 2 threads both modifying the "same" data, you should use 2 lock free ringbuffers to hold pointers to buffers. one thread "reads" a new ptr from the 1st LFRB, and works on that buffer, then "writes" it to the other LFRB. the other thread "reads" a ptr from the 2nd LFRB, and when done with the buffer, writes the ptr to the 1st LFRB. think of the 1st LFRB as the "free" list, and the 2nd LFRB as the "todo" list, or something like that. beautiful, eh? :) you cannot under any circumstances have both threads working on the same buffer. --p
