mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user