forked from Codehardt/go-priority
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriority_windows.go
35 lines (31 loc) · 1005 Bytes
/
priority_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// +build windows
package priority
import (
"fmt"
"syscall"
)
// priority classes
var priorityMapping = map[Priority]uintptr{
PriorityVeryLow: 0x00000040, // equals IDLE_PRIORITY_CLASS
PriorityLow: 0x00004000, // equals BELOW_NORMAL_PRIORITY_CLASS
PriorityMedium: 0x00000020, // equals NORMAL_PRIORITY_CLASS
PriorityHigh: 0x00008000, // equals ABOVE_NORMAL_PRIORITY_CLASS
PriorityVeryHigh: 0x00000080, // equals HIGH_PRIORITY_CLASS
}
func setPriority(priority Priority) error {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
setPriorityClass := kernel32.NewProc("SetPriorityClass")
if err := setPriorityClass.Find(); err != nil {
return err
}
handle, err := syscall.GetCurrentProcess()
if err != nil {
return err
}
defer syscall.CloseHandle(handle)
r1, _, errno := setPriorityClass.Call(uintptr(handle), priorityMapping[priority])
if r1 == 0 {
return fmt.Errorf("SetPriorityClass(0x%x, 0x%x): %s", uintptr(handle), priorityMapping[priority], errno)
}
return nil
}