comparison testpl.c @ 292:43312a36811f

Improve locking.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 11 Oct 2012 16:00:55 +0300
parents c6cdaa675801
children 2b5472173355
comparison
equal deleted inserted replaced
291:701c3d22e0f9 292:43312a36811f
219 jmpPlayOrder(plr, 0); 219 jmpPlayOrder(plr, 0);
220 jvmSetGlobalVol(dev, 60); 220 jvmSetGlobalVol(dev, 60);
221 221
222 // okay, main loop here ... "play" module and print out info 222 // okay, main loop here ... "play" module and print out info
223 printf("----------------------------------------------------\n"); 223 printf("----------------------------------------------------\n");
224 SDL_LockAudio();
224 SDL_PauseAudio(0); 225 SDL_PauseAudio(0);
225 while (plr->isPlaying) 226 SDL_UnlockAudio();
226 { 227 BOOL playing = TRUE;
227 int r = plr->row; 228 while (playing)
228 while (r == plr->row && plr->isPlaying) 229 {
230 JSSPattern *pattern;
231 int currRow, prevRow;
232
233 JSS_LOCK(plr);
234 currRow = prevRow = plr->row;
235 JSS_UNLOCK(plr);
236
237 while (currRow == prevRow && playing)
238 {
239 JSS_LOCK(plr);
240 currRow = plr->row;
241 playing = plr->isPlaying;
242 pattern = plr->pattern;
243 JSS_UNLOCK(plr);
229 SDL_Delay(50); 244 SDL_Delay(50);
230 245 }
231 printRow(stdout, plr->pattern, plr->row); 246
232 printf("\n"); 247 if (playing)
248 {
249 printRow(stdout, pattern, currRow);
250 printf("\n");
251 }
233 } 252 }
234 253
235 printf("----------------------------------------------------\n"); 254 printf("----------------------------------------------------\n");
236 255
256 SDL_LockAudio();
237 SDL_PauseAudio(1); 257 SDL_PauseAudio(1);
238
239 SDL_LockAudio();
240 jmpClose(plr); 258 jmpClose(plr);
241 jvmClose(dev); 259 jvmClose(dev);
242 jssFreeModule(mod); 260 jssFreeModule(mod);
243 SDL_UnlockAudio(); 261 SDL_UnlockAudio();
244 262