commit de042609aceb41a20f8c18eac743d73900714558
parent 1847b8103050d6ea74ccfefca7578296ae8dfde4
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 3 Sep 2023 18:53:34 +0900
move functions
Diffstat:
| M | fid.go | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
| D | pool.go | | | 47 | ----------------------------------------------- |
2 files changed, 42 insertions(+), 47 deletions(-)
diff --git a/fid.go b/fid.go
@@ -40,3 +40,45 @@ func (f *Fid) String() string {
}
return fmt.Sprintf("%d", fid)
}
+
+type FidPool struct {
+ m map[uint32]*Fid
+}
+
+func allocFidPool() *FidPool {
+ f := new(FidPool)
+ f.m = make(map[uint32]*Fid)
+ return f
+}
+
+func (pool *FidPool) lookup(fid uint32) (*Fid, bool) {
+ f, ok := pool.m[fid]
+ return f, ok
+}
+
+func (pool *FidPool) alloc(fid uint32) (*Fid, error) {
+ if _, ok := pool.m[fid]; ok {
+ return nil, fmt.Errorf("fid already in use.")
+ }
+ f := newFid(fid)
+ pool.m[fid] = f
+ return f, nil
+}
+
+func (pool *FidPool) delete(fid uint32) *Fid {
+ f, ok := pool.lookup(fid)
+ if !ok {
+ return nil
+ }
+ delete(pool.m, fid)
+ return f
+}
+
+func (pool *FidPool) String() string {
+ s := "{"
+ for fnum, fstruct := range pool.m {
+ s += fmt.Sprintf(" [%d]%v", fnum, fstruct)
+ }
+ s += "}"
+ return s
+}
diff --git a/pool.go b/pool.go
@@ -1,47 +0,0 @@
-package lib9p
-
-import (
- "fmt"
-)
-
-type FidPool struct {
- m map[uint32]*Fid
-}
-
-func allocFidPool() *FidPool {
- f := new(FidPool)
- f.m = make(map[uint32]*Fid)
- return f
-}
-
-func (pool *FidPool) lookup(fid uint32) (*Fid, bool) {
- f, ok := pool.m[fid]
- return f, ok
-}
-
-func (pool *FidPool) alloc(fid uint32) (*Fid, error) {
- if _, ok := pool.m[fid]; ok {
- return nil, fmt.Errorf("fid already in use.")
- }
- f := newFid(fid)
- pool.m[fid] = f
- return f, nil
-}
-
-func (pool *FidPool) delete(fid uint32) *Fid {
- f, ok := pool.lookup(fid)
- if !ok {
- return nil
- }
- delete(pool.m, fid)
- return f
-}
-
-func (pool *FidPool) String() string {
- s := "{"
- for fnum, fstruct := range pool.m {
- s += fmt.Sprintf(" [%d]%v", fnum, fstruct)
- }
- s += "}"
- return s
-}