-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnativethread.go
More file actions
49 lines (42 loc) · 805 Bytes
/
nativethread.go
File metadata and controls
49 lines (42 loc) · 805 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package handle
import (
"golang.org/x/sys/windows"
)
var (
kernel32 = windows.NewLazyDLL("kernel32.dll")
createThread = kernel32.NewProc("CreateThread")
terminateThread = kernel32.NewProc("TerminateThread")
)
type nativeThread struct {
handle windows.Handle
}
func createNativeThread(callback uintptr, param uintptr) (nativeThread, error) {
var thread nativeThread
h, _, err := createThread.Call(
0,
0,
callback,
param,
0,
0,
)
if h == 0 {
return nativeThread{}, err
}
thread.handle = windows.Handle(h)
return thread, nil
}
func (t nativeThread) Terminate() error {
r1, _, err := terminateThread.Call(
uintptr(t.handle),
0,
)
windows.CloseHandle(t.handle)
if r1 == 0 {
return err
}
return nil
}
func (t nativeThread) IsZero() bool {
return t.handle == 0
}