From 7cd22e5cfb5b7622b4ec19e57246d612e10b3605 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期六, 29 六月 2019 10:53:31 +0800
Subject: [PATCH] add lock
---
service/FaceSdkService.go | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go
index fcdcd04..b3b8215 100644
--- a/service/FaceSdkService.go
+++ b/service/FaceSdkService.go
@@ -129,7 +129,7 @@
case <-ticker.C:
return
default:
- if feas,ok := resultMap[s.Id];ok {
+ if feas,ok := resultMap.Get(s.Id);ok {
s.Result = feas
return
}
@@ -176,13 +176,29 @@
imgPushChan <- is
}
-var resultMap map[string][]*protomsg.ResultFaceExtCom
+type FeaResult struct {
+ FeaM map[string][]*protomsg.ResultFaceExtCom
+ Lock sync.Mutex
+}
+
+func (f *FeaResult) Write(id string,faceResult []*protomsg.ResultFaceExtCom){
+ f.Lock.Lock()
+ defer f.Lock.Unlock()
+ f.FeaM[id] = faceResult
+}
+
+func (f *FeaResult) Get(id string) ([]*protomsg.ResultFaceExtCom,bool){
+ f.Lock.Lock()
+ defer f.Lock.Unlock()
+ coms,ok := f.FeaM[id]
+ return coms,ok
+}
+
+var resultMap = FeaResult{}
func InitService() {
fmt.Println("service init!")
imgPushChan = make(chan []byte)
-
- resultMap = make(map[string][]*protomsg.ResultFaceExtCom,0)
client_push = deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
client_pull = deliver.NewClient(deliver.PushPull, Url_Service_PULL)
@@ -246,7 +262,7 @@
} else {
fmt.Println("鐩爣鏁帮細",len(pff.ExtComp))
if len(pff.ExtComp) >0 {
- resultMap[rMsg.Cid] = pff.ExtComp
+ resultMap.Write(perId,pff.ExtComp)
for _,fea :=range pff.ExtComp{
base64Fea := base64.StdEncoding.EncodeToString(fea.Feats)
--
Gitblit v1.8.0