diff options
author | greatroar <61184462+greatroar@users.noreply.github.com> | 2021-11-27 12:51:46 +0100 |
---|---|---|
committer | Jakob Borg <jakob@kastelo.net> | 2021-11-27 15:35:07 +0100 |
commit | eb857dbc45e1d1080544f63a33a8ad0bc1493040 (patch) | |
tree | 03bb00d6ca526bc3ad3d416a872a652890e6eed8 | |
parent | e7620e951d35f57f67cbbb79e6535cfb24a8ffe1 (diff) |
lib/osutil: Use x/sys/windows for SetLowPriority
-rw-r--r-- | lib/osutil/lowprio_windows.go | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/lib/osutil/lowprio_windows.go b/lib/osutil/lowprio_windows.go index 2402e369ed..902101f867 100644 --- a/lib/osutil/lowprio_windows.go +++ b/lib/osutil/lowprio_windows.go @@ -7,43 +7,19 @@ package osutil import ( - "syscall" - "github.com/pkg/errors" -) - -const ( - // https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-setpriorityclass - aboveNormalPriorityClass = 0x00008000 - belowNormalPriorityClass = 0x00004000 - highPriorityClass = 0x00000080 - idlePriorityClass = 0x00000040 - normalPriorityClass = 0x00000020 - processModeBackgroundBegin = 0x00100000 - processModeBackgroundEnd = 0x00200000 - realtimePriorityClass = 0x00000100 + "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 { - modkernel32 := syscall.NewLazyDLL("kernel32.dll") - setPriorityClass := modkernel32.NewProc("SetPriorityClass") - - if err := setPriorityClass.Find(); err != nil { - return errors.Wrap(err, "find proc") - } - - handle, err := syscall.GetCurrentProcess() + handle, err := windows.GetCurrentProcess() if err != nil { - return errors.Wrap(err, "get process handler") + return errors.Wrap(err, "get process handle") } - defer syscall.CloseHandle(handle) + defer windows.CloseHandle(handle) - res, _, err := setPriorityClass.Call(uintptr(handle), belowNormalPriorityClass) - if res != 0 { - // "If the function succeeds, the return value is nonzero." - return nil - } + err = windows.SetPriorityClass(handle, windows.BELOW_NORMAL_PRIORITY_CLASS) return errors.Wrap(err, "set priority class") // wraps nil as nil } |