diff options
author | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-03-04 10:35:13 +1100 |
---|---|---|
committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-03-04 10:35:13 +1100 |
commit | bde70720e7185ea02f51d485d34ef0fd5422323a (patch) | |
tree | 10470b3a558b4f4beba3cec2b5c855b2a127a930 | |
parent | 4930a6ecb49f793bbd460c0aad0fd614a51ea6f7 (diff) | |
download | nspr-hg-bde70720e7185ea02f51d485d34ef0fd5422323a.tar.gz |
Bug 1252639 (part 1) - Remove the shared PLArena freelist. r=glandium.
-rw-r--r-- | lib/ds/plarena.c | 152 | ||||
-rw-r--r-- | lib/ds/plarenas.h | 2 |
2 files changed, 19 insertions, 135 deletions
diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c index 689496dc..a582ac63 100644 --- a/lib/ds/plarena.c +++ b/lib/ds/plarena.c @@ -17,8 +17,6 @@ #include "prlock.h" #include "prinit.h" -static PLArena *arena_freelist; - #ifdef PL_ARENAMETER static PLArenaStats *arena_stats_list; @@ -29,49 +27,6 @@ static PLArenaStats *arena_stats_list; #define PL_ARENA_DEFAULT_ALIGN sizeof(double) -static PRLock *arenaLock; -static PRCallOnceType once; -static const PRCallOnceType pristineCallOnce; - -/* -** InitializeArenas() -- Initialize arena operations. -** -** InitializeArenas() is called exactly once and only once from -** LockArena(). This function creates the arena protection -** lock: arenaLock. -** -** Note: If the arenaLock cannot be created, InitializeArenas() -** fails quietly, returning only PR_FAILURE. This percolates up -** to the application using the Arena API. He gets no arena -** from PL_ArenaAllocate(). It's up to him to fail gracefully -** or recover. -** -*/ -static PRStatus InitializeArenas( void ) -{ - PR_ASSERT( arenaLock == NULL ); - arenaLock = PR_NewLock(); - if ( arenaLock == NULL ) - return PR_FAILURE; - else - return PR_SUCCESS; -} /* end ArenaInitialize() */ - -static PRStatus LockArena( void ) -{ - PRStatus rc = PR_CallOnce( &once, InitializeArenas ); - - if ( PR_FAILURE != rc ) - PR_Lock( arenaLock ); - return(rc); -} /* end LockArena() */ - -static void UnlockArena( void ) -{ - PR_Unlock( arenaLock ); - return; -} /* end UnlockArena() */ - PR_IMPLEMENT(void) PL_InitArenaPool( PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align) { @@ -124,14 +79,7 @@ PR_IMPLEMENT(void) PL_InitArenaPool( ** pool. ** ** First, try to satisfy the request from arenas starting at -** pool->current. -** -** If there is not enough space in the arena pool->current, try -** to claim an arena, on a first fit basis, from the global -** freelist (arena_freelist). -** -** If no arena in arena_freelist is suitable, then try to -** allocate a new arena from the heap. +** pool->current. Then try to allocate a new arena from the heap. ** ** Returns: pointer to allocated space or NULL ** @@ -169,37 +117,6 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb) } while( NULL != (a = a->next) ); } - /* attempt to allocate from arena_freelist */ - { - PLArena *p; /* previous pointer, for unlinking from freelist */ - - /* lock the arena_freelist. Make access to the freelist MT-Safe */ - if ( PR_FAILURE == LockArena()) - return(0); - - for ( a = arena_freelist, p = NULL; a != NULL ; p = a, a = a->next ) { - if ( nb <= a->limit - a->base ) { - if ( p == NULL ) - arena_freelist = a->next; - else - p->next = a->next; - UnlockArena(); - a->avail = a->base; - rp = (char *)a->avail; - a->avail += nb; - /* the newly allocated arena is linked after pool->current - * and becomes pool->current */ - a->next = pool->current->next; - pool->current->next = a; - pool->current = a; - if ( NULL == pool->first.next ) - pool->first.next = a; - return(rp); - } - } - UnlockArena(); - } - /* attempt to allocate from the heap */ { PRUint32 sz = PR_MAX(pool->arenasize, nb); @@ -246,10 +163,11 @@ PR_IMPLEMENT(void *) PL_ArenaGrow( return newp; } -static void ClearArenaList(PLArena *a, PRInt32 pattern) +PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern) { + PLArena *a; - for (; a; a = a->next) { + for (a = pool->first.next; a; a = a->next) { PR_ASSERT(a->base <= a->avail && a->avail <= a->limit); a->avail = a->base; PL_CLEAR_UNUSED_PATTERN(a, pattern); @@ -257,48 +175,25 @@ static void ClearArenaList(PLArena *a, PRInt32 pattern) } } -PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern) -{ - ClearArenaList(pool->first.next, pattern); -} - /* * Free tail arenas linked after head, which may not be the true list head. * Reset pool->current to point to head in case it pointed at a tail arena. */ -static void FreeArenaList(PLArenaPool *pool, PLArena *head, PRBool reallyFree) +static void FreeArenaList(PLArenaPool *pool, PLArena *head) { - PLArena **ap, *a; - - ap = &head->next; - a = *ap; + PLArena *a = head->next; if (!a) return; -#ifdef DEBUG - ClearArenaList(a, PL_FREE_PATTERN); -#endif + head->next = NULL; - if (reallyFree) { - do { - *ap = a->next; - PL_CLEAR_ARENA(a); - PL_COUNT_ARENA(pool,--); - PR_DELETE(a); - } while ((a = *ap) != 0); - } else { - /* Insert the whole arena chain at the front of the freelist. */ - do { - PL_MAKE_MEM_NOACCESS((void*)(*ap)->base, - (*ap)->limit - (*ap)->base); - ap = &(*ap)->next; - } while (*ap); - LockArena(); - *ap = arena_freelist; - arena_freelist = a; - head->next = 0; - UnlockArena(); - } + do { + PLArena *tmp = a; + a = a->next; + PL_CLEAR_ARENA(tmp); + PL_COUNT_ARENA(pool,--); + PR_DELETE(tmp); + } while (a); pool->current = head; } @@ -310,7 +205,7 @@ PR_IMPLEMENT(void) PL_ArenaRelease(PLArenaPool *pool, char *mark) for (a = &pool->first; a; a = a->next) { if (PR_UPTRDIFF(mark, a->base) <= PR_UPTRDIFF(a->avail, a->base)) { a->avail = (PRUword)PL_ARENA_ALIGN(pool, mark); - FreeArenaList(pool, a, PR_FALSE); + FreeArenaList(pool, a); return; } } @@ -318,13 +213,13 @@ PR_IMPLEMENT(void) PL_ArenaRelease(PLArenaPool *pool, char *mark) PR_IMPLEMENT(void) PL_FreeArenaPool(PLArenaPool *pool) { - FreeArenaList(pool, &pool->first, PR_FALSE); + FreeArenaList(pool, &pool->first); COUNT(pool, ndeallocs); } PR_IMPLEMENT(void) PL_FinishArenaPool(PLArenaPool *pool) { - FreeArenaList(pool, &pool->first, PR_TRUE); + FreeArenaList(pool, &pool->first); #ifdef PL_ARENAMETER { PLArenaStats *stats, **statsp; @@ -348,19 +243,6 @@ PR_IMPLEMENT(void) PL_CompactArenaPool(PLArenaPool *ap) PR_IMPLEMENT(void) PL_ArenaFinish(void) { - PLArena *a, *next; - - for (a = arena_freelist; a; a = next) { - next = a->next; - PR_DELETE(a); - } - arena_freelist = NULL; - - if (arenaLock) { - PR_DestroyLock(arenaLock); - arenaLock = NULL; - } - once = pristineCallOnce; } PR_IMPLEMENT(size_t) PL_SizeOfArenaPoolExcludingPool( diff --git a/lib/ds/plarenas.h b/lib/ds/plarenas.h index 98bd7f87..b374732e 100644 --- a/lib/ds/plarenas.h +++ b/lib/ds/plarenas.h @@ -24,6 +24,8 @@ PR_EXTERN(void) PL_InitArenaPool( /* ** Finish using arenas, freeing all memory associated with them. +** NOTE: this function is now a no-op. If you want to free a single +** PLArenaPoolUse use PL_FreeArenaPool() or PL_FinishArenaPool(). **/ PR_EXTERN(void) PL_ArenaFinish(void); |