/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK *****
*/
/*
* Lifetime-based fast allocation, inspired by much prior art, including
* "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
* David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
*/
#include <stdlib.h>
#include <string.h>
#include "plarena.h"
#include "prmem.h"
#include "prbit.h"
#include "prlog.h"
#include "prlock.h"
#include "prinit.h"
#ifdef PL_ARENAMETER
#else
#endif
#define PL_ARENA_DEFAULT_ALIGN sizeof(double)
/*
** 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.
**
*/
{
arenaLock = PR_NewLock();
return PR_FAILURE;
else
return PR_SUCCESS;
} /* end ArenaInitialize() */
{
if ( PR_FAILURE != rc )
return(rc);
} /* end LockArena() */
static void UnlockArena( void )
{
return;
} /* end UnlockArena() */
{
#if defined(XP_MAC)
#endif
if (align == 0)
#ifdef PL_ARENAMETER
#endif
}
/*
** PL_ArenaAllocate() -- allocate space from an arena pool
**
** Description: PL_ArenaAllocate() allocates space from an arena
** 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.
**
** Returns: pointer to allocated space or NULL
**
** Notes: The original implementation had some difficult to
** solve bugs; the code was difficult to read. Sometimes it's
** just easier to rewrite it. I did that. larryh.
**
** See also: bugzilla: 45343.
**
*/
{
PLArena *a;
/* attempt to allocate from arenas at pool->current */
{
do {
return rp;
}
}
/* 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);
if ( p == arena_freelist )
arena_freelist = a->next;
else
UnlockArena();
/* the newly allocated arena is linked after pool->current
* and becomes pool->current */
return(rp);
}
}
UnlockArena();
}
/* attempt to allocate from the heap */
{
if ( NULL != a ) {
/* the newly allocated arena is linked after pool->current
* and becomes pool->current */
PL_COUNT_ARENA(pool,++);
return(rp);
}
}
/* we got to here, and there's no memory to allocate */
return(NULL);
} /* --- end PL_ArenaAllocate() --- */
{
void *newp;
if (newp)
return newp;
}
/*
* 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.
*/
{
a = *ap;
if (!a)
return;
#ifdef DEBUG
do {
PL_CLEAR_UNUSED(a);
} while ((a = a->next) != 0);
a = *ap;
#endif
if (reallyFree) {
do {
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 {
} while (*ap);
LockArena();
*ap = arena_freelist;
arena_freelist = a;
UnlockArena();
}
}
{
PLArena *a;
return;
}
}
}
{
}
{
#ifdef PL_ARENAMETER
{
return;
}
}
}
#endif
}
{
#if XP_MAC
#if 0
while (curr) {
}
#endif
#endif
}
{
for (a = arena_freelist; a; a = next) {
PR_DELETE(a);
}
if (arenaLock) {
}
}
#ifdef PL_ARENAMETER
{
}
{
}
{
}
{
}
{
}
#include <math.h>
#include <stdio.h>
{
} else {
}
}
}
#endif /* PL_ARENAMETER */