mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
Make ASBatchContext lock-free (#854)
This commit is contained in:
parent
27fac9f586
commit
063194cb1d
@ -264,7 +264,7 @@
|
|||||||
B35062131B010EFD0018CF92 /* ASBasicImageDownloader.h in Headers */ = {isa = PBXBuildFile; fileRef = 054963471A1EA066000F8E56 /* ASBasicImageDownloader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
B35062131B010EFD0018CF92 /* ASBasicImageDownloader.h in Headers */ = {isa = PBXBuildFile; fileRef = 054963471A1EA066000F8E56 /* ASBasicImageDownloader.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
B35062141B010EFD0018CF92 /* ASBasicImageDownloader.mm in Sources */ = {isa = PBXBuildFile; fileRef = 054963481A1EA066000F8E56 /* ASBasicImageDownloader.mm */; };
|
B35062141B010EFD0018CF92 /* ASBasicImageDownloader.mm in Sources */ = {isa = PBXBuildFile; fileRef = 054963481A1EA066000F8E56 /* ASBasicImageDownloader.mm */; };
|
||||||
B35062151B010EFD0018CF92 /* ASBatchContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 299DA1A71A828D2900162D41 /* ASBatchContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
B35062151B010EFD0018CF92 /* ASBatchContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 299DA1A71A828D2900162D41 /* ASBatchContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
B35062161B010EFD0018CF92 /* ASBatchContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 299DA1A81A828D2900162D41 /* ASBatchContext.mm */; };
|
B35062161B010EFD0018CF92 /* ASBatchContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 299DA1A81A828D2900162D41 /* ASBatchContext.m */; };
|
||||||
B35062171B010EFD0018CF92 /* ASDataController.h in Headers */ = {isa = PBXBuildFile; fileRef = 464052191A3F83C40061C0BA /* ASDataController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
B35062171B010EFD0018CF92 /* ASDataController.h in Headers */ = {isa = PBXBuildFile; fileRef = 464052191A3F83C40061C0BA /* ASDataController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
B35062181B010EFD0018CF92 /* ASDataController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4640521A1A3F83C40061C0BA /* ASDataController.mm */; };
|
B35062181B010EFD0018CF92 /* ASDataController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4640521A1A3F83C40061C0BA /* ASDataController.mm */; };
|
||||||
B350621B1B010EFD0018CF92 /* ASTableLayoutController.h in Headers */ = {isa = PBXBuildFile; fileRef = 4640521B1A3F83C40061C0BA /* ASTableLayoutController.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
B350621B1B010EFD0018CF92 /* ASTableLayoutController.h in Headers */ = {isa = PBXBuildFile; fileRef = 4640521B1A3F83C40061C0BA /* ASTableLayoutController.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||||
@ -643,7 +643,7 @@
|
|||||||
296A0A311A951715005ACEAA /* ASScrollDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASScrollDirection.h; path = Source/Details/ASScrollDirection.h; sourceTree = SOURCE_ROOT; };
|
296A0A311A951715005ACEAA /* ASScrollDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASScrollDirection.h; path = Source/Details/ASScrollDirection.h; sourceTree = SOURCE_ROOT; };
|
||||||
296A0A341A951ABF005ACEAA /* ASBatchFetchingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASBatchFetchingTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
296A0A341A951ABF005ACEAA /* ASBatchFetchingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASBatchFetchingTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||||
299DA1A71A828D2900162D41 /* ASBatchContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASBatchContext.h; sourceTree = "<group>"; };
|
299DA1A71A828D2900162D41 /* ASBatchContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASBatchContext.h; sourceTree = "<group>"; };
|
||||||
299DA1A81A828D2900162D41 /* ASBatchContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASBatchContext.mm; sourceTree = "<group>"; };
|
299DA1A81A828D2900162D41 /* ASBatchContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASBatchContext.m; sourceTree = "<group>"; };
|
||||||
29CDC2E11AAE70D000833CA4 /* ASBasicImageDownloaderContextTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASBasicImageDownloaderContextTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
29CDC2E11AAE70D000833CA4 /* ASBasicImageDownloaderContextTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASBasicImageDownloaderContextTests.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||||
3917EBD21E9C2FC400D04A01 /* _ASCollectionReusableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _ASCollectionReusableView.h; sourceTree = "<group>"; };
|
3917EBD21E9C2FC400D04A01 /* _ASCollectionReusableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _ASCollectionReusableView.h; sourceTree = "<group>"; };
|
||||||
3917EBD31E9C2FC400D04A01 /* _ASCollectionReusableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _ASCollectionReusableView.m; sourceTree = "<group>"; };
|
3917EBD31E9C2FC400D04A01 /* _ASCollectionReusableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _ASCollectionReusableView.m; sourceTree = "<group>"; };
|
||||||
@ -1333,7 +1333,7 @@
|
|||||||
054963471A1EA066000F8E56 /* ASBasicImageDownloader.h */,
|
054963471A1EA066000F8E56 /* ASBasicImageDownloader.h */,
|
||||||
054963481A1EA066000F8E56 /* ASBasicImageDownloader.mm */,
|
054963481A1EA066000F8E56 /* ASBasicImageDownloader.mm */,
|
||||||
299DA1A71A828D2900162D41 /* ASBatchContext.h */,
|
299DA1A71A828D2900162D41 /* ASBatchContext.h */,
|
||||||
299DA1A81A828D2900162D41 /* ASBatchContext.mm */,
|
299DA1A81A828D2900162D41 /* ASBatchContext.m */,
|
||||||
E5C347B01ECB3D9200EC4BE4 /* ASBatchFetchingDelegate.h */,
|
E5C347B01ECB3D9200EC4BE4 /* ASBatchFetchingDelegate.h */,
|
||||||
205F0E1B1B373A2C007741D0 /* ASCollectionViewLayoutController.h */,
|
205F0E1B1B373A2C007741D0 /* ASCollectionViewLayoutController.h */,
|
||||||
205F0E1C1B373A2C007741D0 /* ASCollectionViewLayoutController.m */,
|
205F0E1C1B373A2C007741D0 /* ASCollectionViewLayoutController.m */,
|
||||||
@ -2339,7 +2339,7 @@
|
|||||||
34EFC7621B701CA400AD841F /* ASBackgroundLayoutSpec.mm in Sources */,
|
34EFC7621B701CA400AD841F /* ASBackgroundLayoutSpec.mm in Sources */,
|
||||||
DE8BEAC41C2DF3FC00D57C12 /* ASDelegateProxy.m in Sources */,
|
DE8BEAC41C2DF3FC00D57C12 /* ASDelegateProxy.m in Sources */,
|
||||||
B35062141B010EFD0018CF92 /* ASBasicImageDownloader.mm in Sources */,
|
B35062141B010EFD0018CF92 /* ASBasicImageDownloader.mm in Sources */,
|
||||||
B35062161B010EFD0018CF92 /* ASBatchContext.mm in Sources */,
|
B35062161B010EFD0018CF92 /* ASBatchContext.m in Sources */,
|
||||||
AC47D9421B3B891B00AAEE9D /* ASCellNode.mm in Sources */,
|
AC47D9421B3B891B00AAEE9D /* ASCellNode.mm in Sources */,
|
||||||
E58E9E451E941D74004CFC59 /* ASCollectionLayoutContext.m in Sources */,
|
E58E9E451E941D74004CFC59 /* ASCollectionLayoutContext.m in Sources */,
|
||||||
34EFC7641B701CC600AD841F /* ASCenterLayoutSpec.mm in Sources */,
|
34EFC7641B701CC600AD841F /* ASCenterLayoutSpec.mm in Sources */,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// ASBatchContext.mm
|
// ASBatchContext.m
|
||||||
// Texture
|
// Texture
|
||||||
//
|
//
|
||||||
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||||
@ -18,7 +18,7 @@
|
|||||||
#import <AsyncDisplayKit/ASBatchContext.h>
|
#import <AsyncDisplayKit/ASBatchContext.h>
|
||||||
|
|
||||||
#import <AsyncDisplayKit/ASLog.h>
|
#import <AsyncDisplayKit/ASLog.h>
|
||||||
#import <AsyncDisplayKit/ASThread.h>
|
#import <stdatomic.h>
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, ASBatchContextState) {
|
typedef NS_ENUM(NSInteger, ASBatchContextState) {
|
||||||
ASBatchContextStateFetching,
|
ASBatchContextStateFetching,
|
||||||
@ -26,54 +26,44 @@ typedef NS_ENUM(NSInteger, ASBatchContextState) {
|
|||||||
ASBatchContextStateCompleted
|
ASBatchContextStateCompleted
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface ASBatchContext ()
|
@implementation ASBatchContext {
|
||||||
{
|
atomic_int _state;
|
||||||
ASBatchContextState _state;
|
|
||||||
ASDN::RecursiveMutex __instanceLock__;
|
|
||||||
}
|
}
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation ASBatchContext
|
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_state = ASBatchContextStateCompleted;
|
_state = ATOMIC_VAR_INIT(ASBatchContextStateCompleted);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isFetching
|
- (BOOL)isFetching
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
return atomic_load(&_state) == ASBatchContextStateFetching;
|
||||||
return _state == ASBatchContextStateFetching;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)batchFetchingWasCancelled
|
- (BOOL)batchFetchingWasCancelled
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
return atomic_load(&_state) == ASBatchContextStateCancelled;
|
||||||
return _state == ASBatchContextStateCancelled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)beginBatchFetching
|
- (void)beginBatchFetching
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
atomic_store(&_state, ASBatchContextStateFetching);
|
||||||
_state = ASBatchContextStateFetching;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)completeBatchFetching:(BOOL)didComplete
|
- (void)completeBatchFetching:(BOOL)didComplete
|
||||||
{
|
{
|
||||||
if (didComplete) {
|
if (didComplete) {
|
||||||
as_log_debug(ASCollectionLog(), "Completed batch fetch with context %@", self);
|
as_log_debug(ASCollectionLog(), "Completed batch fetch with context %@", self);
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
atomic_store(&_state, ASBatchContextStateCompleted);
|
||||||
_state = ASBatchContextStateCompleted;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)cancelBatchFetching
|
- (void)cancelBatchFetching
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
atomic_store(&_state, ASBatchContextStateCancelled);
|
||||||
_state = ASBatchContextStateCancelled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
Loading…
x
Reference in New Issue
Block a user