storage.c

Go to the documentation of this file.
00001 /*                       S T O R A G E . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** @addtogroup librt */
00023 /*@{*/
00024 /** @file storage.c
00025  * Ray Tracing program, storage manager.
00026  *
00027  *  Functions -
00028  *      rt_get_seg      Invoked by GET_SEG() macro
00029  *
00030  *  Author -
00031  *      Michael John Muuss
00032  *
00033  *  Source -
00034  *      The U. S. Army Research Laboratory
00035  *      Aberdeen Proving Ground, Maryland  21005-5068  USA
00036  *
00037  */
00038 /*@}*/
00039 
00040 #ifndef lint
00041 static const char RCSstorage[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/storage.c,v 14.11 2006/09/16 02:04:26 lbutler Exp $ (ARL)";
00042 #endif
00043 
00044 #include "common.h"
00045 
00046 
00047 
00048 #include <stdio.h>
00049 #ifdef HAVE_STRING_H
00050 # include <string.h>
00051 #else
00052 # include <strings.h>
00053 #endif
00054 
00055 #include "machine.h"
00056 #include "vmath.h"
00057 #include "raytrace.h"
00058 #include "bu.h"
00059 #include "./debug.h"
00060 
00061 /*
00062  *                      R T _ G E T _ S E G
00063  *
00064  *  This routine is called by the GET_SEG macro when the freelist
00065  *  is exhausted.  Rather than simply getting one additional structure,
00066  *  we get a whole batch, saving overhead.  When this routine is called,
00067  *  the seg resource must already be locked.
00068  *  malloc() locking is done in bu_malloc.
00069  */
00070 void
00071 rt_get_seg(register struct resource *res)
00072 {
00073         register struct seg     *sp;
00074         register int            bytes;
00075 
00076         RT_CK_RESOURCE(res);
00077 
00078         if( BU_LIST_UNINITIALIZED( &res->re_seg ) )  {
00079                 BU_LIST_INIT( &(res->re_seg) );
00080                 bu_ptbl_init( &res->re_seg_blocks, 64, "re_seg_blocks ptbl" );
00081         }
00082         bytes = bu_malloc_len_roundup(64*sizeof(struct seg));
00083         sp = (struct seg *)bu_malloc(bytes, "rt_get_seg()");
00084         bu_ptbl_ins( &res->re_seg_blocks, (long *)sp );
00085         while( bytes >= sizeof(struct seg) )  {
00086                 sp->l.magic = RT_SEG_MAGIC;
00087                 BU_LIST_INSERT(&(res->re_seg), &(sp->l));
00088                 res->re_seglen++;
00089                 sp++;
00090                 bytes -= sizeof(struct seg);
00091         }
00092 }
00093 
00094 /*
00095  * Local Variables:
00096  * mode: C
00097  * tab-width: 8
00098  * c-basic-offset: 4
00099  * indent-tabs-mode: t
00100  * End:
00101  * ex: shiftwidth=4 tabstop=8
00102  */

Generated on Mon Sep 18 01:24:56 2006 for BRL-CAD by  doxygen 1.4.6