mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
b10d106a55
This replaces old style errors.Wrap with modern fmt.Errorf and removes the (direct) dependency on github.com/pkg/errors. A couple of cases are adjusted by hand as previously errors.Wrap(nil, ...) would return nil, which is not what fmt.Errorf does.
29 lines
785 B
Go
29 lines
785 B
Go
// 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
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// SetLowPriority lowers the process CPU scheduling priority, and possibly
|
|
// I/O priority depending on the platform and OS.
|
|
func SetLowPriority() error {
|
|
handle, err := windows.GetCurrentProcess()
|
|
if err != nil {
|
|
return fmt.Errorf("get process handle: %w", err)
|
|
}
|
|
defer windows.CloseHandle(handle)
|
|
|
|
if err := windows.SetPriorityClass(handle, windows.BELOW_NORMAL_PRIORITY_CLASS); err != nil {
|
|
return fmt.Errorf("set priority class: %w", err)
|
|
}
|
|
return nil
|
|
}
|