Files
sdk/runtime/tests/vm/dart/thread_priority_windows_test.dart
T
Martin Kustermann cfe45b6e3e [vm] Add opt-in flag to set priority for worker threads created by the VM
The newly added --worker-thread-priority can be used by users as an
opt-in to set the thread priority / nice value.

It is the responsibility of the user to ensure that the process has the
right to change the priority to the given value. Failure to set the
priority will be fatal.

See b/154918152

Change-Id: I3b3791e88b6ddf4fa6e39e4587f7fe1ab4d2312f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150560
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-06-10 19:57:02 +00:00

35 lines
1.1 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--worker-thread-priority=-2
// A priority of -2 means THREAD_PRIORITY_LOWEST on windows
import 'dart:ffi';
import 'dart:io';
import 'package:expect/expect.dart';
final DynamicLibrary kernel32 = DynamicLibrary.open("kernel32.dll");
// HANDLE GetCurrentThread();
typedef GetCurrentThreadFT = int Function();
typedef GetCurrentThreadNFT = IntPtr Function();
// int GetThreadPriority(HANDLE hThread);
typedef GetThreadPriorityFT = int Function(int handle);
typedef GetThreadPriorityNFT = Int32 Function(IntPtr handle);
final getCurrentThread =
kernel32.lookupFunction<GetCurrentThreadNFT, GetCurrentThreadFT>(
'GetCurrentThread');
final getThreadPriority =
kernel32.lookupFunction<GetThreadPriorityNFT, GetThreadPriorityFT>(
'GetThreadPriority');
main(args) {
if (Platform.isWindows) {
Expect.equals(-2, getThreadPriority(getCurrentThread()));
}
}