]> 127.0.0.1 Git - part/.git/commitdiff
1 (#33) v0.28.20250302140701
authorqydysky <qydysky@foxmail.com>
Sun, 2 Mar 2025 14:06:52 +0000 (22:06 +0800)
committerGitHub <noreply@github.com>
Sun, 2 Mar 2025 14:06:52 +0000 (22:06 +0800)
ctx/Ctx.go
signal/Signal.go

index 7dd15d99287a6b3cf167adb8d1a7d4b6ce13d783..669350aaca98ef6a3544393a439252063b90e4cd 100644 (file)
@@ -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
index 9fdc2b31f0ec7d2870592fed7b724d5b2133b785..7704030f7a550fe158543b9a929e251f374bf20e 100644 (file)
@@ -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)
                }
        }
 }