Skip to content

Commit

Permalink
Smart Tiking waking up only when buffer level 0->1 (#144)
Browse files Browse the repository at this point in the history
* Smart ticking revision

* format upate

---------

Co-authored-by: Yifan Sun <sunyifan112358@gmail.com>
  • Loading branch information
sylvzhz and syifan authored Oct 1, 2024
1 parent 2b70cea commit fcdfc76
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sim/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -139,6 +143,8 @@ func (p *LimitNumMsgPort) Deliver(msg Msg) *SendError {
return NewSendError()
}

wasEmpty := (p.incomingBuf.Size() == 0)

hookCtx := HookCtx{
Domain: p,
Pos: HookPosPortMsgRecvd,
Expand All @@ -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)
}

Expand Down

0 comments on commit fcdfc76

Please sign in to comment.