From: Erik de Castro Lopo Date: Sat, 11 Jun 2016 07:57:06 +0000 (+1000) Subject: Add two new locks X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=61eae8754e58e3c9455d09ef8bd70c0b88b3f9db;p=liskon_frotz.git Add two new locks --- diff --git a/Makefile b/Makefile index 4df1267..330555f 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ MAN_PREFIX = $(PREFIX) CONFIG_DIR = /etc #CONFIG_DIR = $(PREFIX)/etc -# Pick your sound support. The most featureful form of sound support is +# Pick your sound support. The most featureful form of sound support is # through libao. Comment all of these out if you don't want sound. # #SOUND = none @@ -30,8 +30,8 @@ SOUND = ao ########################################################################## -# The configuration options below are intended mainly for older flavors -# of Unix. For Linux, BSD, and Solaris released since 2003, you can +# The configuration options below are intended mainly for older flavors +# of Unix. For Linux, BSD, and Solaris released since 2003, you can # ignore this section. ########################################################################## @@ -44,7 +44,7 @@ COLOR = yes CURSES = -lncurses #CURSES = -lcurses -# Just in case your operating system keeps its user-added header files +# Just in case your operating system keeps its user-added header files # somewhere unusual... # #INCL = -I/usr/local/include @@ -67,8 +67,8 @@ CURSES = -lncurses #NO_MEMMOVE = yes # Default sample rate for sound effects. -# All modern sound interfaces can be expected to support 44100 Hz sample -# rates. Earlier ones, particularly ones in Sun 4c workstations support +# All modern sound interfaces can be expected to support 44100 Hz sample +# rates. Earlier ones, particularly ones in Sun 4c workstations support # only up to 8000 Hz. SAMPLERATE = 44100 @@ -123,7 +123,8 @@ CURSES_OBJECT = $(CURSES_DIR)/ux_init.o \ $(CURSES_DIR)/ux_blorb.o \ $(CURSES_DIR)/ux_audio.o \ $(CURSES_DIR)/ux_resource.o \ - $(CURSES_DIR)/ux_audio_none.o + $(CURSES_DIR)/ux_audio_none.o \ + $(CURSES_DIR)/ux_locks.o DUMB_DIR = $(SRCDIR)/dumb DUMB_TARGET = $(SRCDIR)/frotz_dumb.a diff --git a/src/curses/ux_audio.c b/src/curses/ux_audio.c index 3e2f7e9..13d094c 100644 --- a/src/curses/ux_audio.c +++ b/src/curses/ux_audio.c @@ -36,6 +36,7 @@ #endif #include "ux_frotz.h" +#include "ux_locks.h" #ifndef NO_SOUND @@ -99,7 +100,6 @@ bool music_stop = FALSE; float *musicbuffer; int musicsamples; -int musicnum; /* @@ -259,8 +259,8 @@ void os_stop_sample (int number) while(pthread_kill(playaiff_id, 0) == 0); } - if (music_playing && (number == musicnum || number == 0)) { - music_playing = FALSE; + if (get_music_playing() && (number == get_musicnum () || number == 0)) { + set_music_playing(false); while(pthread_kill(playmusic_id, 0) == 0); } @@ -456,7 +456,7 @@ static int mypower(int base, int exp) { * handled here. * * This function should be able to play OGG chunks, but because of a bug - * or oversight in Libsndfile, that library is incapable of playing OGG + * or oversight in Libsndfile, that library is incapable of playing OGG * data which are embedded in a larger file. * */ @@ -631,7 +631,7 @@ static void *playmod(EFFECT *raw_effect) EFFECT myeffect = *raw_effect; - musicnum = myeffect.number; + set_musicnum(myeffect.number); filestart = ftell(myeffect.fp); fseek(myeffect.fp, myeffect.result.data.startpos, SEEK_SET); diff --git a/src/curses/ux_locks.c b/src/curses/ux_locks.c new file mode 100644 index 0000000..08f02a4 --- /dev/null +++ b/src/curses/ux_locks.c @@ -0,0 +1,60 @@ + +#include +#include + +#include "ux_locks.h" + +static bool music_playing = false; +static pthread_mutex_t music_playing_mutex = PTHREAD_MUTEX_INITIALIZER; + +static int musicnum = 0; +static pthread_mutex_t musicnum_mutex = PTHREAD_MUTEX_INITIALIZER; + +bool +get_music_playing (void) +{ + bool value; + + pthread_mutex_lock (&music_playing_mutex); + value = music_playing; + pthread_mutex_unlock (&music_playing_mutex); + return value; +} + + +bool +set_music_playing (bool new_value) +{ + bool old_value; + + pthread_mutex_lock (&music_playing_mutex); + old_value = music_playing; + music_playing = new_value; + pthread_mutex_unlock (&music_playing_mutex); + return old_value; +} + + +int +get_musicnum (void) +{ + int value; + + pthread_mutex_lock (&musicnum_mutex); + value = musicnum; + pthread_mutex_unlock (&musicnum_mutex); + return value; +} + + +int +set_musicnum (int new_value) +{ + int old_value; + + pthread_mutex_lock (&musicnum_mutex); + old_value = musicnum; + musicnum = new_value; + pthread_mutex_unlock (&musicnum_mutex); + return old_value; +} diff --git a/src/curses/ux_locks.h b/src/curses/ux_locks.h new file mode 100644 index 0000000..a289469 --- /dev/null +++ b/src/curses/ux_locks.h @@ -0,0 +1,5 @@ +bool get_music_playing (void); +bool set_music_playing (bool new_value); + +int get_musicnum (void); +int set_musicnum (int new_value);