Skip to content

Commit

Permalink
Minimise the critical section in PdContext::sendExternalMessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhroth committed Feb 16, 2012
1 parent ed0ccfe commit d8c3206
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/PdContext.cpp
Expand Up @@ -464,13 +464,15 @@ void PdContext::scheduleExternalMessage(const char *receiverName, PdMessage *mes
}

void PdContext::scheduleExternalMessage(const char *receiverName, double timestamp, const char *initString) {
lock();
// do the heavy lifting of string parsing before the lock (minimise the critical section)
int maxElements = (strlen(initString)/2)+1;
PdMessage *message = PD_MESSAGE_ON_STACK(maxElements);
char str[strlen(initString)+1]; strcpy(str, initString);
message->initWithString(timestamp, maxElements, str);

lock(); // lock and load
int receiverNameIndex = sendController->getNameIndex(receiverName);
if (receiverNameIndex >= 0) { // if the receiver exists
int maxElements = (strlen(initString)/2)+1;
PdMessage *message = PD_MESSAGE_ON_STACK(maxElements);
char str[strlen(initString)+1]; strcpy(str, initString);
message->initWithString(timestamp, maxElements, str);
scheduleMessage(sendController, receiverNameIndex, message);
}
unlock();
Expand Down

0 comments on commit d8c3206

Please sign in to comment.