From 6e8b6f874778a3dfadc8fa45b88e0d00c54dd83c Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 15 一月 2020 13:12:23 +0800
Subject: [PATCH] debug
---
run.go | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/run.go b/run.go
index 6fe49b7..30256d6 100644
--- a/run.go
+++ b/run.go
@@ -2,6 +2,7 @@
import (
"context"
+ "os"
"sync"
"time"
"unsafe"
@@ -12,6 +13,8 @@
"basic.com/valib/gogpu.git"
"github.com/gogo/protobuf/proto"
)
+
+const maxTryBeforeReboot = 10
type face struct {
handle *SDKFace
@@ -30,6 +33,40 @@
ipc2Rule string
ruleMsgMaxCacheSize int
reserved map[string]interface{}
+
+ running bool
+ rebootUntil int
+ mtxRunning sync.Mutex
+}
+
+func (f *face) maybeReboot(ctx context.Context) {
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ default:
+ f.mtxRunning.Lock()
+ running := f.running
+ f.mtxRunning.Unlock()
+
+ if running {
+ f.rebootUntil = 0
+
+ f.mtxRunning.Lock()
+ f.running = false
+ f.mtxRunning.Unlock()
+
+ } else {
+ f.rebootUntil++
+ f.fnLogger("Face No Running: ", f.rebootUntil)
+ if f.rebootUntil > maxTryBeforeReboot {
+ f.fnLogger("Face Too Long Running, Reboot")
+ os.Exit(0)
+ }
+ }
+ time.Sleep(time.Second)
+ }
+ }
}
// Create create sdk
@@ -115,6 +152,9 @@
ipc2Rule: ipc2Rule,
ruleMsgMaxCacheSize: ruleMaxSize,
reserved: reserved,
+
+ running: true,
+ rebootUntil: maxTryBeforeReboot,
}
}
@@ -148,6 +188,8 @@
go torule.Run(ctx)
go s.run(ctx, chRcv, chSnd)
+
+ go s.maybeReboot(ctx)
}
//////////////////////////////////////////////////////////////////
@@ -310,6 +352,9 @@
// f.fnLogger("Face~~~EjectResult", dtchn)
common.EjectResult(data, rMsg, out)
// f.fnLogger("Face~~~EjectResult Over", dtchn)
+ f.mtxRunning.Lock()
+ f.running = true
+ f.mtxRunning.Unlock()
var id, name string
if rMsg.Msg.Tasklab != nil {
--
Gitblit v1.8.0