Skip to content

Commit

Permalink
Disable text kit lock (#1910)
Browse files Browse the repository at this point in the history
* Add experiment to disable global textkit lock

* Forgot the bang
  • Loading branch information
garrettmoon committed Sep 17, 2020
1 parent 45c0f19 commit d7f58a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalDispatchApply = 1 << 7, // exp_dispatch_apply
ASExperimentalDrawingGlobal = 1 << 8, // exp_drawing_global
ASExperimentalOptimizeDataControllerPipeline = 1 << 9, // exp_optimize_data_controller_pipeline
ASExperimentalDisableGlobalTextkitLock = 1 << 10, // exp_disable_global_textkit_lock
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
@"exp_did_enter_preload_skip_asm_layout",
@"exp_dispatch_apply",
@"exp_drawing_global",
@"exp_optimize_data_controller_pipeline"]));
@"exp_optimize_data_controller_pipeline",
@"exp_disable_global_textkit_lock"]));
if (flags == ASExperimentalFeatureAll) {
return allNames;
}
Expand Down
18 changes: 11 additions & 7 deletions Source/TextKit/ASTextKitContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString
if (self = [super init]) {
static AS::Mutex *mutex = NULL;
static dispatch_once_t onceToken;
// Concurrently initialising TextKit components crashes (rdar://18448377) so we use a global lock.
dispatch_once(&onceToken, ^{
mutex = new AS::Mutex();
});
if (mutex != NULL) {
mutex->lock();

BOOL useGlobalTextKitLock = !ASActivateExperimentalFeature(ASExperimentalDisableGlobalTextkitLock);
if (useGlobalTextKitLock) {
// Concurrently initialising TextKit components crashes (rdar://18448377) so we use a global lock.
dispatch_once(&onceToken, ^{
mutex = new AS::Mutex();
});
if (mutex != NULL) {
mutex->lock();
}
}

__instanceLock__ = std::make_shared<AS::Mutex>();
Expand Down Expand Up @@ -76,7 +80,7 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString
_textContainer.exclusionPaths = exclusionPaths;
[_layoutManager addTextContainer:_textContainer];

if (mutex != NULL) {
if (useGlobalTextKitLock && mutex != NULL) {
mutex->unlock();
}
}
Expand Down

0 comments on commit d7f58a5

Please sign in to comment.