2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Library General Public License for more details.
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the Free
16 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 #include "dbprim_int.h"
28 static link_head_t _smat_freelist = LINK_HEAD_INIT(0);
36 if (!ll_count(&_smat_freelist) || !(le = ll_first(&_smat_freelist)) ||
37 ll_remove(&_smat_freelist, le)) {
38 /* Must allocate a new element */
39 if (!(se = (smat_entry_t *)malloc(sizeof(smat_entry_t))))
40 return 0; /* couldn't allocate an entry... */
42 se = le_object(le); /* get smat entry object */
44 /* initialize a smat entry */
45 if (he_init(&se->se_hash, se) || le_init(&se->se_link[SMAT_LOC_FIRST], se) ||
46 le_init(&se->se_link[SMAT_LOC_SECOND], se)) {
47 free(se); /* initialization failed... */
51 se->se_table = 0; /* initialize the rest of the structure */
52 se->se_object[SMAT_LOC_FIRST] = 0;
53 se->se_object[SMAT_LOC_SECOND] = 0;
55 se->se_magic = SMAT_ENTRY_MAGIC; /* set up the magic number */
57 return se; /* return the object */
61 _smat_free(smat_entry_t *entry)
63 entry->se_magic = 0; /* clear magic number to prevent use */
65 /* Add the entry to the free list */
66 if (ll_add(&_smat_freelist, _se_link(entry), LINK_LOC_HEAD, 0))
67 free(entry); /* addition failed, so free the entry */
70 /** \ingroup dbprim_smat
71 * \brief Clean up the smat free list.
73 * This function frees all smat_entry_t objects on the internal free
74 * list. It is always successful and returns 0.
81 initialize_dbpr_error_table(); /* set up error tables */
83 /* walk the free list */
84 while ((entry = ll_first(&_smat_freelist))) {
85 ll_remove(&_smat_freelist, entry); /* remove entry */
86 free(le_object(entry)); /* free the element */
92 /** \ingroup dbprim_smat
93 * \brief Report how much memory is used by the free list.
95 * This function returns the amount of memory being used by the
96 * internal free list of smat_entry_t objects.
98 * \return A number indicating the size, in bytes, of the memory
99 * allocated for smat_entry_t objects on the free list.
104 initialize_dbpr_error_table(); /* set up error tables */
106 /* tell caller how much memory we're using */
107 return ll_count(&_smat_freelist) * sizeof(smat_entry_t);