2
This software and ancillary information (herein called "SOFTWARE")
3
called Supermon is made available under the terms described
4
here. The SOFTWARE has been approved for release with associated
5
LA-CC Number LA-CC 99-51.
7
Unless otherwise indicated, this SOFTWARE has been authored by an
8
employee or employees of the University of California, operator of the
9
Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
10
the U.S. Department of Energy. The U.S. Government has rights to use,
11
reproduce, and distribute this SOFTWARE, and to allow others to do so.
12
The public may copy, distribute, prepare derivative works and publicly
13
display this SOFTWARE without charge, provided that this Notice and
14
any statement of authorship are reproduced on all copies. Neither the
15
Government nor the University makes any warranty, express or implied,
16
or assumes any liability or responsibility for the use of this
19
If SOFTWARE is modified to produce derivative works, such modified
20
SOFTWARE should be clearly marked, so as not to confuse it with the
21
version available from LANL.
23
/** NOTICE: This software is licensed under the GNU Public License, which
24
is included as LICENSE_GPL in this source distribution. **/
25
/** NOTE: This library is part of the supermon project, hence the name
31
* \brief Implementation of a fast stack with smart memory management.
33
* Author: Matt Sottile (matt@lanl.gov)
34
* See LICENSE for info on licensing.
36
#ifndef __FASTSTACK_H__
37
#define __FASTSTACK_H__
39
#ifdef _DEBUG_MALLOCS_
40
#include "malloc_util.h"
44
* Structure representing a single level in the stack. Has a pointer to the
45
* level above and below itself and a pointer to a generic blob of data
46
* associated with this level.
48
typedef struct stack_level {
50
* Pointer to the level above this one. If NULL, then this level is the
51
* top of the stack. If above is non-NULL, this level *may* be the top,
52
* but all that can be guaranteed is that there are other allocated
53
* but potentially unused levels above this one.
55
struct stack_level *above;
58
* Pointer to the level below this one. If NULL, then this level is the
61
struct stack_level *below;
64
* Pointer to some data associated with this level. User is responsible
65
* for knowing what to cast the \c void \c * pointer into.
71
* Wrapper around the stack levels - keeps a pointer to the current top and
72
* bottom of the stack and a count of the current height. This allows the top
73
* to have non-null above pointer resulting from previously allocated stack
74
* levels that may be recycled later without \c malloc overhead.
76
typedef struct stack_wrapper {
78
* The top of the stack. If this is NULL, the stack is empty.
83
* The bottom of the stack. If this is NULL, the stack is empty.
88
* The current height of the stack, in terms of allocated and used levels.
101
* Return a pointer to an empty stack structure.
103
faststack_t *make_stack();
106
* Given a stack structure, destroy it and free all of the stack levels.
107
* <B>Important note</B> : This function <I>does not</I> free the data
108
* pointed to from each level of the stack - the user is responsible
109
* for freeing this data themselves before calling this function to
110
* prevent memory leakage.
112
void destroy_stack(faststack_t *s);
115
* Given a stack, push a new level on referring to the data pointer.
117
faststack_t *push(faststack_t *cur_stack, void *data);
120
* Given a stack, pop a level off and return a pointer to that level.
121
* The user is responsible for extracting the data, but the stack_lvl_t
122
* structures pointed to from the level (above and below) should be left
125
stack_lvl_t *pop(faststack_t *s);
127
/* this is for C++ */
133
* Given a stack \a s, examine the data pointer at the top.
135
#define top_data(s) (s->top->data)
138
* Given a stack \a s, check to see if the stack is empty or not. Value
139
* is boolean true or false.
141
#define empty_stack(s) (s->top == NULL)
143
#endif /* __FASTSTACK_H__ */