From 373c81c18fae060436dd23b058664a1edcbb2bbc Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 2 Mar 2025 22:06:52 +0800 Subject: [PATCH] 1 (#33) --- ctx/Ctx.go | 11 ++++++----- signal/Signal.go | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ctx/Ctx.go b/ctx/Ctx.go index 7dd15d9..669350a 100644 --- a/ctx/Ctx.go +++ b/ctx/Ctx.go @@ -3,12 +3,13 @@ package ctx import ( "context" "errors" - "runtime" "sync" "sync/atomic" "time" ) +const sleepDru = 100 + var ( ptr = &struct{}{} ErrWaitTo = errors.New("ErrWaitTo") @@ -64,15 +65,15 @@ func WithWait(sctx context.Context, planNum int32, to ...time.Duration) (dctx co if len(to) > 0 && time.Since(be) > to[0] { return ErrWaitTo } - time.Sleep(time.Millisecond * 100) - runtime.Gosched() + time.Sleep(time.Millisecond * sleepDru) + // runtime.Gosched() } for !ctx.r32.CompareAndSwap(0, -1) { if len(to) > 0 && time.Since(be) > to[0] { return ErrWaitTo } - time.Sleep(time.Millisecond * 100) - runtime.Gosched() + time.Sleep(time.Millisecond * sleepDru) + // runtime.Gosched() } if len(to) > 0 && time.Since(be) > to[0] { return ErrWaitTo diff --git a/signal/Signal.go b/signal/Signal.go index 9fdc2b3..7704030 100644 --- a/signal/Signal.go +++ b/signal/Signal.go @@ -1,8 +1,8 @@ package part import ( - "runtime" "sync/atomic" + "time" ) type Signal struct { @@ -39,7 +39,7 @@ func (i *Signal) Done() { if i.Islive() { close(i.c) for !i.waitCount.CompareAndSwap(0, -1) { - runtime.Gosched() + time.Sleep(time.Millisecond * 100) } } } -- 2.39.2