Mercurial > hg > beaglert
changeset 381:a0698d523a6a prerelease
Added check for already-running Bela process.
author | andrewm |
---|---|
date | Sun, 12 Jun 2016 23:20:37 +0100 |
parents | 9dc5a0ccad25 |
children | bcc033b46636 |
files | core/RTAudio.cpp |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/RTAudio.cpp Sun Jun 12 23:03:57 2016 +0100 +++ b/core/RTAudio.cpp Sun Jun 12 23:20:37 2016 +0100 @@ -99,6 +99,22 @@ int Bela_initAudio(BelaInitSettings *settings, void *userData) { + // First check if there's a Bela program already running on the board. + // We can't have more than one instance at a time, but we can tell via + // the Xenomai task info. We expect the rt_task_bind call to fail so if it + // doesn't then it means something else is running. + RT_TASK otherBelaTask; + int returnVal = rt_task_bind(&otherBelaTask, gRTAudioThreadName, TM_NONBLOCK); + if(returnVal == 0) { + cout << "Error: Bela is already running in another process. Cannot start.\n"; + rt_task_unbind(&otherBelaTask); + return -1; + } + else if(returnVal != -EWOULDBLOCK && returnVal != -ETIMEDOUT) { + cout << "Error " << returnVal << " occurred determining if another Bela task is running.\n"; + return -1; + } + // Sanity checks if(settings->pruNumber < 0 || settings->pruNumber > 1) { cout << "Invalid PRU number " << settings->pruNumber << endl;