2018-01-15 17:11:14 +00:00
|
|
|
// Copyright (C) 2018 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package osutil
|
|
|
|
|
2018-01-18 17:03:24 +00:00
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
2021-11-27 11:51:46 +00:00
|
|
|
"golang.org/x/sys/windows"
|
2018-01-18 17:03:24 +00:00
|
|
|
)
|
|
|
|
|
2018-01-15 17:11:14 +00:00
|
|
|
// SetLowPriority lowers the process CPU scheduling priority, and possibly
|
|
|
|
// I/O priority depending on the platform and OS.
|
|
|
|
func SetLowPriority() error {
|
2021-11-27 11:51:46 +00:00
|
|
|
handle, err := windows.GetCurrentProcess()
|
2018-01-18 17:03:24 +00:00
|
|
|
if err != nil {
|
2021-11-27 11:51:46 +00:00
|
|
|
return errors.Wrap(err, "get process handle")
|
2018-01-18 17:03:24 +00:00
|
|
|
}
|
2021-11-27 11:51:46 +00:00
|
|
|
defer windows.CloseHandle(handle)
|
2018-01-18 17:03:24 +00:00
|
|
|
|
2021-11-27 11:51:46 +00:00
|
|
|
err = windows.SetPriorityClass(handle, windows.BELOW_NORMAL_PRIORITY_CLASS)
|
2018-01-18 17:03:24 +00:00
|
|
|
return errors.Wrap(err, "set priority class") // wraps nil as nil
|
2018-01-15 17:11:14 +00:00
|
|
|
}
|