[Minor Breaking API] Make deallocation queues more reliable (#651)

* Make our async deallocation functions take a double pointer, so we can be sure we've released before the queue drains

* Make it a class property

* Fix the return type

* Use a locker

* Improve release notes
This commit is contained in:
Adlai Holler
2017-11-02 10:45:34 -07:00
committed by GitHub
parent 64b6242b9c
commit ff608c92bf
13 changed files with 45 additions and 25 deletions

View File

@@ -45,7 +45,7 @@ static void runLoopSourceCallback(void *info) {
ASDN::RecursiveMutex _queueLock;
}
+ (instancetype)sharedDeallocationQueue
+ (ASDeallocQueue *)sharedDeallocationQueue
{
static ASDeallocQueue *deallocQueue = nil;
static dispatch_once_t onceToken;
@@ -55,16 +55,18 @@ static void runLoopSourceCallback(void *info) {
return deallocQueue;
}
- (void)releaseObjectInBackground:(id)object
- (void)releaseObjectInBackground:(id _Nullable __strong *)objectPtr
{
// Disable background deallocation on iOS 8 and below to avoid crashes related to UIAXDelegateClearer (#2767).
if (!AS_AT_LEAST_IOS9) {
return;
}
_queueLock.lock();
_queue.push_back(object);
_queueLock.unlock();
if (objectPtr != NULL && *objectPtr != nil) {
ASDN::MutexLocker l(_queueLock);
_queue.push_back(*objectPtr);
*objectPtr = nil;
}
}
- (void)threadMain
@@ -454,4 +456,16 @@ typedef enum {
return _internalQueue.count == 0;
}
#pragma mark - NSLocking
- (void)lock
{
_internalQueueLock.lock();
}
- (void)unlock
{
_internalQueueLock.unlock();
}
@end