#ifndef lint
static char rcsid [] = "$RCSfile$ $Revision$ $State$";
#endif
/****************************************************************************
*   File: rtmp_pool.c                                                       *
*                                                                           *
*       Copyright 1994 by Loral Advanced Distributed Simulation, Inc.       *
*                                                                           *
*               Loral Advanced Distributed Simulation, Inc.                 *
*               10 Moulton Street                                           *
*               Cambridge, MA 02238                                         *
*               617-873-1850                                                *
*                                                                           *
*       This software was developed by Loral under U. S. Government contracts*
*       and may be reproduced by or for the U. S. Government pursuant to    *
*       the copyright license under the clause at DFARS 252.227-7013        *
*       (OCT 1988).                                                         *
*                                                                           *
*       Contents: Maintains a pool of plan steps                            *
*       Created: Wed Aug  3 1994                                            *
*       Author: jesmith                                                     *
*       Remarks:                                                            *
*                                                                           *
****************************************************************************/

#include "librtmp_local.h"
#include <stdalloc.h>
#include <stdext.h>

static ROUTEMAP_PLAN_STEP *step_pool = NULL;

/* Counter for debugging */
static int32 outstanding_steps = 0;

/* Allocate a new step from memory or the pool */
ROUTEMAP_PLAN_STEP *routemap_new_step()
{
    ROUTEMAP_PLAN_STEP *step;

    outstanding_steps++;

    if (step_pool)
    {
	step = step_pool;
	step_pool = step_pool->next;
    }
    else
    {
	step = (ROUTEMAP_PLAN_STEP *)STDALLOC(sizeof(ROUTEMAP_PLAN_STEP));
    }
    bzero(step, sizeof(ROUTEMAP_PLAN_STEP));
    return step;
}

/* Return a step to the pool */
void routemap_free_step(step)
    ROUTEMAP_PLAN_STEP *step;
{
    outstanding_steps--;

    step->is_free = TRUE;
    step->next = step_pool;
    step_pool = step;
}

/* Return a whole list of steps to the pool */
void routemap_free_steps(head)
    ROUTEMAP_PLAN_STEP *head;
{
    ROUTEMAP_PLAN_STEP *i;

    /* Find the end */
    for(i=head;i->next;i=i->next)
      outstanding_steps--;
    outstanding_steps--;
    i->next = step_pool;
    step_pool = head;
}

/* Check whether there is a leak */
void routemap_check_leaks()
{
    if (outstanding_steps)
      printf("ROUTEMAP IS LEAKING!  %d outstanding\n", outstanding_steps);
}
