]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/tool/preprocess/test/verify/template.h
Some minor fixes.
[l4.git] / kernel / fiasco / tool / preprocess / test / verify / template.h
1 // AUTOMATICALLY GENERATED -- DO NOT EDIT!         -*- c++ -*-
2
3 #ifndef template_h
4 #define template_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   stack_top_t (int version, T *next);
44   
45 #line 67 "template.cpp"
46   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> bool compare_and_swap(I *ptr, I oldval, I newval);
99
100 #line 41 "template.cpp"
101 template <class I> 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 #line 238 "template.cpp"
116 template<typename FOO,
117          typename = typename cxx::enable_if<!cxx::is_same<SPACE, Mem_space>::value>::type> void
118 template_with_dfl_arg1();
119
120 #line 244 "template.cpp"
121 template<typename FOO,
122          typename = typename cxx::enable_if<!cxx::is_same<SPACE, Mem_space>::value>::type,
123          typename BAR> void
124 template_with_dfl_arg2();
125
126 //
127 // IMPLEMENTATION of inline functions (and needed classes)
128 //
129
130
131 #line 192 "template.cpp"
132
133
134
135 template <> inline stack_t<bool>*
136 create_stack<bool>()
137 {
138   return new stack<bool>();
139 }
140
141 //
142 // IMPLEMENTATION of function templates
143 //
144
145
146 #line 26 "template.cpp"
147
148 // 
149 // atomic-manipulation functions
150 // 
151
152 // typesafe variants
153
154 template <class I> bool compare_and_swap(I *ptr, I oldval, I newval)
155 {
156   return compare_and_swap(reinterpret_cast<unsigned*>(ptr),
157                           *reinterpret_cast<unsigned*>(&oldval),
158                           *reinterpret_cast<unsigned*>(&newval));
159 }
160
161 #line 39 "template.cpp"
162
163
164 template <class I> bool test_and_set(I *l)
165 {
166   return test_and_set(reinterpret_cast<unsigned*>(l));
167 }
168
169 #line 45 "template.cpp"
170
171 // 
172 // stack_top_t
173 // 
174
175 // template<class T>
176 // stack_top_t<T> &
177 // stack_top_t<T>::operator=(const stack_top_t& _copy){
178 //   _version = _copy._version;
179 //   _next    = _copy._next;
180 //   return *this;
181 // }
182
183
184
185 template<class T> stack_top_t<T>::stack_top_t (int version, T *next)
186   : _version (version),
187     _next (next)
188 {}
189
190 #line 64 "template.cpp"
191
192
193
194 template<class T> stack_top_t<T>::stack_top_t ()
195   : _version (0),
196     _next (0)
197 {}
198
199 #line 71 "template.cpp"
200
201 // 
202 // stack_t
203 // 
204
205
206
207 template<class T> stack_t<T>::stack_t()
208   : _head (0, 0)
209 {}
210
211 #line 81 "template.cpp"
212
213
214
215 template<class T> int 
216 stack_t<T>::insert(T *e)
217 {
218   stack_top_t<T>  old_head,
219                   new_head;
220
221   do {
222       e->set_next(_head._next);
223       old_head             = _head;
224       new_head._version    = _head._version+1;
225       new_head._next       = e;
226   }  while (! compare_and_swap2((int *) &_head, 
227                                 (int *) &old_head,
228                                 (int *) &new_head));
229   return new_head._version;
230 }
231
232 #line 100 "template.cpp"
233
234
235
236 template<class T> T* 
237 stack_t<T>::dequeue()
238 {
239   stack_top_t<T> old_head,
240                  new_head;
241
242   T *first;
243
244   do {
245     old_head          = _head;
246
247     first = _head._next;
248     if(! first){
249       break;
250     }
251
252     new_head._next    = first->get_next();
253     new_head._version = _head._version + 1;
254   }  while (! compare_and_swap2((int *) &_head,
255                                 (int *) &old_head,
256                                 (int *) &new_head));
257   //  XXX Why did the old implementation test on e ?
258   //  while (e && ! compare_and_swap(&_first, e, e->list_property.next));
259   //  This is necessary to handle the case of a empty stack.
260
261   //  return old_head._next;
262   return first;
263 }
264
265 #line 131 "template.cpp"
266
267 // This version of dequeue only returns a value
268 // if it is equal to the one passed as top
269
270
271 template<class T> T* 
272 stack_t<T>::dequeue(T *top)
273 {
274   stack_top_t<T> old_head,
275                  new_head;
276   //  stack_elem_t  *first;
277
278   old_head._version  = _head._version;   // version doesnt matter
279   old_head._next     = top;              // cas will fail, if top aint at top
280   if(!_head._next){                      // empty stack
281     return 0;
282   }
283   new_head._version = _head._version + 1;
284   new_head._next    = top->get_next();
285   
286
287   if(! compare_and_swap2((int *) &_head,
288                          (int *) &old_head,
289                          (int *) &new_head))
290     // we didnt succeed
291     return 0;
292   else 
293     // top was on top , so we dequeued it
294     return top;
295 }
296
297 #line 161 "template.cpp"
298
299
300
301 template<class T> T* 
302 stack_t<T>::first()
303 {
304   return _head._next;
305 }
306
307 #line 169 "template.cpp"
308
309
310
311 template<class T> void 
312 stack_t<T>::reset()
313 {
314   _head._version = 0;
315   _head._next    = 0;
316 }
317
318 #line 178 "template.cpp"
319
320
321 template<class T> stack_t<T>*
322 create_stack()
323 {
324   return new stack_t<T>();
325 }
326
327 #line 236 "template.cpp"
328
329
330 template<typename FOO,
331          typename> void
332 template_with_dfl_arg1()
333 {}
334
335 #line 242 "template.cpp"
336
337
338 template<typename FOO,
339          typename,
340          typename BAR> void
341 template_with_dfl_arg2()
342 {}
343
344 #endif // template_h