mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
lib/osutil: Disable setting priority on Windows (fixes #4676)
Presumably fixing the crash, leaving us to improve this calmly. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4677
This commit is contained in:
parent
5cfb9783b3
commit
582539a1e6
@ -6,42 +6,8 @@
|
|||||||
|
|
||||||
package osutil
|
package osutil
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
kernel32, _ = syscall.LoadLibrary("kernel32.dll")
|
|
||||||
setPriorityClass, _ = syscall.GetProcAddress(kernel32, "SetPriorityClass")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686219(v=vs.85).aspx
|
|
||||||
aboveNormalPriorityClass = 0x00008000
|
|
||||||
belowNormalPriorityClass = 0x00004000
|
|
||||||
highPriorityClass = 0x00000080
|
|
||||||
idlePriorityClass = 0x00000040
|
|
||||||
normalPriorityClass = 0x00000020
|
|
||||||
processModeBackgroundBegin = 0x00100000
|
|
||||||
processModeBackgroundEnd = 0x00200000
|
|
||||||
realtimePriorityClass = 0x00000100
|
|
||||||
)
|
|
||||||
|
|
||||||
// SetLowPriority lowers the process CPU scheduling priority, and possibly
|
// SetLowPriority lowers the process CPU scheduling priority, and possibly
|
||||||
// I/O priority depending on the platform and OS.
|
// I/O priority depending on the platform and OS.
|
||||||
func SetLowPriority() error {
|
func SetLowPriority() error {
|
||||||
handle, err := syscall.GetCurrentProcess()
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "get process handler")
|
|
||||||
}
|
|
||||||
defer syscall.CloseHandle(handle)
|
|
||||||
|
|
||||||
res, _, err := syscall.Syscall(uintptr(setPriorityClass), uintptr(handle), belowNormalPriorityClass, 0, 0)
|
|
||||||
if res != 0 {
|
|
||||||
// "If the function succeeds, the return value is nonzero."
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.Wrap(err, "set priority class") // wraps nil as nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user