From 3e45412327a2654a77944249962b3652e6142299 Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 17 Jan 2011 12:40:45 +0100 Subject: Imported Upstream version 2011.01.12 --- src/pkg/runtime/mfinal.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/pkg/runtime/mfinal.c') diff --git a/src/pkg/runtime/mfinal.c b/src/pkg/runtime/mfinal.c index 03c1e1044..f73561b3c 100644 --- a/src/pkg/runtime/mfinal.c +++ b/src/pkg/runtime/mfinal.c @@ -5,7 +5,7 @@ #include "runtime.h" #include "malloc.h" -Lock finlock; +static Lock finlock; // Finalizer hash table. Direct hash, linear scan, at most 3/4 full. // Table size is power of 3 so that hash can be key % max. @@ -44,7 +44,7 @@ addfintab(Fintab *t, void *k, Finalizer *v) } // cannot happen - table is known to be non-full - throw("finalizer table inconsistent"); + runtime·throw("finalizer table inconsistent"); ret: t->key[i] = k; @@ -77,7 +77,7 @@ lookfintab(Fintab *t, void *k, bool del) } // cannot happen - table is known to be non-full - throw("finalizer table inconsistent"); + runtime·throw("finalizer table inconsistent"); return nil; } @@ -85,7 +85,7 @@ static Fintab fintab; // add finalizer; caller is responsible for making sure not already in table void -addfinalizer(void *p, void (*f)(void*), int32 nret) +runtime·addfinalizer(void *p, void (*f)(void*), int32 nret) { Fintab newtab; int32 i; @@ -95,28 +95,28 @@ addfinalizer(void *p, void (*f)(void*), int32 nret) e = nil; if(f != nil) { - e = mal(sizeof *e); + e = runtime·mal(sizeof *e); e->fn = f; e->nret = nret; } - lock(&finlock); - if(!mlookup(p, &base, nil, nil, &ref) || p != base) { - unlock(&finlock); - throw("addfinalizer on invalid pointer"); + runtime·lock(&finlock); + if(!runtime·mlookup(p, &base, nil, nil, &ref) || p != base) { + runtime·unlock(&finlock); + runtime·throw("addfinalizer on invalid pointer"); } if(f == nil) { if(*ref & RefHasFinalizer) { lookfintab(&fintab, p, 1); *ref &= ~RefHasFinalizer; } - unlock(&finlock); + runtime·unlock(&finlock); return; } if(*ref & RefHasFinalizer) { - unlock(&finlock); - throw("double finalizer"); + runtime·unlock(&finlock); + runtime·throw("double finalizer"); } *ref |= RefHasFinalizer; @@ -124,7 +124,7 @@ addfinalizer(void *p, void (*f)(void*), int32 nret) // keep table at most 3/4 full: // allocate new table and rehash. - runtime_memclr((byte*)&newtab, sizeof newtab); + runtime·memclr((byte*)&newtab, sizeof newtab); newtab.max = fintab.max; if(newtab.max == 0) newtab.max = 3*3*3; @@ -134,8 +134,8 @@ addfinalizer(void *p, void (*f)(void*), int32 nret) newtab.max *= 3; } - newtab.key = mallocgc(newtab.max*sizeof newtab.key[0], RefNoPointers, 0, 1); - newtab.val = mallocgc(newtab.max*sizeof newtab.val[0], 0, 0, 1); + newtab.key = runtime·mallocgc(newtab.max*sizeof newtab.key[0], RefNoPointers, 0, 1); + newtab.val = runtime·mallocgc(newtab.max*sizeof newtab.val[0], 0, 0, 1); for(i=0; i