From 38672e1ea56024fbe812e4a2aae5fbe267c9770f Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期一, 13 一月 2020 14:05:01 +0800 Subject: [PATCH] vehicle remove model and key --- run.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) diff --git a/run.go b/run.go index ceb4a62..bda030f 100644 --- a/run.go +++ b/run.go @@ -2,6 +2,7 @@ import ( "context" + "os" "sync" "time" @@ -11,6 +12,8 @@ "basic.com/pubsub/protomsg.git" "basic.com/valib/gogpu.git" ) + +const maxTryBeforeReboot = 30 type face struct { handle *SDKFace @@ -29,6 +32,38 @@ 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++ + if f.rebootUntil > maxTryBeforeReboot { + os.Exit(0) + } + } + time.Sleep(time.Second) + } + } } // Create create sdk @@ -114,6 +149,9 @@ ipc2Rule: ipc2Rule, ruleMsgMaxCacheSize: ruleMaxSize, reserved: reserved, + + running: true, + rebootUntil: maxTryBeforeReboot, } } @@ -141,6 +179,8 @@ go torule.Run(ctx) go s.run(ctx, chRcv, chSnd) + + go s.maybeReboot(ctx) } ////////////////////////////////////////////////////////////////// @@ -259,6 +299,10 @@ count, data, _ := f.handle.Run(i.Data, imgW, imgH, 3, dtchn) sdkhelper.EjectResult(data, rMsg, out) + f.mtxRunning.Lock() + f.running = true + f.mtxRunning.Unlock() + var id, name string if rMsg.Tasklab != nil { id, name = rMsg.Tasklab.Taskid, rMsg.Tasklab.Taskname -- Gitblit v1.8.0