mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Increase IO thread's priority on iOS to avoid stucks (flutter/engine#34568)
This commit is contained in:
parent
af05788509
commit
0136679fb8
@ -699,7 +699,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
host_config.io_config =
|
||||
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::IO, threadLabel.UTF8String),
|
||||
fml::Thread::ThreadPriority::BACKGROUND);
|
||||
fml::Thread::ThreadPriority::NORMAL);
|
||||
|
||||
return (flutter::ThreadHost){host_config};
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
#import <OCMock/OCMock.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
#import "flutter/common/settings.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h"
|
||||
@ -261,4 +263,32 @@ FLUTTER_ASSERT_ARC
|
||||
[self waitForExpectationsWithTimeout:1 handler:nil];
|
||||
}
|
||||
|
||||
- (void)testThreadPrioritySetCorrectly {
|
||||
XCTestExpectation* prioritiesSet = [self expectationWithDescription:@"prioritiesSet"];
|
||||
prioritiesSet.expectedFulfillmentCount = 3;
|
||||
|
||||
IMP mockSetThreadPriority =
|
||||
imp_implementationWithBlock(^(NSThread* thread, double threadPriority) {
|
||||
if ([thread.name hasSuffix:@".ui"]) {
|
||||
XCTAssertEqual(threadPriority, 1.0);
|
||||
[prioritiesSet fulfill];
|
||||
} else if ([thread.name hasSuffix:@".raster"]) {
|
||||
XCTAssertEqual(threadPriority, 1.0);
|
||||
[prioritiesSet fulfill];
|
||||
} else if ([thread.name hasSuffix:@".io"]) {
|
||||
XCTAssertEqual(threadPriority, 0.5);
|
||||
[prioritiesSet fulfill];
|
||||
}
|
||||
});
|
||||
Method method = class_getInstanceMethod([NSThread class], @selector(setThreadPriority:));
|
||||
IMP originalSetThreadPriority = method_getImplementation(method);
|
||||
method_setImplementation(method, mockSetThreadPriority);
|
||||
|
||||
FlutterEngine* engine = [[FlutterEngine alloc] init];
|
||||
[engine run];
|
||||
[self waitForExpectationsWithTimeout:1 handler:nil];
|
||||
|
||||
method_setImplementation(method, originalSetThreadPriority);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user