Mercurial > hg > dmlib
changeset 292:43312a36811f
Improve locking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Oct 2012 16:00:55 +0300 |
parents | 701c3d22e0f9 |
children | bc2e8ce003d7 |
files | testpl.c |
diffstat | 1 files changed, 25 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/testpl.c Thu Oct 11 16:00:46 2012 +0300 +++ b/testpl.c Thu Oct 11 16:00:55 2012 +0300 @@ -221,22 +221,40 @@ // okay, main loop here ... "play" module and print out info printf("----------------------------------------------------\n"); + SDL_LockAudio(); SDL_PauseAudio(0); - while (plr->isPlaying) + SDL_UnlockAudio(); + BOOL playing = TRUE; + while (playing) { - int r = plr->row; - while (r == plr->row && plr->isPlaying) + JSSPattern *pattern; + int currRow, prevRow; + + JSS_LOCK(plr); + currRow = prevRow = plr->row; + JSS_UNLOCK(plr); + + while (currRow == prevRow && playing) + { + JSS_LOCK(plr); + currRow = plr->row; + playing = plr->isPlaying; + pattern = plr->pattern; + JSS_UNLOCK(plr); SDL_Delay(50); + } - printRow(stdout, plr->pattern, plr->row); - printf("\n"); + if (playing) + { + printRow(stdout, pattern, currRow); + printf("\n"); + } } printf("----------------------------------------------------\n"); + SDL_LockAudio(); SDL_PauseAudio(1); - - SDL_LockAudio(); jmpClose(plr); jvmClose(dev); jssFreeModule(mod);