]> rtime.felk.cvut.cz Git - l4.git/blob - tools/preprocess/test/verify/template.h
320fceb28490163d748b93bb37ad13a12f476b4a
[l4.git] / tools / 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 <> stack_t<bool>*
113 create_stack();
114
115 //
116 // IMPLEMENTATION of function templates
117 //
118
119
120 #line 26 "template.cpp"
121
122 // 
123 // atomic-manipulation functions
124 // 
125
126 // typesafe variants
127
128 template <class I> bool compare_and_swap(I *ptr, I oldval, I newval)
129 {
130   return compare_and_swap(reinterpret_cast<unsigned*>(ptr),
131                           *reinterpret_cast<unsigned*>(&oldval),
132                           *reinterpret_cast<unsigned*>(&newval));
133 }
134
135 #line 39 "template.cpp"
136
137
138 template <class I> bool test_and_set(I *l)
139 {
140   return test_and_set(reinterpret_cast<unsigned*>(l));
141 }
142
143 #line 45 "template.cpp"
144
145 // 
146 // stack_top_t
147 // 
148
149 // template<class T>
150 // stack_top_t<T> &
151 // stack_top_t<T>::operator=(const stack_top_t& _copy){
152 //   _version = _copy._version;
153 //   _next    = _copy._next;
154 //   return *this;
155 // }
156
157
158
159 template<class T> stack_top_t<T>::stack_top_t(int version, T *next)
160   : _version (version),
161     _next (next)
162 {}
163
164 #line 64 "template.cpp"
165
166
167
168 template<class T> stack_top_t<T>::stack_top_t()
169   : _version (0),
170     _next (0)
171 {}
172
173 #line 71 "template.cpp"
174
175 // 
176 // stack_t
177 // 
178
179
180
181 template<class T> stack_t<T>::stack_t()
182   : _head (0, 0)
183 {}
184
185 #line 81 "template.cpp"
186
187
188
189 template<class T> int 
190 stack_t<T>::insert(T *e)
191 {
192   stack_top_t<T>  old_head,
193                   new_head;
194
195   do {
196       e->set_next(_head._next);
197       old_head             = _head;
198       new_head._version    = _head._version+1;
199       new_head._next       = e;
200   }  while (! compare_and_swap2((int *) &_head, 
201                                 (int *) &old_head,
202                                 (int *) &new_head));
203   return new_head._version;
204 }
205
206 #line 100 "template.cpp"
207
208
209
210 template<class T> T* 
211 stack_t<T>::dequeue()
212 {
213   stack_top_t<T> old_head,
214                  new_head;
215
216   T *first;
217
218   do {
219     old_head          = _head;
220
221     first = _head._next;
222     if(! first){
223       break;
224     }
225
226     new_head._next    = first->get_next();
227     new_head._version = _head._version + 1;
228   }  while (! compare_and_swap2((int *) &_head,
229                                 (int *) &old_head,
230                                 (int *) &new_head));
231   //  XXX Why did the old implementation test on e ?
232   //  while (e && ! compare_and_swap(&_first, e, e->list_property.next));
233   //  This is necessary to handle the case of a empty stack.
234
235   //  return old_head._next;
236   return first;
237 }
238
239 #line 131 "template.cpp"
240
241 // This version of dequeue only returns a value
242 // if it is equal to the one passed as top
243
244
245 template<class T> T* 
246 stack_t<T>::dequeue(T *top)
247 {
248   stack_top_t<T> old_head,
249                  new_head;
250   //  stack_elem_t  *first;
251
252   old_head._version  = _head._version;   // version doesnt matter
253   old_head._next     = top;              // cas will fail, if top aint at top
254   if(!_head._next){                      // empty stack
255     return 0;
256   }
257   new_head._version = _head._version + 1;
258   new_head._next    = top->get_next();
259   
260
261   if(! compare_and_swap2((int *) &_head,
262                          (int *) &old_head,
263                          (int *) &new_head))
264     // we didnt succeed
265     return 0;
266   else 
267     // top was on top , so we dequeued it
268     return top;
269 }
270
271 #line 161 "template.cpp"
272
273
274
275 template<class T> T* 
276 stack_t<T>::first()
277 {
278   return _head._next;
279 }
280
281 #line 169 "template.cpp"
282
283
284
285 template<class T> void 
286 stack_t<T>::reset()
287 {
288   _head._version = 0;
289   _head._next    = 0;
290 }
291
292 #line 178 "template.cpp"
293
294
295 template<class T> stack_t<T>*
296 create_stack()
297 {
298   return new stack_t<T>();
299 }
300
301 #endif // template_h