load DLL only once

This commit is contained in:
Drew Weymouth
2024-07-19 07:29:57 -07:00
parent bc89cc20fc
commit 80e53c2971
+16 -2
View File
@@ -2,16 +2,30 @@
package backend package backend
import "syscall" import (
"sync/atomic"
"syscall"
)
const ( const (
ES_CONTINUOUS uint = 0x80000000 ES_CONTINUOUS uint = 0x80000000
ES_SYSTEM_REQUIRED uint = 0x00000001 ES_SYSTEM_REQUIRED uint = 0x00000001
) )
var (
sleepDisabled atomic.Bool
executionState *syscall.LazyProc
)
func SetSystemSleepDisabled(disable bool) { func SetSystemSleepDisabled(disable bool) {
if old := sleepDisabled.Swap(disable); old == disable {
return
}
if executionState == nil {
kernel32 := syscall.NewLazyDLL("kernel32.dll") kernel32 := syscall.NewLazyDLL("kernel32.dll")
executionState := kernel32.NewProc("SetThreadExecutionState") executionState = kernel32.NewProc("SetThreadExecutionState")
}
uType := ES_CONTINUOUS uType := ES_CONTINUOUS
if disable { if disable {