| 38 | } |
| 39 | |
| 40 | func (c *operatorCache) alloc() *FDOperator { |
| 41 | lock(&c.locked) |
| 42 | if c.first == nil { |
| 43 | const opSize = unsafe.Sizeof(FDOperator{}) |
| 44 | n := block4k / opSize |
| 45 | if n == 0 { |
| 46 | n = 1 |
| 47 | } |
| 48 | index := int32(len(c.cache)) |
| 49 | for i := uintptr(0); i < n; i++ { |
| 50 | pd := &FDOperator{index: index} |
| 51 | c.cache = append(c.cache, pd) |
| 52 | pd.next = c.first |
| 53 | c.first = pd |
| 54 | index++ |
| 55 | } |
| 56 | } |
| 57 | op := c.first |
| 58 | c.first = op.next |
| 59 | unlock(&c.locked) |
| 60 | return op |
| 61 | } |
| 62 | |
| 63 | // freeable mark the operator that could be freed |
| 64 | // only poller could do the real free action |