瀏覽代碼

lib/osutil: Skip setLowPriority in Windows if already lower (fixes #6597) (#8993)

tomasz1986 2 年之前
父節點
當前提交
d70eb569f2
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      lib/osutil/lowprio_windows.go

+ 5 - 0
lib/osutil/lowprio_windows.go

@@ -21,6 +21,11 @@ func SetLowPriority() error {
 	}
 	defer windows.CloseHandle(handle)
 
+	if cur, err := windows.GetPriorityClass(handle); err == nil && (cur == windows.IDLE_PRIORITY_CLASS || cur == windows.BELOW_NORMAL_PRIORITY_CLASS) {
+		// We're done here.
+		return nil
+	}
+
 	if err := windows.SetPriorityClass(handle, windows.BELOW_NORMAL_PRIORITY_CLASS); err != nil {
 		return fmt.Errorf("set priority class: %w", err)
 	}