LEFT | RIGHT |
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 // Page heap. | 5 // Page heap. |
6 // | 6 // |
7 // See malloc.h for overview. | 7 // See malloc.h for overview. |
8 // | 8 // |
9 // When a MSpan is in the heap free list, state == MSpanFree | 9 // When a MSpan is in the heap free list, state == MSpanFree |
10 // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. | 10 // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. |
(...skipping 17 matching lines...) Expand all Loading... |
28 MSpan *s; | 28 MSpan *s; |
29 | 29 |
30 h = vh; | 30 h = vh; |
31 s = (MSpan*)p; | 31 s = (MSpan*)p; |
32 s->allnext = h->allspans; | 32 s->allnext = h->allspans; |
33 h->allspans = s; | 33 h->allspans = s; |
34 } | 34 } |
35 | 35 |
36 // Initialize the heap; fetch memory using alloc. | 36 // Initialize the heap; fetch memory using alloc. |
37 void | 37 void |
38 runtime·MHeap_Init(MHeap *h, void *(*alloc)(void*, uintptr)) | 38 runtime·MHeap_Init(MHeap *h, void *(*alloc)(uintptr)) |
39 { | 39 { |
40 uint32 i; | 40 uint32 i; |
41 | 41 |
42 runtime·FixAlloc_Init(&h->spanalloc, sizeof(MSpan), alloc, RecordSpan, h
); | 42 runtime·FixAlloc_Init(&h->spanalloc, sizeof(MSpan), alloc, RecordSpan, h
); |
43 runtime·FixAlloc_Init(&h->cachealloc, sizeof(MCache), alloc, nil, nil); | 43 runtime·FixAlloc_Init(&h->cachealloc, sizeof(MCache), alloc, nil, nil); |
44 // h->mapcache needs no init | 44 // h->mapcache needs no init |
45 for(i=0; i<nelem(h->free); i++) | 45 for(i=0; i<nelem(h->free); i++) |
46 runtime·MSpanList_Init(&h->free[i]); | 46 runtime·MSpanList_Init(&h->free[i]); |
47 runtime·MSpanList_Init(&h->large); | 47 runtime·MSpanList_Init(&h->large); |
48 for(i=0; i<nelem(h->central); i++) | 48 for(i=0; i<nelem(h->central); i++) |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 void | 370 void |
371 runtime·MSpanList_Insert(MSpan *list, MSpan *span) | 371 runtime·MSpanList_Insert(MSpan *list, MSpan *span) |
372 { | 372 { |
373 if(span->next != nil || span->prev != nil) | 373 if(span->next != nil || span->prev != nil) |
374 runtime·throw("MSpanList_Insert"); | 374 runtime·throw("MSpanList_Insert"); |
375 span->next = list->next; | 375 span->next = list->next; |
376 span->prev = list; | 376 span->prev = list; |
377 span->next->prev = span; | 377 span->next->prev = span; |
378 span->prev->next = span; | 378 span->prev->next = span; |
379 } | 379 } |
LEFT | RIGHT |