From 941e583fe00aea19449843947eae9a934913b484 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 16 Feb 2009 16:26:02 +0000 Subject: [PATCH] Added proper locking of conditional variable mutex --- src/sound.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sound.cpp b/src/sound.cpp index 53c6fb0..73e8dda 100755 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -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 -- 2.37.2