]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/tool/preprocess/test/verify/template_inline.h
update
[l4.git] / kernel / fiasco / tool / preprocess / test / verify / template_inline.h
1 // AUTOMATICALLY GENERATED -- DO NOT EDIT!         -*- c++ -*-
2
3 #ifndef template_inline_h
4 #define template_inline_h
5
6 //
7 // INTERFACE definition follows 
8 //
9
10 #line 2 "template.cpp"
11
12 template<class T>
13 class stack_t;
14 #line 5 "template.cpp"
15
16 template<class T>
17 class stack_top_t
18 {
19 private:
20   friend class stack_t<T>;
21
22   // Dont change the layout !!, comp_and_swap2 expects
23   // version and _next  next to each other, in that order
24   int _version;
25   T   *_next;
26
27 public:  
28 #line 46 "template.cpp"
29   // 
30   // stack_top_t
31   // 
32   
33   // template<class T>
34   // stack_top_t<T> &
35   // stack_top_t<T>::operator=(const stack_top_t& _copy){
36   //   _version = _copy._version;
37   //   _next    = _copy._next;
38   //   return *this;
39   // }
40   
41   
42   
43   inline stack_top_t(int version, T *next);
44   
45 #line 67 "template.cpp"
46   inline stack_top_t();
47 };
48 #line 17 "template.cpp"
49
50 template<class T>
51 class stack_t
52 {
53 private:
54   stack_top_t<T> _head;
55
56 public:  
57 #line 72 "template.cpp"
58   // 
59   // stack_t
60   // 
61   
62   
63   
64   stack_t();
65   
66 #line 84 "template.cpp"
67   int 
68   insert(T *e);
69   
70 #line 103 "template.cpp"
71   T* 
72   dequeue();
73   
74 #line 132 "template.cpp"
75   // This version of dequeue only returns a value
76   // if it is equal to the one passed as top
77   
78   
79   T* 
80   dequeue(T *top);
81   
82 #line 164 "template.cpp"
83   T* 
84   first();
85   
86 #line 172 "template.cpp"
87   void 
88   reset();
89 };
90
91 #line 27 "template.cpp"
92 // 
93 // atomic-manipulation functions
94 // 
95
96 // typesafe variants
97
98 template <class I> inline bool compare_and_swap(I *ptr, I oldval, I newval);
99
100 #line 41 "template.cpp"
101 template <class I> inline bool test_and_set(I *l);
102
103 #line 180 "template.cpp"
104 template<class T> stack_t<T>*
105 create_stack();
106
107 #line 187 "template.cpp"
108 template <> stack_t<int>*
109 create_stack();
110
111 #line 195 "template.cpp"
112 template <> inline stack_t<bool>*
113 create_stack();
114
115 //
116 // IMPLEMENTATION of inline functions (and needed classes)
117 //
118
119
120 #line 45 "template.cpp"
121
122 // 
123 // stack_top_t
124 // 
125
126 // template<class T>
127 // stack_top_t<T> &
128 // stack_top_t<T>::operator=(const stack_top_t& _copy){
129 //   _version = _copy._version;
130 //   _next    = _copy._next;
131 //   return *this;
132 // }
133
134
135
136 template<class T> inline stack_top_t<T>::stack_top_t(int version, T *next)
137   : _version (version),
138     _next (next)
139 {}
140
141 #line 64 "template.cpp"
142
143
144
145 template<class T> inline stack_top_t<T>::stack_top_t()
146   : _version (0),
147     _next (0)
148 {}
149
150 #line 26 "template.cpp"
151
152 // 
153 // atomic-manipulation functions
154 // 
155
156 // typesafe variants
157
158 template <class I> inline bool compare_and_swap(I *ptr, I oldval, I newval)
159 {
160   return compare_and_swap(reinterpret_cast<unsigned*>(ptr),
161                           *reinterpret_cast<unsigned*>(&oldval),
162                           *reinterpret_cast<unsigned*>(&newval));
163 }
164
165 #line 39 "template.cpp"
166
167
168 template <class I> inline bool test_and_set(I *l)
169 {
170   return test_and_set(reinterpret_cast<unsigned*>(l));
171 }
172
173 #line 192 "template.cpp"
174
175
176
177 template <> inline stack_t<bool>*
178 create_stack<bool>()
179 {
180   return new stack<bool>();
181 }
182
183 //
184 // IMPLEMENTATION of function templates
185 //
186
187
188 #line 71 "template.cpp"
189
190 // 
191 // stack_t
192 // 
193
194
195
196 template<class T> stack_t<T>::stack_t()
197   : _head (0, 0)
198 {}
199
200 #line 81 "template.cpp"
201
202
203
204 template<class T> int 
205 stack_t<T>::insert(T *e)
206 {
207   stack_top_t<T>  old_head,
208                   new_head;
209
210   do {
211       e->set_next(_head._next);
212       old_head             = _head;
213       new_head._version    = _head._version+1;
214       new_head._next       = e;
215   }  while (! compare_and_swap2((int *) &_head, 
216                                 (int *) &old_head,
217                                 (int *) &new_head));
218   return new_head._version;
219 }
220
221 #line 100 "template.cpp"
222
223
224
225 template<class T> T* 
226 stack_t<T>::dequeue()
227 {
228   stack_top_t<T> old_head,
229                  new_head;
230
231   T *first;
232
233   do {
234     old_head          = _head;
235
236     first = _head._next;
237     if(! first){
238       break;
239     }
240
241     new_head._next    = first->get_next();
242     new_head._version = _head._version + 1;
243   }  while (! compare_and_swap2((int *) &_head,
244                                 (int *) &old_head,
245                                 (int *) &new_head));
246   //  XXX Why did the old implementation test on e ?
247   //  while (e && ! compare_and_swap(&_first, e, e->list_property.next));
248   //  This is necessary to handle the case of a empty stack.
249
250   //  return old_head._next;
251   return first;
252 }
253
254 #line 131 "template.cpp"
255
256 // This version of dequeue only returns a value
257 // if it is equal to the one passed as top
258
259
260 template<class T> T* 
261 stack_t<T>::dequeue(T *top)
262 {
263   stack_top_t<T> old_head,
264                  new_head;
265   //  stack_elem_t  *first;
266
267   old_head._version  = _head._version;   // version doesnt matter
268   old_head._next     = top;              // cas will fail, if top aint at top
269   if(!_head._next){                      // empty stack
270     return 0;
271   }
272   new_head._version = _head._version + 1;
273   new_head._next    = top->get_next();
274   
275
276   if(! compare_and_swap2((int *) &_head,
277                          (int *) &old_head,
278                          (int *) &new_head))
279     // we didnt succeed
280     return 0;
281   else 
282     // top was on top , so we dequeued it
283     return top;
284 }
285
286 #line 161 "template.cpp"
287
288
289
290 template<class T> T* 
291 stack_t<T>::first()
292 {
293   return _head._next;
294 }
295
296 #line 169 "template.cpp"
297
298
299
300 template<class T> void 
301 stack_t<T>::reset()
302 {
303   _head._version = 0;
304   _head._next    = 0;
305 }
306
307 #line 178 "template.cpp"
308
309
310 template<class T> stack_t<T>*
311 create_stack()
312 {
313   return new stack_t<T>();
314 }
315
316 #endif // template_inline_h