diff options
| author | Russ Cox <rsc@golang.org> | 2011-02-02 23:03:47 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-02-02 23:03:47 -0500 |
| commit | 1e063b32cdeaa6e07c8e720823ec5d280145cbcd (patch) | |
| tree | 68d3b99a1c1b54c1c1edf440e23904ec150c59d5 /src/pkg/runtime/mfinal.c | |
| parent | 6b93a92ac0ef864466254c58ffd1cbc9bc590ebc (diff) | |
| download | go-1e063b32cdeaa6e07c8e720823ec5d280145cbcd.tar.xz | |
runtime: faster allocator, garbage collector
GC is still single-threaded.
Multiple threads will happen in another CL.
Garbage collection pauses are typically
about half as long as they were before this CL.
R=brainman, iant, r
CC=golang-dev
https://golang.org/cl/3975046
Diffstat (limited to 'src/pkg/runtime/mfinal.c')
| -rw-r--r-- | src/pkg/runtime/mfinal.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/pkg/runtime/mfinal.c b/src/pkg/runtime/mfinal.c index f73561b3cd..03ee777c0b 100644 --- a/src/pkg/runtime/mfinal.c +++ b/src/pkg/runtime/mfinal.c @@ -5,6 +5,7 @@ #include "runtime.h" #include "malloc.h" +// TODO(rsc): Why not just use mheap.Lock? static Lock finlock; // Finalizer hash table. Direct hash, linear scan, at most 3/4 full. @@ -101,24 +102,21 @@ runtime·addfinalizer(void *p, void (*f)(void*), int32 nret) } runtime·lock(&finlock); - if(!runtime·mlookup(p, &base, nil, nil, &ref) || p != base) { + if(!runtime·mlookup(p, &base, nil, nil) || p != base) { runtime·unlock(&finlock); runtime·throw("addfinalizer on invalid pointer"); } if(f == nil) { - if(*ref & RefHasFinalizer) { - lookfintab(&fintab, p, 1); - *ref &= ~RefHasFinalizer; - } + lookfintab(&fintab, p, 1); runtime·unlock(&finlock); return; } - if(*ref & RefHasFinalizer) { + if(lookfintab(&fintab, p, 0)) { runtime·unlock(&finlock); runtime·throw("double finalizer"); } - *ref |= RefHasFinalizer; + runtime·setblockspecial(p); if(fintab.nkey >= fintab.max/2+fintab.max/4) { // keep table at most 3/4 full: @@ -134,7 +132,7 @@ runtime·addfinalizer(void *p, void (*f)(void*), int32 nret) newtab.max *= 3; } - newtab.key = runtime·mallocgc(newtab.max*sizeof newtab.key[0], RefNoPointers, 0, 1); + newtab.key = runtime·mallocgc(newtab.max*sizeof newtab.key[0], FlagNoPointers, 0, 1); newtab.val = runtime·mallocgc(newtab.max*sizeof newtab.val[0], 0, 0, 1); for(i=0; i<fintab.max; i++) { |
