Skip to content

Commit

Permalink
Fixing "dispatch_get_current_queue() deprecated" warning. Fixes issue C…
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Oct 29, 2012
1 parent 290fef9 commit 585d7cf
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 204 deletions.
170 changes: 85 additions & 85 deletions Lumberjack/DDFileLogger.m
Expand Up @@ -522,118 +522,119 @@ - (void)dealloc

- (unsigned long long)maximumFileSize
{
__block unsigned long long result;

dispatch_block_t block = ^{
result = maximumFileSize;
};

// The design of this method is taken from the DDAbstractLogger implementation.
// For extensive documentation please refer to the DDAbstractLogger implementation.

// Note: The internal implementation should access the maximumFileSize variable directly,
// but if we forget to do this, then this method should at least work properly.
// Note: The internal implementation MUST access the maximumFileSize variable directly,
// This method is designed explicitly for external access.
//
// Using "self." syntax to go through this method will cause immediate deadlock.
// This is the intended result. Fix it by accessing the ivar directly.
// Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.

dispatch_queue_t currentQueue = dispatch_get_current_queue();
if (currentQueue == loggerQueue)
{
return maximumFileSize;
}
else
{
dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
NSAssert(currentQueue != globalLoggingQueue, @"Core architecture requirement failure");

__block unsigned long long result;

dispatch_sync(globalLoggingQueue, ^{
dispatch_sync(loggerQueue, ^{
result = maximumFileSize;
});
});

return result;
}
NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");

dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];

dispatch_sync(globalLoggingQueue, ^{
dispatch_sync(loggerQueue, block);
});

return result;
}

- (void)setMaximumFileSize:(unsigned long long)newMaximumFileSize
{
// The design of this method is taken from the DDAbstractLogger implementation.
// For documentation please refer to the DDAbstractLogger implementation.

dispatch_block_t block = ^{ @autoreleasepool {

maximumFileSize = newMaximumFileSize;
[self maybeRollLogFileDueToSize];

}};

dispatch_queue_t currentQueue = dispatch_get_current_queue();
if (currentQueue == loggerQueue)
{
block();
}
else
{
dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
NSAssert(currentQueue != globalLoggingQueue, @"Core architecture requirement failure");

dispatch_async(globalLoggingQueue, ^{
dispatch_async(loggerQueue, block);
});
}
// The design of this method is taken from the DDAbstractLogger implementation.
// For extensive documentation please refer to the DDAbstractLogger implementation.

// Note: The internal implementation MUST access the maximumFileSize variable directly,
// This method is designed explicitly for external access.
//
// Using "self." syntax to go through this method will cause immediate deadlock.
// This is the intended result. Fix it by accessing the ivar directly.
// Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.

NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");

dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];

dispatch_async(globalLoggingQueue, ^{
dispatch_async(loggerQueue, block);
});
}

- (NSTimeInterval)rollingFrequency
{
__block NSTimeInterval result;

dispatch_block_t block = ^{
result = rollingFrequency;
};

// The design of this method is taken from the DDAbstractLogger implementation.
// For documentation please refer to the DDAbstractLogger implementation.
// For extensive documentation please refer to the DDAbstractLogger implementation.

// Note: The internal implementation should access the rollingFrequency variable directly,
// but if we forget to do this, then this method should at least work properly.
// This method is designed explicitly for external access.
//
// Using "self." syntax to go through this method will cause immediate deadlock.
// This is the intended result. Fix it by accessing the ivar directly.
// Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.

dispatch_queue_t currentQueue = dispatch_get_current_queue();
if (currentQueue == loggerQueue)
{
return rollingFrequency;
}
else
{
dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
NSAssert(currentQueue != globalLoggingQueue, @"Core architecture requirement failure");

__block NSTimeInterval result;

dispatch_sync(globalLoggingQueue, ^{
dispatch_sync(loggerQueue, ^{
result = rollingFrequency;
});
});

return result;
}
NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");

dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];

dispatch_sync(globalLoggingQueue, ^{
dispatch_sync(loggerQueue, block);
});

return result;
}

- (void)setRollingFrequency:(NSTimeInterval)newRollingFrequency
{
// The design of this method is taken from the DDAbstractLogger implementation.
// For documentation please refer to the DDAbstractLogger implementation.

dispatch_block_t block = ^{ @autoreleasepool {

rollingFrequency = newRollingFrequency;
[self maybeRollLogFileDueToAge];

}};

dispatch_queue_t currentQueue = dispatch_get_current_queue();
if (currentQueue == loggerQueue)
{
block();
}
else
{
dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
NSAssert(currentQueue != globalLoggingQueue, @"Core architecture requirement failure");

dispatch_async(globalLoggingQueue, ^{
dispatch_async(loggerQueue, block);
});
}
// The design of this method is taken from the DDAbstractLogger implementation.
// For extensive documentation please refer to the DDAbstractLogger implementation.

// Note: The internal implementation should access the rollingFrequency variable directly,
// This method is designed explicitly for external access.
//
// Using "self." syntax to go through this method will cause immediate deadlock.
// This is the intended result. Fix it by accessing the ivar directly.
// Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.

NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");

dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];

dispatch_async(globalLoggingQueue, ^{
dispatch_async(loggerQueue, block);
});
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -691,24 +692,23 @@ - (void)rollLogFile
{
// This method is public.
// We need to execute the rolling on our logging thread/queue.
//
// The design of this method is taken from the DDAbstractLogger implementation.
// For documentation please refer to the DDAbstractLogger implementation.

dispatch_block_t block = ^{ @autoreleasepool {

[self rollLogFileNow];
}};

dispatch_queue_t currentQueue = dispatch_get_current_queue();
if (currentQueue == loggerQueue)
// The design of this method is taken from the DDAbstractLogger implementation.
// For extensive documentation please refer to the DDAbstractLogger implementation.

if ([self isOnInternalLoggerQueue])
{
block();
}
else
{
dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
NSAssert(currentQueue != globalLoggingQueue, @"Core architecture requirement failure");
NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");

dispatch_async(globalLoggingQueue, ^{
dispatch_async(loggerQueue, block);
Expand Down
4 changes: 4 additions & 0 deletions Lumberjack/DDLog.h
Expand Up @@ -594,4 +594,8 @@ typedef int DDLogMessageOptions;
- (id <DDLogFormatter>)logFormatter;
- (void)setLogFormatter:(id <DDLogFormatter>)formatter;

// For thread-safety assertions
- (BOOL)isOnGlobalLoggingQueue;
- (BOOL)isOnInternalLoggerQueue;

@end

0 comments on commit 585d7cf

Please sign in to comment.