I am writing a program under Linux that utilizes both playback and record using ALSA (connected to a custom device). I would like to use the asynchronous callback architecture for both reading and writing data.
However, I have been unable to get any information with respect to the limitations of what I am allowed to do inside the callback. Specifically, do I have to be aynchronous-safe? If so, this seems to severely restrict what can be done, since among other things, I should not reference any global variables, making it rather hard to, for example, read from a buffer that is filled by the main thread of execution or write to a buffer which is subsequently saved to file outside the callback.
Is there any C concurrency constructs that I can use in the ALSA callbacks to coordinate use of globals with the main thread? For example, can I use POSIX semaphores? Do I have any guarantee that the ALSA callback is atomic with respect to the main thread (I know it's not atomic to other ALSA callbacks)?
Many thanks for any insight that people can bring to bear upon this.