LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Per-thread (in Go, per-M) malloc cache for small objects. | 5 // Per-thread (in Go, per-M) malloc cache for small objects. |
6 // | 6 // |
7 // See malloc.h for an overview. | 7 // See malloc.h for an overview. |
8 | 8 |
9 #include "runtime.h" | 9 #include "runtime.h" |
10 #include "arch_GOARCH.h" | 10 #include "arch_GOARCH.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 l->nlistmin = l->nlist; | 36 l->nlistmin = l->nlist; |
37 c->size -= size; | 37 c->size -= size; |
38 | 38 |
39 // v is zeroed except for the link pointer | 39 // v is zeroed except for the link pointer |
40 // that we used above; zero that. | 40 // that we used above; zero that. |
41 v->next = nil; | 41 v->next = nil; |
42 if(zeroed) { | 42 if(zeroed) { |
43 // block is zeroed iff second word is zero ... | 43 // block is zeroed iff second word is zero ... |
44 if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0) | 44 if(size > sizeof(uintptr) && ((uintptr*)v)[1] != 0) |
45 runtime·memclr((byte*)v, size); | 45 runtime·memclr((byte*)v, size); |
46 else { | |
47 // ... except for the link pointer | |
48 // that we used above; zero that. | |
49 v->next = nil; | |
50 } | |
51 } | 46 } |
52 c->local_cachealloc += size; | 47 c->local_cachealloc += size; |
53 c->local_objects++; | 48 c->local_objects++; |
54 return v; | 49 return v; |
55 } | 50 } |
56 | 51 |
57 // Take n elements off l and return them to the central free list. | 52 // Take n elements off l and return them to the central free list. |
58 static void | 53 static void |
59 ReleaseN(MCache *c, MCacheList *l, int32 n, int32 sizeclass) | 54 ReleaseN(MCache *c, MCacheList *l, int32 n, int32 sizeclass) |
60 { | 55 { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 { | 120 { |
126 int32 i; | 121 int32 i; |
127 MCacheList *l; | 122 MCacheList *l; |
128 | 123 |
129 for(i=0; i<NumSizeClasses; i++) { | 124 for(i=0; i<NumSizeClasses; i++) { |
130 l = &c->list[i]; | 125 l = &c->list[i]; |
131 ReleaseN(c, l, l->nlist, i); | 126 ReleaseN(c, l, l->nlist, i); |
132 l->nlistmin = 0; | 127 l->nlistmin = 0; |
133 } | 128 } |
134 } | 129 } |
LEFT | RIGHT |