1 /* $NetBSD: prop_stack.c,v 1.2 2007/08/30 12:23:54 joerg Exp $ */
4 * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include "prop_stack.h"
33 #include "prop_object_impl.h"
36 _prop_stack_init(prop_stack_t stack
)
38 stack
->used_intern_elems
= 0;
39 SLIST_INIT(&stack
->extern_elems
);
43 _prop_stack_push(prop_stack_t stack
, prop_object_t obj
, void *data1
,
44 void *data2
, void *data3
)
46 struct _prop_stack_extern_elem
*eelem
;
47 struct _prop_stack_intern_elem
*ielem
;
49 if (stack
->used_intern_elems
== PROP_STACK_INTERN_ELEMS
) {
50 eelem
= _PROP_MALLOC(sizeof(*eelem
), M_TEMP
);
56 eelem
->object_data
[0] = data1
;
57 eelem
->object_data
[1] = data2
;
58 eelem
->object_data
[2] = data3
;
60 SLIST_INSERT_HEAD(&stack
->extern_elems
, eelem
, stack_link
);
65 _PROP_ASSERT(stack
->used_intern_elems
< PROP_STACK_INTERN_ELEMS
);
66 _PROP_ASSERT(SLIST_EMPTY(&stack
->extern_elems
));
68 ielem
= &stack
->intern_elems
[stack
->used_intern_elems
];
70 ielem
->object_data
[0] = data1
;
71 ielem
->object_data
[1] = data2
;
72 ielem
->object_data
[2] = data3
;
74 ++stack
->used_intern_elems
;
80 _prop_stack_pop(prop_stack_t stack
, prop_object_t
*obj
, void **data1
,
81 void **data2
, void **data3
)
83 struct _prop_stack_extern_elem
*eelem
;
84 struct _prop_stack_intern_elem
*ielem
;
86 if (stack
->used_intern_elems
== 0)
89 if ((eelem
= SLIST_FIRST(&stack
->extern_elems
)) != NULL
) {
90 _PROP_ASSERT(stack
->used_intern_elems
== PROP_STACK_INTERN_ELEMS
);
92 SLIST_REMOVE_HEAD(&stack
->extern_elems
, stack_link
);
96 *data1
= eelem
->object_data
[0];
98 *data2
= eelem
->object_data
[1];
100 *data3
= eelem
->object_data
[2];
101 _PROP_FREE(eelem
, M_TEMP
);
105 --stack
->used_intern_elems
;
106 ielem
= &stack
->intern_elems
[stack
->used_intern_elems
];
109 *obj
= ielem
->object
;
111 *data1
= ielem
->object_data
[0];
113 *data2
= ielem
->object_data
[1];
115 *data3
= ielem
->object_data
[2];