| OLD | NEW |
| 1 package gkvlite | 1 package gkvlite |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "fmt" | 4 "fmt" |
| 5 "sync" | 5 "sync" |
| 6 "sync/atomic" | 6 "sync/atomic" |
| 7 "unsafe" | |
| 8 ) | 7 ) |
| 9 | 8 |
| 10 var freeNodeLock sync.Mutex | 9 var freeNodeLock sync.Mutex |
| 11 var freeNodes *node | 10 var freeNodes *node |
| 12 | 11 |
| 13 var freeNodeLocLock sync.Mutex | 12 var freeNodeLocLock sync.Mutex |
| 14 var freeNodeLocs *nodeLoc | 13 var freeNodeLocs *nodeLoc |
| 15 | 14 |
| 16 var freeRootNodeLocLock sync.Mutex | 15 var freeRootNodeLocLock sync.Mutex |
| 17 var freeRootNodeLocs *rootNodeLoc | 16 var freeRootNodeLocs *rootNodeLoc |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 if nloc == nil { | 165 if nloc == nil { |
| 167 allocStats.AllocNodeLocs++ | 166 allocStats.AllocNodeLocs++ |
| 168 t.allocStats.AllocNodeLocs++ | 167 t.allocStats.AllocNodeLocs++ |
| 169 freeNodeLocLock.Unlock() | 168 freeNodeLocLock.Unlock() |
| 170 nloc = &nodeLoc{} | 169 nloc = &nodeLoc{} |
| 171 } else { | 170 } else { |
| 172 freeNodeLocs = nloc.next | 171 freeNodeLocs = nloc.next |
| 173 allocStats.CurFreeNodeLocs-- | 172 allocStats.CurFreeNodeLocs-- |
| 174 freeNodeLocLock.Unlock() | 173 freeNodeLocLock.Unlock() |
| 175 } | 174 } |
| 176 » nloc.loc = unsafe.Pointer(nil) | 175 » nloc.loc = nil |
| 177 » nloc.node = unsafe.Pointer(n) | 176 » nloc.node = n |
| 178 nloc.next = nil | 177 nloc.next = nil |
| 179 return nloc | 178 return nloc |
| 180 } | 179 } |
| 181 | 180 |
| 182 // Assumes that the caller serializes invocations. | 181 // Assumes that the caller serializes invocations. |
| 183 func (t *Collection) freeNodeLoc(nloc *nodeLoc) { | 182 func (t *Collection) freeNodeLoc(nloc *nodeLoc) { |
| 184 if nloc == nil || nloc == empty_nodeLoc { | 183 if nloc == nil || nloc == empty_nodeLoc { |
| 185 return | 184 return |
| 186 } | 185 } |
| 187 if nloc.next != nil { | 186 if nloc.next != nil { |
| 188 panic("double free nodeLoc") | 187 panic("double free nodeLoc") |
| 189 } | 188 } |
| 190 » nloc.loc = unsafe.Pointer(nil) | 189 » nloc.loc = nil |
| 191 » nloc.node = unsafe.Pointer(nil) | 190 » nloc.node = nil |
| 192 | 191 |
| 193 freeNodeLocLock.Lock() | 192 freeNodeLocLock.Lock() |
| 194 nloc.next = freeNodeLocs | 193 nloc.next = freeNodeLocs |
| 195 freeNodeLocs = nloc | 194 freeNodeLocs = nloc |
| 196 allocStats.CurFreeNodeLocs++ | 195 allocStats.CurFreeNodeLocs++ |
| 197 allocStats.FreeNodeLocs++ | 196 allocStats.FreeNodeLocs++ |
| 198 t.allocStats.FreeNodeLocs++ | 197 t.allocStats.FreeNodeLocs++ |
| 199 freeNodeLocLock.Unlock() | 198 freeNodeLocLock.Unlock() |
| 200 } | 199 } |
| 201 | 200 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 242 } |
| 244 } | 243 } |
| 245 freeRootNodeLocLock.Lock() | 244 freeRootNodeLocLock.Lock() |
| 246 rnl.next = freeRootNodeLocs | 245 rnl.next = freeRootNodeLocs |
| 247 freeRootNodeLocs = rnl | 246 freeRootNodeLocs = rnl |
| 248 allocStats.CurFreeRootNodeLocs++ | 247 allocStats.CurFreeRootNodeLocs++ |
| 249 allocStats.FreeRootNodeLocs++ | 248 allocStats.FreeRootNodeLocs++ |
| 250 t.allocStats.FreeRootNodeLocs++ | 249 t.allocStats.FreeRootNodeLocs++ |
| 251 freeRootNodeLocLock.Unlock() | 250 freeRootNodeLocLock.Unlock() |
| 252 } | 251 } |
| OLD | NEW |