From fcdfc7651b3eda6b61ffbd60c2f5820b1742f0c9 Mon Sep 17 00:00:00 2001 From: Huizhi Zhao Date: Tue, 1 Oct 2024 23:30:24 +0800 Subject: [PATCH] Smart Tiking waking up only when buffer level 0->1 (#144) * Smart ticking revision * format upate --------- Co-authored-by: Yifan Sun --- sim/port.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sim/port.go b/sim/port.go index 83eb45bf..dc7ad410 100644 --- a/sim/port.go +++ b/sim/port.go @@ -116,6 +116,8 @@ func (p *LimitNumMsgPort) Send(msg Msg) *SendError { return NewSendError() } + wasEmpty := (p.outgoingBuf.Size() == 0) + p.outgoingBuf.Push(msg) hookCtx := HookCtx{ Domain: p, @@ -125,7 +127,9 @@ func (p *LimitNumMsgPort) Send(msg Msg) *SendError { p.InvokeHook(hookCtx) p.lock.Unlock() - p.conn.NotifySend() + if wasEmpty { + p.conn.NotifySend() + } return nil } @@ -139,6 +143,8 @@ func (p *LimitNumMsgPort) Deliver(msg Msg) *SendError { return NewSendError() } + wasEmpty := (p.incomingBuf.Size() == 0) + hookCtx := HookCtx{ Domain: p, Pos: HookPosPortMsgRecvd, @@ -149,7 +155,7 @@ func (p *LimitNumMsgPort) Deliver(msg Msg) *SendError { p.incomingBuf.Push(msg) p.lock.Unlock() - if p.comp != nil { + if p.comp != nil && wasEmpty { p.comp.NotifyRecv(p) }