# HG changeset patch # User andrewm # Date 1465770037 -3600 # Node ID a0698d523a6ae2fb06010c4612bf4ad45e5b364f # Parent 9dc5a0ccad2569e8d8eb3ca0c1ef4167005d38cb Added check for already-running Bela process. diff -r 9dc5a0ccad25 -r a0698d523a6a core/RTAudio.cpp --- 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;