-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupervisor.go
66 lines (53 loc) · 1.1 KB
/
supervisor.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package muSupervisor
import (
"fmt"
"time"
)
var opReq chan *opData
var opObtained chan *opData
var unlockChan chan *opData
var unlockedChan chan struct{}
func init() {
opReq = make(chan *opData)
opObtained = make(chan *opData)
unlockChan = make(chan *opData)
unlockedChan = make(chan struct{})
go supervisor()
}
func supervisor() {
if Opts.Disable == true {
fmt.Println("supervisor disabled.")
return
}
fmt.Println("supervisor enabled.")
newMutexMap := make(mutexOpMap)
t := time.NewTicker(Opts.CheckFrequency)
for {
select {
case opD := <-opReq:
opD.reqTime = time.Now()
newMutexMap.mapRequest(opD)
case opD := <-opObtained:
newMutexMap.mapObtained(opD)
case opD := <-unlockChan:
newMutexMap.mapUnlock(opD)
unlockedChan <- struct{}{}
case <-t.C:
newMutexMap.doCheck()
}
}
}
func logOpDetails(op *opData) {
now := time.Now()
fmt.Printf("Routine: %v, state: %v, type: %v, time: %v, request: %p, mutex: %p\n",
op.numRoutine,
op.state,
op.t,
now.Sub(op.reqTime),
op,
op.mutexPtr,
)
if op.stackTrace != nil {
fmt.Printf("%s\n\n", *op.stackTrace)
}
}