Remove almost all instances of "volatile" keyword.

As Tiffany pointed out in Bugzilla, volatile is not useful for thread safety:

https://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/

Some of these volatiles didn't need to be, some were otherwise protected by
spinlocks or mutexes, and some got moved over to SDL_atomic_t data, etc.

Fixes Bugzilla #3220.
This commit is contained in:
Ryan C. Gordon 2016-01-03 06:50:50 -05:00
parent 21f66ea295
commit fa8c83c1c1
11 changed files with 66 additions and 72 deletions

View file

@ -25,7 +25,7 @@ typedef struct
{
SDL_AudioDeviceID dev;
int soundpos;
volatile int done;
SDL_atomic_t done;
} callback_data;
callback_data cbd[64];
@ -46,14 +46,14 @@ play_through_once(void *arg, Uint8 * stream, int len)
if (len > 0) {
stream += cpy;
SDL_memset(stream, spec.silence, len);
cbd->done++;
SDL_AtomicSet(&cbd->done, 1);
}
}
void
loop()
{
if(cbd[0].done) {
if (SDL_AtomicGet(&cbd[0].done)) {
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#endif
@ -100,8 +100,7 @@ test_multi_audio(int devcount)
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!cbd[0].done)
{
while (!SDL_AtomicGet(&cbd[0].done)) {
#ifdef __ANDROID__
/* Empty queue, some application events would prevent pause. */
while (SDL_PollEvent(&event)){}
@ -136,7 +135,7 @@ test_multi_audio(int devcount)
while (keep_going) {
keep_going = 0;
for (i = 0; i < devcount; i++) {
if ((cbd[i].dev) && (!cbd[i].done)) {
if ((cbd[i].dev) && (!SDL_AtomicGet(&cbd[i].done))) {
keep_going = 1;
}
}