Fix locking in waitForEvent() and sample playing
This commit is contained in:
parent
e8e31e6aa7
commit
a082807455
@ -269,11 +269,13 @@ void waitForEvent(int source, int value) {
|
|||||||
pthread_mutex_lock(&eventMutex);
|
pthread_mutex_lock(&eventMutex);
|
||||||
t->waitSource = source;
|
t->waitSource = source;
|
||||||
t->waitValue = value;
|
t->waitValue = value;
|
||||||
|
stopUser();
|
||||||
// spourious wake ups may occur they say
|
// spourious wake ups may occur they say
|
||||||
while (t->waitSource) {
|
while (t->waitSource) {
|
||||||
pthread_cond_wait(&t->waitCond, &eventMutex);
|
pthread_cond_wait(&t->waitCond, &eventMutex);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&eventMutex);
|
pthread_mutex_unlock(&eventMutex);
|
||||||
|
startUser();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ namespace pxt {
|
|||||||
void raiseEvent(int id, int event);
|
void raiseEvent(int id, int event);
|
||||||
int allocateNotifyEvent();
|
int allocateNotifyEvent();
|
||||||
void sleep_core_us(uint64_t us);
|
void sleep_core_us(uint64_t us);
|
||||||
|
void startUser();
|
||||||
|
void stopUser();
|
||||||
|
|
||||||
class Button;
|
class Button;
|
||||||
typedef Button *Button_;
|
typedef Button *Button_;
|
||||||
|
@ -119,6 +119,7 @@ void playSample(Buffer buf) {
|
|||||||
pthread_detach(pid);
|
pthread_detach(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopUser();
|
||||||
pthread_mutex_lock(&pumpMutex);
|
pthread_mutex_lock(&pumpMutex);
|
||||||
*lmsSoundMMap = 1; // BUSY
|
*lmsSoundMMap = 1; // BUSY
|
||||||
uint8_t cmd[] = {SOUND_CMD_PLAY, (uint8_t)((currVolume / 33) + 1)};
|
uint8_t cmd[] = {SOUND_CMD_PLAY, (uint8_t)((currVolume / 33) + 1)};
|
||||||
@ -130,6 +131,7 @@ void playSample(Buffer buf) {
|
|||||||
pumpMusic();
|
pumpMusic();
|
||||||
pthread_cond_wait(&sampleDone, &pumpMutex);
|
pthread_cond_wait(&sampleDone, &pumpMutex);
|
||||||
pthread_mutex_unlock(&pumpMutex);
|
pthread_mutex_unlock(&pumpMutex);
|
||||||
|
startUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user