Files
sdk/runtime/tests/vm/dart/thread_priority_linux_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

28 lines
837 B
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=12
import 'dart:ffi';
import 'dart:io';
import 'package:expect/expect.dart';
// Value of "PRIO_PROCESS".
const int kPrioProcess = 0;
const int kCurrentThreadId = 0;
// int getpriority(int which, id_t who)
typedef GetPriorityFT = int Function(int which, int who);
typedef GetPriorityNFT = Int32 Function(Int32 which, Uint32 who);
final getPriority = DynamicLibrary.process()
.lookupFunction<GetPriorityNFT, GetPriorityFT>('getpriority');
main(args) {
if (Platform.isLinux || Platform.isAndroid) {
Expect.equals(12, getPriority(kPrioProcess, kCurrentThreadId));
}
}