From 79ed991be3a0c20cdd27cb7e0f062db8087cef12 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 19 Jun 2013 22:11:29 -0400 Subject: [PATCH] Convert MessageQueue to use a ThreadSafeDelegate. --- Source/MessageQueue.h | 4 +++- Source/MessageQueue.m | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/MessageQueue.h b/Source/MessageQueue.h index a7878b0..2e4f968 100644 --- a/Source/MessageQueue.h +++ b/Source/MessageQueue.h @@ -16,6 +16,8 @@ #import +#import "ThreadSafeDeleage.h" + @protocol MessageQueueDelegate; // MessageQueue operates a listening socket, that is connected to another @@ -38,7 +40,7 @@ NSMutableArray* _queue; // The delegate for this class. - id _delegate; + ThreadSafeDeleage* _delegate; // The socket that listens for new incoming connections. CFSocketRef _socket; diff --git a/Source/MessageQueue.m b/Source/MessageQueue.m index 731fca6..c7c4ff0 100644 --- a/Source/MessageQueue.m +++ b/Source/MessageQueue.m @@ -88,13 +88,18 @@ static void MessageQueueWriteEvent(CFWriteStreamRef stream, if ((self = [super init])) { _port = port; _queue = [[NSMutableArray alloc] init]; - _delegate = delegate; + _delegate = (ThreadSafeDeleage*) + [[ThreadSafeDeleage alloc] initWithObject:delegate + protocol:@protocol(MessageQueueDelegate) + thread:[NSThread currentThread] + modes:@[ NSDefaultRunLoopMode ]]; } return self; } - (void)dealloc { [_queue release]; + [_delegate release]; [super dealloc]; } @@ -225,7 +230,7 @@ static void MessageQueueWriteEvent(CFWriteStreamRef stream, if (![_queue count]) return; - if (![_delegate shouldSendMessage]) + if (![(id)_delegate.object shouldSendMessage]) return; if (!CFWriteStreamCanAcceptBytes(_writeStream)) -- 2.43.5