lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 34b5ad6fd5e6bb9c3e0190467eb54a40ba9ce45d
parent 121b1130d450e81812e3c347cc034131a7e59693
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat,  6 Jan 2024 07:57:02 +0900

move client.fidPool.Lock from nextFid to add

Diffstat:
Mclient/fid.go | 27++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/client/fid.go b/client/fid.go @@ -25,27 +25,25 @@ func newClientFid(id uint32) *fid { type fidPool struct { m map[uint32]*fid - lock *sync.Mutex + *sync.Mutex } func allocClientFidPool() *fidPool { return &fidPool{ - m: make(map[uint32]*fid), - lock: new(sync.Mutex), + make(map[uint32]*fid), + new(sync.Mutex), } } func (pool *fidPool) lookup(fid uint32) (*fid, bool) { - pool.lock.Lock() - defer pool.lock.Unlock() - + pool.Lock() + defer pool.Unlock() f, ok := pool.m[fid] return f, ok } +// NextFid does not lock pool. Lock it before calling this function. func (pool *fidPool) nextFid() (uint32, error) { - pool.lock.Lock() - defer pool.lock.Unlock() for i := uint32(0); i < i+1; i++ { if _, ok := pool.m[i]; !ok { return i, nil @@ -55,12 +53,12 @@ func (pool *fidPool) nextFid() (uint32, error) { } func (pool *fidPool) add() (*fid, error) { + pool.Lock() + defer pool.Unlock() fid, err := pool.nextFid() if err != nil { return nil, err } - pool.lock.Lock() - defer pool.lock.Unlock() if _, ok := pool.m[fid]; ok { return nil, fmt.Errorf("fid already in use.") } @@ -70,15 +68,14 @@ func (pool *fidPool) add() (*fid, error) { } func (pool *fidPool) delete(fid uint32) { - pool.lock.Lock() - defer pool.lock.Unlock() - + pool.Lock() + defer pool.Unlock() delete(pool.m, fid) } func (pool *fidPool) String() string { - pool.lock.Lock() // TODO: need? - defer pool.lock.Unlock() + pool.Lock() // TODO: need? + defer pool.Unlock() s := "{" for fnum, fstruct := range pool.m { if fstruct.file == nil {