github.com/hsfzxjy/dgo/go@v0.2.0/pin/pchan/manager_specialized.go (about) 1 package pchan 2 3 import ( 4 "sync" 5 6 "github.com/hsfzxjy/dgo/go/pin/bitset" 7 ) 8 9 type manager1 struct { 10 heads [1]*listener 11 lidsets [1]bitset.Bitset64 12 } 13 14 func (c *manager1) as_chanman(n uint8) Manager { 15 return Manager{ 16 backing: c, 17 heads: c.heads[:n], 18 lidsets: c.lidsets[:n], 19 } 20 } 21 22 func (c *manager1) recycle() { 23 for i := range c.heads { 24 c.heads[i].free() 25 c.heads[i] = nil 26 } 27 c.lidsets = [1]bitset.Bitset64{} 28 } 29 30 type manager2 struct { 31 heads [2]*listener 32 lidsets [2]bitset.Bitset64 33 } 34 35 func (c *manager2) as_chanman(n uint8) Manager { 36 return Manager{ 37 backing: c, 38 heads: c.heads[:n], 39 lidsets: c.lidsets[:n], 40 } 41 } 42 43 func (c *manager2) recycle() { 44 for i := range c.heads { 45 c.heads[i].free() 46 c.heads[i] = nil 47 } 48 c.lidsets = [2]bitset.Bitset64{} 49 } 50 51 type manager4 struct { 52 heads [4]*listener 53 lidsets [4]bitset.Bitset64 54 } 55 56 func (c *manager4) as_chanman(n uint8) Manager { 57 return Manager{ 58 backing: c, 59 heads: c.heads[:n], 60 lidsets: c.lidsets[:n], 61 } 62 } 63 64 func (c *manager4) recycle() { 65 for i := range c.heads { 66 c.heads[i].free() 67 c.heads[i] = nil 68 } 69 c.lidsets = [4]bitset.Bitset64{} 70 } 71 72 type manager8 struct { 73 heads [8]*listener 74 lidsets [8]bitset.Bitset64 75 } 76 77 func (c *manager8) as_chanman(n uint8) Manager { 78 return Manager{ 79 backing: c, 80 heads: c.heads[:n], 81 lidsets: c.lidsets[:n], 82 } 83 } 84 85 func (c *manager8) recycle() { 86 for i := range c.heads { 87 c.heads[i].free() 88 c.heads[i] = nil 89 } 90 c.lidsets = [8]bitset.Bitset64{} 91 } 92 93 type manager16 struct { 94 heads [16]*listener 95 lidsets [16]bitset.Bitset64 96 } 97 98 func (c *manager16) as_chanman(n uint8) Manager { 99 return Manager{ 100 backing: c, 101 heads: c.heads[:n], 102 lidsets: c.lidsets[:n], 103 } 104 } 105 106 func (c *manager16) recycle() { 107 for i := range c.heads { 108 c.heads[i].free() 109 c.heads[i] = nil 110 } 111 c.lidsets = [16]bitset.Bitset64{} 112 } 113 114 type manager32 struct { 115 heads [32]*listener 116 lidsets [32]bitset.Bitset64 117 } 118 119 func (c *manager32) as_chanman(n uint8) Manager { 120 return Manager{ 121 backing: c, 122 heads: c.heads[:n], 123 lidsets: c.lidsets[:n], 124 } 125 } 126 127 func (c *manager32) recycle() { 128 for i := range c.heads { 129 c.heads[i].free() 130 c.heads[i] = nil 131 } 132 c.lidsets = [32]bitset.Bitset64{} 133 } 134 135 type manager64 struct { 136 heads [64]*listener 137 lidsets [64]bitset.Bitset64 138 } 139 140 func (c *manager64) as_chanman(n uint8) Manager { 141 return Manager{ 142 backing: c, 143 heads: c.heads[:n], 144 lidsets: c.lidsets[:n], 145 } 146 } 147 148 func (c *manager64) recycle() { 149 for i := range c.heads { 150 c.heads[i].free() 151 c.heads[i] = nil 152 } 153 c.lidsets = [64]bitset.Bitset64{} 154 } 155 156 var managerPools [7]sync.Pool 157 158 func init() { 159 managerPools[0].New = func() any { return new(manager1) } 160 managerPools[1].New = func() any { return new(manager2) } 161 managerPools[2].New = func() any { return new(manager4) } 162 managerPools[3].New = func() any { return new(manager8) } 163 managerPools[4].New = func() any { return new(manager16) } 164 managerPools[5].New = func() any { return new(manager32) } 165 managerPools[6].New = func() any { return new(manager64) } 166 } 167 168 type imanager interface { 169 as_chanman(n uint8) Manager 170 recycle() 171 }