comparison core/RTAudio.cpp @ 381:a0698d523a6a prerelease

Added check for already-running Bela process.
author andrewm
date Sun, 12 Jun 2016 23:20:37 +0100
parents 3bed6b09223c
children 5c8f46fcd4d0
comparison
equal deleted inserted replaced
380:9dc5a0ccad25 381:a0698d523a6a
97 // 97 //
98 // Returns 0 on success. 98 // Returns 0 on success.
99 99
100 int Bela_initAudio(BelaInitSettings *settings, void *userData) 100 int Bela_initAudio(BelaInitSettings *settings, void *userData)
101 { 101 {
102 // First check if there's a Bela program already running on the board.
103 // We can't have more than one instance at a time, but we can tell via
104 // the Xenomai task info. We expect the rt_task_bind call to fail so if it
105 // doesn't then it means something else is running.
106 RT_TASK otherBelaTask;
107 int returnVal = rt_task_bind(&otherBelaTask, gRTAudioThreadName, TM_NONBLOCK);
108 if(returnVal == 0) {
109 cout << "Error: Bela is already running in another process. Cannot start.\n";
110 rt_task_unbind(&otherBelaTask);
111 return -1;
112 }
113 else if(returnVal != -EWOULDBLOCK && returnVal != -ETIMEDOUT) {
114 cout << "Error " << returnVal << " occurred determining if another Bela task is running.\n";
115 return -1;
116 }
117
102 // Sanity checks 118 // Sanity checks
103 if(settings->pruNumber < 0 || settings->pruNumber > 1) { 119 if(settings->pruNumber < 0 || settings->pruNumber > 1) {
104 cout << "Invalid PRU number " << settings->pruNumber << endl; 120 cout << "Invalid PRU number " << settings->pruNumber << endl;
105 return -1; 121 return -1;
106 } 122 }