< prev index next >

src/hotspot/share/utilities/lockFreeStack.hpp

Print this page




  86     T* old;
  87     do {
  88       old = result;
  89       T* new_top = NULL;
  90       if (result != NULL) {
  91         new_top = next(*result);
  92       }
  93       // CAS even on empty pop, for consistent membar bahavior.
  94       result = Atomic::cmpxchg(new_top, &_top, result);
  95     } while (result != old);
  96     if (result != NULL) {
  97       set_next(*result, NULL);
  98     }
  99     return result;
 100   }
 101 
 102   // Atomically exchange the list of elements with NULL, returning the old
 103   // list of elements.  Acts as a full memory barrier.
 104   // postcondition: empty()
 105   T* pop_all() {
 106     return Atomic::xchg((T*)NULL, &_top);
 107   }
 108 
 109   // Atomically adds value to the top of this stack.  Acts as a full
 110   // memory barrier.
 111   void push(T& value) {
 112     assert(next(value) == NULL, "precondition");
 113     prepend_impl(&value, &value);
 114   }
 115 
 116   // Atomically adds the list of objects (designated by first and
 117   // last) before the objects already in this stack, in the same order
 118   // as in the list. Acts as a full memory barrier.
 119   // precondition: next(last) == NULL.
 120   // postcondition: top() == &first, next(last) == old top().
 121   void prepend(T& first, T& last) {
 122     assert(next(last) == NULL, "precondition");
 123 #ifdef ASSERT
 124     for (T* p = &first; p != &last; p = next(*p)) {
 125       assert(p != NULL, "invalid prepend list");
 126     }




  86     T* old;
  87     do {
  88       old = result;
  89       T* new_top = NULL;
  90       if (result != NULL) {
  91         new_top = next(*result);
  92       }
  93       // CAS even on empty pop, for consistent membar bahavior.
  94       result = Atomic::cmpxchg(new_top, &_top, result);
  95     } while (result != old);
  96     if (result != NULL) {
  97       set_next(*result, NULL);
  98     }
  99     return result;
 100   }
 101 
 102   // Atomically exchange the list of elements with NULL, returning the old
 103   // list of elements.  Acts as a full memory barrier.
 104   // postcondition: empty()
 105   T* pop_all() {
 106     return Atomic::xchg(&_top, (T*)NULL);
 107   }
 108 
 109   // Atomically adds value to the top of this stack.  Acts as a full
 110   // memory barrier.
 111   void push(T& value) {
 112     assert(next(value) == NULL, "precondition");
 113     prepend_impl(&value, &value);
 114   }
 115 
 116   // Atomically adds the list of objects (designated by first and
 117   // last) before the objects already in this stack, in the same order
 118   // as in the list. Acts as a full memory barrier.
 119   // precondition: next(last) == NULL.
 120   // postcondition: top() == &first, next(last) == old top().
 121   void prepend(T& first, T& last) {
 122     assert(next(last) == NULL, "precondition");
 123 #ifdef ASSERT
 124     for (T* p = &first; p != &last; p = next(*p)) {
 125       assert(p != NULL, "invalid prepend list");
 126     }


< prev index next >