tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
reservation.h
Go to the documentation of this file.
1 /* =============================================================================
2  *
3  * reservation.h
4  * -- Representation of car, flight, and hotel relations
5  *
6  * =============================================================================
7  *
8  * Copyright (C) Stanford University, 2006. All Rights Reserved.
9  * Author: Chi Cao Minh
10  *
11  * =============================================================================
12  *
13  * For the license of bayes/sort.h and bayes/sort.c, please see the header
14  * of the files.
15  *
16  * ------------------------------------------------------------------------
17  *
18  * For the license of kmeans, please see kmeans/LICENSE.kmeans
19  *
20  * ------------------------------------------------------------------------
21  *
22  * For the license of ssca2, please see ssca2/COPYRIGHT
23  *
24  * ------------------------------------------------------------------------
25  *
26  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
27  * header of the files.
28  *
29  * ------------------------------------------------------------------------
30  *
31  * For the license of lib/rbtree.h and lib/rbtree.c, please see
32  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
33  *
34  * ------------------------------------------------------------------------
35  *
36  * Unless otherwise noted, the following license applies to STAMP files:
37  *
38  * Copyright (c) 2007, Stanford University
39  * All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions are
43  * met:
44  *
45  * * Redistributions of source code must retain the above copyright
46  * notice, this list of conditions and the following disclaimer.
47  *
48  * * Redistributions in binary form must reproduce the above copyright
49  * notice, this list of conditions and the following disclaimer in
50  * the documentation and/or other materials provided with the
51  * distribution.
52  *
53  * * Neither the name of Stanford University nor the names of its
54  * contributors may be used to endorse or promote products derived
55  * from this software without specific prior written permission.
56  *
57  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
58  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
61  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
62  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
64  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
65  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
66  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
67  * THE POSSIBILITY OF SUCH DAMAGE.
68  *
69  * =============================================================================
70  */
71 
72 
73 #ifndef RESERVATION_H
74 #define RESERVATION_H 1
75 
76 
77 #include "tm.h"
78 #include "types.h"
79 
80 typedef enum reservation_type {
86 
87 typedef struct reservation_info {
89  long id;
90  long price; /* holds price at time reservation was made */
92 
93 typedef struct reservation {
94  long id;
95  long numUsed;
96  long numFree;
97  long numTotal;
98  long price;
100 
101 
102 /* =============================================================================
103  * reservation_info_alloc
104  * -- Returns NULL on failure
105  * =============================================================================
106  */
109 reservation_info_alloc (TM_ARGDECL reservation_type_t type, long id, long price);
110 
111 
112 /* =============================================================================
113  * reservation_info_free
114  * =============================================================================
115  */
117 void
119 
120 
121 /* =============================================================================
122  * reservation_info_compare
123  * -- Returns -1 if A < B, 0 if A = B, 1 if A > B
124  *
125  * [RSTM] this is tagged as TM_CALLABLE to make sure that there's a
126  * transactional clone available when we're not waivering the
127  * comparison.
128  * =============================================================================
129  */
131 long
133 
134 
135 /* =============================================================================
136  * reservation_alloc
137  * -- Returns NULL on failure
138  * =============================================================================
139  */
142 reservation_alloc (TM_ARGDECL long id, long price, long numTotal);
143 
145 reservation_alloc_seq (long id, long price, long numTotal);
146 
147 
148 /* =============================================================================
149  * reservation_addToTotal
150  * -- Adds if 'num' > 0, removes if 'num' < 0;
151  * -- Returns TRUE on success, else FALSE
152  * =============================================================================
153  */
155 bool_t
156 reservation_addToTotal (TM_ARGDECL reservation_t* reservationPtr, long num);
157 
158 bool_t
159 reservation_addToTotal_seq (reservation_t* reservationPtr, long num);
160 
161 
162 /* =============================================================================
163  * reservation_make
164  * -- Returns TRUE on success, else FALSE
165  * =============================================================================
166  */
168 bool_t
169 reservation_make (TM_ARGDECL reservation_t* reservationPtr);
170 
171 bool_t
172 reservation_make_seq (reservation_t* reservationPtr);
173 
174 
175 /* =============================================================================
176  * reservation_cancel
177  * -- Returns TRUE on success, else FALSE
178  * =============================================================================
179  */
181 bool_t
183 
184 bool_t
185 reservation_cancel_seq (reservation_t* reservationPtr);
186 
187 
188 /* =============================================================================
189  * reservation_updatePrice
190  * -- Failure if 'price' < 0
191  * -- Returns TRUE on success, else FALSE
192  * =============================================================================
193  */
195 bool_t
196 reservation_updatePrice (TM_ARGDECL reservation_t* reservationPtr, long newPrice);
197 
198 bool_t
199 reservation_updatePrice_seq (reservation_t* reservationPtr, long newPrice);
200 
201 
202 /* =============================================================================
203  * reservation_compare
204  * -- Returns -1 if A < B, 0 if A = B, 1 if A > B
205  * =============================================================================
206  */
207 long
209 
210 
211 /* =============================================================================
212  * reservation_hash
213  * =============================================================================
214  */
215 ulong_t
216 reservation_hash (reservation_t* reservationPtr);
217 
218 
219 /* =============================================================================
220  * reservation_free
221  * =============================================================================
222  */
224 void
225 reservation_free (TM_ARGDECL reservation_t* reservationPtr);
226 
227 
228 #define RESERVATION_INFO_ALLOC(type, id, price) \
229  reservation_info_alloc(TM_ARG type, id, price)
230 #define RESERVATION_INFO_FREE(r) \
231  reservation_info_free(TM_ARG r)
232 
233 #define RESERVATION_ALLOC(id, price, tot) \
234  reservation_alloc(TM_ARG id, price, tot)
235 #define RESERVATION_ADD_TO_TOTAL(r, num) \
236  reservation_addToTotal(TM_ARG r, num)
237 #define RESERVATION_MAKE(r) \
238  reservation_make(TM_ARG r)
239 #define RESERVATION_CANCEL(r) \
240  reservation_cancel(TM_ARG r)
241 #define RESERVATION_UPDATE_PRICE(r, price) \
242  reservation_updatePrice(TM_ARG r, price)
243 #define RESERVATION_FREE(r) \
244  reservation_free(TM_ARG r)
245 
246 
247 #endif /* RESERVATION_H */
248 
249 
250 /* =============================================================================
251  *
252  * End of reservation.h
253  *
254  * =============================================================================
255  */
long reservation_compare(reservation_t *aPtr, reservation_t *bPtr)
Definition: reservation.c:390
reservation_t * reservation_alloc_seq(long id, long price, long numTotal)
Definition: reservation.c:210
#define TM_CALLABLE
Definition: cxxtm.hpp:32
TM_CALLABLE reservation_info_t * reservation_info_alloc(TM_ARGDECL reservation_type_t type, long id, long price)
Definition: reservation.c:94
bool_t reservation_cancel_seq(reservation_t *reservationPtr)
Definition: reservation.c:333
TM_CALLABLE bool_t reservation_make(TM_ARGDECL reservation_t *reservationPtr)
Definition: reservation.c:275
TM_CALLABLE bool_t reservation_updatePrice(TM_ARGDECL reservation_t *reservationPtr, long newPrice)
Definition: reservation.c:355
TM_CALLABLE long reservation_info_compare(reservation_info_t *aPtr, reservation_info_t *bPtr)
Definition: reservation.c:126
long id
Definition: reservation.h:94
unsigned long ulong_t
Definition: types.h:88
struct reservation reservation_t
bool_t reservation_updatePrice_seq(reservation_t *reservationPtr, long newPrice)
Definition: reservation.c:370
struct reservation_info reservation_info_t
TM_CALLABLE bool_t reservation_addToTotal(TM_ARGDECL reservation_t *reservationPtr, long num)
Definition: reservation.c:235
long price
Definition: reservation.h:98
Definition: reservation.h:93
int bool_t
Definition: portable_defns.h:32
#define TM_ARGDECL
Definition: tm.h:532
TM_CALLABLE void reservation_free(TM_ARGDECL reservation_t *reservationPtr)
Definition: reservation.c:413
bool_t reservation_addToTotal_seq(reservation_t *reservationPtr, long num)
Definition: reservation.c:254
enum reservation_type reservation_type_t
TM_CALLABLE bool_t reservation_cancel(TM_ARGDECL reservation_t *reservationPtr)
Definition: reservation.c:314
Definition: reservation.h:81
bool_t reservation_make_seq(reservation_t *reservationPtr)
Definition: reservation.c:293
long numTotal
Definition: reservation.h:97
long id
Definition: reservation.h:89
ulong_t reservation_hash(reservation_t *reservationPtr)
Definition: reservation.c:401
TM_CALLABLE void reservation_info_free(TM_ARGDECL reservation_info_t *reservationInfoPtr)
Definition: reservation.c:114
long price
Definition: reservation.h:90
long numFree
Definition: reservation.h:96
long numUsed
Definition: reservation.h:95
reservation_type_t type
Definition: reservation.h:88
TM_CALLABLE reservation_t * reservation_alloc(TM_ARGDECL long id, long price, long numTotal)
Definition: reservation.c:191
reservation_type
Definition: reservation.h:80
Definition: reservation.h:83
Definition: reservation.h:87
Definition: reservation.h:84
Definition: reservation.h:82