Skip to content

Commit

Permalink
dispatch_retain & dispatch_release no longer needed with latest ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Jun 17, 2012
1 parent a82260a commit f7129a7
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 21 deletions.
46 changes: 35 additions & 11 deletions Core/HTTPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

// Does ARC support support GCD objects?
// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+

#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
// Other flags: trace
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN; // | HTTP_LOG_FLAG_TRACE;
Expand Down Expand Up @@ -182,7 +207,9 @@ - (id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig
if (aConfig.queue)
{
connectionQueue = aConfig.queue;
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_retain(connectionQueue);
#endif
}
else
{
Expand Down Expand Up @@ -218,21 +245,17 @@ - (void)dealloc
{
HTTPLogTrace();

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(connectionQueue);
#endif

[asyncSocket setDelegate:nil delegateQueue:NULL];
[asyncSocket disconnect];




if ([httpResponse respondsToSelector:@selector(connectionDidClose)])
{
[httpResponse connectionDidClose];
}



}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2686,19 +2709,20 @@ - (id)initWithServer:(HTTPServer *)aServer documentRoot:(NSString *)aDocumentRoo

if (q)
{
dispatch_retain(q);
queue = q;
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_retain(queue);
#endif
}
}
return self;
}

- (void)dealloc
{

if (queue)
dispatch_release(queue);

#if NEEDS_DISPATCH_RETAIN_RELEASE
if (queue) dispatch_release(queue);
#endif
}

@end
31 changes: 27 additions & 4 deletions Core/HTTPServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

// Does ARC support support GCD objects?
// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+

#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
// Other flags: trace
static const int httpLogLevel = HTTP_LOG_LEVEL_INFO; // | HTTP_LOG_FLAG_TRACE;
Expand Down Expand Up @@ -104,14 +129,12 @@ - (void)dealloc

// Release all instance variables

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(serverQueue);
dispatch_release(connectionQueue);
#endif

[asyncSocket setDelegate:nil delegateQueue:NULL];




}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
37 changes: 33 additions & 4 deletions Core/Responses/HTTPAsyncFileResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

/**
* Does ARC support support GCD objects?
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
**/
#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels : off, error, warn, info, verbose
// Other flags: trace
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN; // | HTTP_LOG_FLAG_TRACE;
Expand Down Expand Up @@ -232,7 +258,9 @@ - (BOOL)openFileAndSetupReadSource
});

int theFileFD = fileFD;
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_source_t theReadSource = readSource;
#endif

dispatch_source_set_cancel_handler(readSource, ^{

Expand All @@ -242,7 +270,9 @@ - (BOOL)openFileAndSetupReadSource

HTTPLogTrace2(@"%@: cancelBlock - Close fd[%i]", THIS_FILE, theFileFD);

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(theReadSource);
#endif
close(theFileFD);
});

Expand Down Expand Up @@ -390,13 +420,12 @@ - (void)dealloc
{
HTTPLogTrace();

if (readQueue)
dispatch_release(readQueue);
#if NEEDS_DISPATCH_RETAIN_RELEASE
if (readQueue) dispatch_release(readQueue);
#endif

if (readBuffer)
free(readBuffer);


}

@end
29 changes: 27 additions & 2 deletions Core/WebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

// Does ARC support support GCD objects?
// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+

#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
// Other flags : trace
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN; // | HTTP_LOG_FLAG_TRACE;
Expand Down Expand Up @@ -193,12 +218,12 @@ - (void)dealloc
{
HTTPLogTrace();

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(websocketQueue);

#endif

[asyncSocket setDelegate:nil delegateQueue:NULL];
[asyncSocket disconnect];

}

- (id)delegate
Expand Down

0 comments on commit f7129a7

Please sign in to comment.