MCPcopy Create free account
hub / github.com/cloudwego/netpoll / alloc

Method alloc

fd_operator_cache.go:40–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38}
39
40func (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

Callers 4

AllocMethod · 0.80
TestPersistFDOperatorFunction · 0.80

Calls 2

lockFunction · 0.85
unlockFunction · 0.85

Tested by 3

TestPersistFDOperatorFunction · 0.64