lib9p

Go 9P library.
Log | Files | Refs

commit 9f77e937b5bf1bdd7a69377f4027d61f248022ba
parent bac7a661fa1e9d4efcb7ce6ab90f956e322a2be1
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 20 Oct 2023 08:26:08 +0900

wait for tag being deleted when TFlush is evoked. need test

Diffstat:
Mreq.go | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/req.go b/req.go @@ -8,6 +8,7 @@ import ( type Req struct { tag uint16 + tagDeleted chan struct{} srv *Server ifcall Msg ofcall Msg @@ -21,6 +22,8 @@ type Req struct { func (r *Req) flush() { // TODO: need mutex? r.cancel() + // wait for tag being deleted. + <-r.tagDeleted } type ReqPool struct { @@ -40,12 +43,12 @@ func newReqPool() *ReqPool { func (rp *ReqPool) add(tag uint16) (*Req, error) { rp.lock.Lock() defer rp.lock.Unlock() - if _, ok := rp.m[tag]; ok { return nil, ErrDupTag } req := &Req{ pool: rp, + tagDeleted: make(chan struct{}), } rp.m[tag] = req return req, nil @@ -61,6 +64,10 @@ func (rp *ReqPool) lookup(tag uint16) (*Req, bool) { func (rp *ReqPool) delete(tag uint16) { rp.lock.Lock() defer rp.lock.Unlock() + req, ok := rp.m[tag] + if ok { + defer close(req.tagDeleted) + } delete(rp.m, tag) }