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 <> stack_t<bool>*
116 // IMPLEMENTATION of function templates
120 #line 26 "template.cpp"
123 // atomic-manipulation functions
128 template <class I> bool compare_and_swap(I *ptr, I oldval, I newval)
130 return compare_and_swap(reinterpret_cast<unsigned*>(ptr),
131 *reinterpret_cast<unsigned*>(&oldval),
132 *reinterpret_cast<unsigned*>(&newval));
135 #line 39 "template.cpp"
138 template <class I> bool test_and_set(I *l)
140 return test_and_set(reinterpret_cast<unsigned*>(l));
143 #line 45 "template.cpp"
151 // stack_top_t<T>::operator=(const stack_top_t& _copy){
152 // _version = _copy._version;
153 // _next = _copy._next;
159 template<class T> stack_top_t<T>::stack_top_t(int version, T *next)
160 : _version (version),
164 #line 64 "template.cpp"
168 template<class T> stack_top_t<T>::stack_top_t()
173 #line 71 "template.cpp"
181 template<class T> stack_t<T>::stack_t()
185 #line 81 "template.cpp"
189 template<class T> int
190 stack_t<T>::insert(T *e)
192 stack_top_t<T> old_head,
196 e->set_next(_head._next);
198 new_head._version = _head._version+1;
200 } while (! compare_and_swap2((int *) &_head,
203 return new_head._version;
206 #line 100 "template.cpp"
211 stack_t<T>::dequeue()
213 stack_top_t<T> old_head,
226 new_head._next = first->get_next();
227 new_head._version = _head._version + 1;
228 } while (! compare_and_swap2((int *) &_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.
235 // return old_head._next;
239 #line 131 "template.cpp"
241 // This version of dequeue only returns a value
242 // if it is equal to the one passed as top
246 stack_t<T>::dequeue(T *top)
248 stack_top_t<T> old_head,
250 // stack_elem_t *first;
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
257 new_head._version = _head._version + 1;
258 new_head._next = top->get_next();
261 if(! compare_and_swap2((int *) &_head,
267 // top was on top , so we dequeued it
271 #line 161 "template.cpp"
281 #line 169 "template.cpp"
285 template<class T> void
292 #line 178 "template.cpp"
295 template<class T> stack_t<T>*
298 return new stack_t<T>();