Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Woo, GCD! Removing locks from the receiver patch

  • Loading branch information...
commit 55c6264573fd7f532a691c7123a498a6c83f63d8 1 parent 5d750a6
Jonathan del Strother authored
Showing with 4 additions and 10 deletions.
  1. +4 −1 BBOSCInPort.m
  2. +0 −1  BBOSCPluginReceiver.h
  3. +0 −8 BBOSCPluginReceiver.m
View
5 BBOSCInPort.m
@@ -42,6 +42,9 @@ -(void)remove {
}
- (void) receivedOSCMessage:(OSCMessage *)m {
- [delegates makeObjectsPerformSelector:@selector(receivedOSCMessage:) withObject:m];
+ // Bounce off to the main thread so plugins don't have to worry about locking
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [delegates makeObjectsPerformSelector:@selector(receivedOSCMessage:) withObject:m];
+ });
}
@end
View
1  BBOSCPluginReceiver.h
@@ -11,7 +11,6 @@
@class BBOSCInPort;
@interface BBOSCPluginReceiver : QCPlugIn {
NSMutableArray* messages;
- NSLock* messageLock;
}
@property (nonatomic, readonly, retain) NSString* listeningPath;
View
8 BBOSCPluginReceiver.m
@@ -84,7 +84,6 @@ - (id) init
if(self = [super init]) {
self.oscParameters = [NSArray array];
messages = [[NSMutableArray alloc] init];
- messageLock = [[NSLock alloc] init];
listeningPath = @"";
}
@@ -104,7 +103,6 @@ - (void) dealloc
{
[oscPort release];
[messages release];
- [messageLock release];
[listeningPath release];
[oscParameters release];
[super dealloc];
@@ -145,11 +143,9 @@ -(void)setOscParameters:(NSArray*)params {
- (void) receivedOSCMessage:(OSCMessage *)m {
- [messageLock lock];
if ([[m address] hasPrefix:self.listeningPath]) {
[messages addObject:m];
}
- [messageLock unlock];
}
@end
@@ -183,10 +179,8 @@ Return NO in case of failure during the execution (this will prevent rendering o
*/
if ([self didValueForInputKeyChange:@"inputReceivingPath"]) {
- [messageLock lock];
self.listeningPath = self.inputReceivingPath;
[messages removeAllObjects];
- [messageLock unlock];
}
if ([self didValueForInputKeyChange:@"inputReceivingPort"]) {
@@ -198,7 +192,6 @@ Return NO in case of failure during the execution (this will prevent rendering o
NSLog(@"Failed to created input port");
}
- [messageLock lock];
if ([messages count]==0) {
self.outputMessageReceived = NO;
} else {
@@ -228,7 +221,6 @@ Return NO in case of failure during the execution (this will prevent rendering o
else
[messages removeObjectAtIndex:0];
}
- [messageLock unlock];
return YES;
}
Please sign in to comment.
Something went wrong with that request. Please try again.