派生自 libgowrapper/face

zhangmeng
2020-01-13 38672e1ea56024fbe812e4a2aae5fbe267c9770f
vehicle remove model and key
1个文件已修改
44 ■■■■■ 已修改文件
run.go 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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