rclone/vendor/github.com/spacemonkeygo/monkit/v3/monotime/monotime_windows.go
2020-05-12 15:56:50 +00:00

28 lines
756 B
Go

package monotime
import (
"syscall"
"time"
"unsafe"
)
var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
queryPerformanceFrequencyProc = modkernel32.NewProc("QueryPerformanceFrequency")
queryPerformanceCounterProc = modkernel32.NewProc("QueryPerformanceCounter")
qpcFrequency = queryPerformanceFrequency()
)
func elapsed() time.Duration {
var elapsed int64
syscall.Syscall(queryPerformanceCounterProc.Addr(), 1, uintptr(unsafe.Pointer(&elapsed)), 0, 0)
return time.Duration(elapsed) * time.Second / (time.Duration(qpcFrequency) * time.Nanosecond)
}
func queryPerformanceFrequency() int64 {
var freq int64
syscall.Syscall(queryPerformanceFrequencyProc.Addr(), 1, uintptr(unsafe.Pointer(&freq)), 0, 0)
return freq
}