-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interrupt.go
52 lines (41 loc) · 970 Bytes
/
interrupt.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2018 The ctxfs Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ctxfs
import (
"context"
"runtime"
"syscall"
"unsafe"
)
const intrSig = syscall.SIGUSR1
func funcPC(f interface{}) uintptr {
const ptrSize = unsafe.Sizeof(uintptr(0))
pc := uintptr(unsafe.Pointer(&f)) + ptrSize
return **(**uintptr)(unsafe.Pointer(pc))
}
func sigtramp()
var intrHandler = func(sig int32) {}
func init() {
setsighandler()
}
// interrupt starts a background task to send the current goroutine a SIGUSR1
// when ctx is done.
func interrupt(ctx context.Context) (cleanup func()) {
runtime.LockOSThread()
done := make(chan struct{}, 1)
tid := threadID()
//unblocksig()
go func() {
select {
case <-ctx.Done():
threadKill(tid)
case <-done:
}
}()
return func() {
//blocksig()
runtime.UnlockOSThread()
done <- struct{}{} // don't leak goroutine
}
}