From f41c18fee48065c60af60cc95f043fd1c74840d1 Mon Sep 17 00:00:00 2001 From: John Janus Date: Fri, 22 Sep 2017 18:39:59 +0200 Subject: [PATCH] remove segfault --- Makefile | 2 +- simple_try.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1697d80..eab35e1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -std=gnu11 -Wall -O2 +CFLAGS = -std=gnu11 -Wall -g LDFLAGS = -lpthread -lao -lmpg123 -lwiringPi fakeradio : mp3player.o main.o $(CC) $(CFLAGS) -o fakeradio main.o mp3player.o $(LDFLAGS) diff --git a/simple_try.c b/simple_try.c index 82ceafb..d0ca308 100644 --- a/simple_try.c +++ b/simple_try.c @@ -69,6 +69,7 @@ void introBtn(void) { if (delaying || pwrOn) return; pthread_mutex_lock(mut); intro = !intro; + horn = false; pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -77,6 +78,7 @@ void hornBtn(void) { if (delaying || pwrOn) return; pthread_mutex_lock(mut); horn = !horn; + intro = false; pthread_mutex_unlock(mut); pthread_cond_signal(wakeup); } @@ -125,6 +127,7 @@ int main(void) { delaying = true; if (playThread) { pthread_cancel(playThread); + pthread_join(playThread, NULL); } if (!pwrOn) { @@ -135,10 +138,8 @@ int main(void) { if (intro) { playThread = startPlayThread("intro.mp3", true); digitalWrite(INTROLED, LOW); - horn = false; } else if (horn) { playThread = startPlayThread("nebelhorn.mp3", true); - intro = false; digitalWrite(INTROLED, HIGH); } else { digitalWrite(INTROLED, HIGH); -- 2.47.1