1 // AUTOMATICALLY GENERATED -- DO NOT EDIT! -*- c++ -*-
7 // INTERFACE definition follows
10 #line 2 "template.cpp"
14 #line 5 "template.cpp"
20 friend class stack_t<T>;
22 // Dont change the layout !!, comp_and_swap2 expects
23 // version and _next next to each other, in that order
28 #line 46 "template.cpp"
35 // stack_top_t<T>::operator=(const stack_top_t& _copy){
36 // _version = _copy._version;
37 // _next = _copy._next;
43 stack_top_t(int version, T *next);
45 #line 67 "template.cpp"
48 #line 17 "template.cpp"
57 #line 72 "template.cpp"
66 #line 84 "template.cpp"
70 #line 103 "template.cpp"
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
82 #line 164 "template.cpp"
86 #line 172 "template.cpp"
91 #line 27 "template.cpp"
93 // atomic-manipulation functions
98 template <class I> bool compare_and_swap(I *ptr, I oldval, I newval);
100 #line 41 "template.cpp"
101 template <class I> bool test_and_set(I *l);
103 #line 180 "template.cpp"
104 template<class T> stack_t<T>*
107 #line 187 "template.cpp"
108 template <> stack_t<int>*
111 #line 195 "template.cpp"
112 template <> inline stack_t<bool>*
116 // IMPLEMENTATION of inline functions (and needed classes)
120 #line 192 "template.cpp"
124 template <> inline stack_t<bool>*
127 return new stack<bool>();
131 // IMPLEMENTATION of function templates
135 #line 26 "template.cpp"
138 // atomic-manipulation functions
143 template <class I> bool compare_and_swap(I *ptr, I oldval, I newval)
145 return compare_and_swap(reinterpret_cast<unsigned*>(ptr),
146 *reinterpret_cast<unsigned*>(&oldval),
147 *reinterpret_cast<unsigned*>(&newval));
150 #line 39 "template.cpp"
153 template <class I> bool test_and_set(I *l)
155 return test_and_set(reinterpret_cast<unsigned*>(l));
158 #line 45 "template.cpp"
166 // stack_top_t<T>::operator=(const stack_top_t& _copy){
167 // _version = _copy._version;
168 // _next = _copy._next;
174 template<class T> stack_top_t<T>::stack_top_t(int version, T *next)
175 : _version (version),
179 #line 64 "template.cpp"
183 template<class T> stack_top_t<T>::stack_top_t()
188 #line 71 "template.cpp"
196 template<class T> stack_t<T>::stack_t()
200 #line 81 "template.cpp"
204 template<class T> int
205 stack_t<T>::insert(T *e)
207 stack_top_t<T> old_head,
211 e->set_next(_head._next);
213 new_head._version = _head._version+1;
215 } while (! compare_and_swap2((int *) &_head,
218 return new_head._version;
221 #line 100 "template.cpp"
226 stack_t<T>::dequeue()
228 stack_top_t<T> old_head,
241 new_head._next = first->get_next();
242 new_head._version = _head._version + 1;
243 } while (! compare_and_swap2((int *) &_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.
250 // return old_head._next;
254 #line 131 "template.cpp"
256 // This version of dequeue only returns a value
257 // if it is equal to the one passed as top
261 stack_t<T>::dequeue(T *top)
263 stack_top_t<T> old_head,
265 // stack_elem_t *first;
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
272 new_head._version = _head._version + 1;
273 new_head._next = top->get_next();
276 if(! compare_and_swap2((int *) &_head,
282 // top was on top , so we dequeued it
286 #line 161 "template.cpp"
296 #line 169 "template.cpp"
300 template<class T> void
307 #line 178 "template.cpp"
310 template<class T> stack_t<T>*
313 return new stack_t<T>();