Hey guys!
I am trying to implement sound output using OS X CoreAudio APIs. The problem is that CoreAudio wants to pull PCM data from me via so called render callback and it calls this callback from another thread. I can just call gameGetSoundSamples() from my render callback but I think it's a bad idea because I don't want gameGetSoundSamples() to think about thread-safety.
What I want to do is to somehow pull data from the game using gameGetSoundSamples() in my main loop and somehow make this data accessible for my render callback. The only solution I have in my mind is to implement a kind of ring buffer like DirectSound does. My main loop can write to this buffer when it gets new data from the game and my render callback can read from it when it's asked for new data by CoreAudio. But then I need to somehow make this ring buffer operations thread-safe.
What other options do I have? If I really want to make this DirectSound-style ring buffer how can I make it thread-safe? Apple reference pages say that I can't just use locks because my render callback should return immediately without blocking on anything. Maybe I should try to use some API for atomic operations?