]> Shamusworld >> Repos - apple2/commitdiff
Added proper locking of conditional variable mutex
authorShamus Hammons <jlhamm@acm.org>
Mon, 16 Feb 2009 16:26:02 +0000 (16:26 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 16 Feb 2009 16:26:02 +0000 (16:26 +0000)
src/sound.cpp

index 53c6fb05ef6389df9fb366bb6faecaff51675e65..73e8ddaeda2867ba34e7ededfb0e49e77073fbd3 100755 (executable)
@@ -95,7 +95,7 @@ return;
        conditional = SDL_CreateCond();
        mutex = SDL_CreateMutex();
        mutex2 = SDL_CreateMutex();// Let's try real signalling...
-       SDL_mutexP(mutex);                                                      // Must lock the mutex for the cond to work properly...
+//     SDL_mutexP(mutex);                                                      // Must lock the mutex for the cond to work properly...
        soundBufferPos = 0;
        sampleBase = 0;
        lastToggleCycles = 0;
@@ -266,7 +266,9 @@ Seems like it's OK now that I've fixed the buffer-less-than-length bug...
 // Hm.
 // This might not empty the buffer enough, causing hash and trash. !!! FIX !!!
 SDL_mutexV(mutex2);//Release it so sound thread can get it,
+       SDL_mutexP(mutex);                                                      // Must lock the mutex for the cond to work properly...
 SDL_CondWait(conditional, mutex);//Sleep/wait for the sound thread
+       SDL_mutexV(mutex);                                                      // Must unlock the mutex for the cond to work properly...
 SDL_mutexP(mutex2);//Re-lock it until we're done with it...
 
 //             currentPos = sampleBase + (uint32)((double)deltaCycles / CYCLES_PER_SAMPLE);
@@ -363,7 +365,9 @@ printf("SOUND: AdjustLastToggleCycles() start...\n");
                // Hm.
                // This might not empty the buffer enough, causing hash and trash. !!! FIX !!! [DONE]
                SDL_mutexV(mutex2);//Release it so sound thread can get it,
+               SDL_mutexP(mutex);                                                      // Must lock the mutex for the cond to work properly...
                SDL_CondWait(conditional, mutex);//Sleep/wait for the sound thread
+               SDL_mutexV(mutex);                                                      // Must unlock the mutex for the cond to work properly...
                SDL_mutexP(mutex2);//Re-lock it until we're done with it...
 
 //HMM, this doesn't need to lock or recalculate this value