From a0828074550f9c11c2904a66e205265e812423ff Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 30 Oct 2017 19:18:01 +0000 Subject: [PATCH] Fix locking in waitForEvent() and sample playing --- libs/core/linux.cpp | 2 ++ libs/core/pxt.h | 2 ++ libs/music/music.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/libs/core/linux.cpp b/libs/core/linux.cpp index b7322584..ac40c270 100644 --- a/libs/core/linux.cpp +++ b/libs/core/linux.cpp @@ -269,11 +269,13 @@ void waitForEvent(int source, int value) { pthread_mutex_lock(&eventMutex); t->waitSource = source; t->waitValue = value; + stopUser(); // spourious wake ups may occur they say while (t->waitSource) { pthread_cond_wait(&t->waitCond, &eventMutex); } pthread_mutex_unlock(&eventMutex); + startUser(); return; } } diff --git a/libs/core/pxt.h b/libs/core/pxt.h index e2a31439..0c62ad43 100644 --- a/libs/core/pxt.h +++ b/libs/core/pxt.h @@ -7,6 +7,8 @@ namespace pxt { void raiseEvent(int id, int event); int allocateNotifyEvent(); void sleep_core_us(uint64_t us); +void startUser(); +void stopUser(); class Button; typedef Button *Button_; diff --git a/libs/music/music.cpp b/libs/music/music.cpp index b9373c0e..5912ae5c 100644 --- a/libs/music/music.cpp +++ b/libs/music/music.cpp @@ -119,6 +119,7 @@ void playSample(Buffer buf) { pthread_detach(pid); } + stopUser(); pthread_mutex_lock(&pumpMutex); *lmsSoundMMap = 1; // BUSY uint8_t cmd[] = {SOUND_CMD_PLAY, (uint8_t)((currVolume / 33) + 1)}; @@ -130,6 +131,7 @@ void playSample(Buffer buf) { pumpMusic(); pthread_cond_wait(&sampleDone, &pumpMutex); pthread_mutex_unlock(&pumpMutex); + startUser(); } /**