From c84440a662e81b20dad7b1e54b073c7e610875e7 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Mon, 9 Jan 2023 11:55:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A8=8B=E5=BA=8F=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E8=B0=83=E5=BA=A6=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pool.go | 27 ++++++++++++++++++--------- pkg/baseline.go | 2 ++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/internal/pool.go b/internal/pool.go index 36c8602..0ba9505 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -210,33 +210,41 @@ func (pool *Pool) Run(ctx context.Context, offset, limit int) { go pool.doCommonFile() } - go func() { - for { + closeCh := make(chan struct{}) + //go func() { + // select { + // case <-worderDone: + // closeCh <- struct{}{} + // } + //}() + var worderDone bool + wait := func() { + if !worderDone { + worderDone = true pool.wg.Wait() - pool.closeCh <- struct{}{} + close(closeCh) } - }() + } Loop: for { select { case u, ok := <-pool.worder.C: if !ok { + go wait() continue } pool.Statistor.End++ - if int(pool.reqCount) < offset { + if pool.reqCount < offset { pool.reqCount++ continue } if pool.Statistor.End > limit { + go wait() continue } - if u == "" { - continue - } pool.wg.Add(1) pool.reqPool.Invoke(newUnit(u, WordSource)) case source := <-pool.checkCh: @@ -251,7 +259,7 @@ Loop: continue } pool.reqPool.Invoke(unit) - case <-pool.closeCh: + case <-closeCh: break Loop case <-ctx.Done(): break Loop @@ -260,6 +268,7 @@ Loop: } } + pool.wg.Wait() for pool.analyzeDone { time.Sleep(time.Duration(100) * time.Millisecond) } diff --git a/pkg/baseline.go b/pkg/baseline.go index 7760c94..44a6cbd 100644 --- a/pkg/baseline.go +++ b/pkg/baseline.go @@ -35,6 +35,8 @@ func GetSourceName(s int) string { return "rule" case 10: return "bak" + case 11: + return "common" default: return "unknown" }