3535
3636use std:: cast;
3737use std:: sync:: atomics;
38+ use std:: ty:: Unsafe ;
3839
3940// NB: all links are done as AtomicUint instead of AtomicPtr to allow for static
4041// initialization.
@@ -50,22 +51,22 @@ pub struct DummyNode {
5051
5152pub struct Queue < T > {
5253 head : atomics:: AtomicUint ,
53- tail : * mut Node < T > ,
54+ tail : Unsafe < * mut Node < T > > ,
5455 stub : DummyNode ,
5556}
5657
5758impl < T : Send > Queue < T > {
5859 pub fn new ( ) -> Queue < T > {
5960 Queue {
6061 head : atomics:: AtomicUint :: new ( 0 ) ,
61- tail : 0 as * mut Node < T > ,
62+ tail : Unsafe :: new ( 0 as * mut Node < T > ) ,
6263 stub : DummyNode {
6364 next : atomics:: AtomicUint :: new ( 0 ) ,
6465 } ,
6566 }
6667 }
6768
68- pub unsafe fn push ( & mut self , node : * mut Node < T > ) {
69+ pub unsafe fn push ( & self , node : * mut Node < T > ) {
6970 ( * node) . next . store ( 0 , atomics:: Release ) ;
7071 let prev = self . head . swap ( node as uint , atomics:: AcqRel ) ;
7172
@@ -93,8 +94,8 @@ impl<T: Send> Queue<T> {
9394 /// Right now consumers of this queue must be ready for this fact. Just
9495 /// because `pop` returns `None` does not mean that there is not data
9596 /// on the queue.
96- pub unsafe fn pop ( & mut self ) -> Option < * mut Node < T > > {
97- let tail = self . tail ;
97+ pub unsafe fn pop ( & self ) -> Option < * mut Node < T > > {
98+ let tail = * self . tail . get ( ) ;
9899 let mut tail = if !tail. is_null ( ) { tail} else {
99100 cast:: transmute ( & self . stub )
100101 } ;
@@ -103,12 +104,12 @@ impl<T: Send> Queue<T> {
103104 if next. is_null ( ) {
104105 return None ;
105106 }
106- self . tail = next;
107+ * self . tail . get ( ) = next;
107108 tail = next;
108109 next = ( * next) . next ( atomics:: Relaxed ) ;
109110 }
110111 if !next. is_null ( ) {
111- self . tail = next;
112+ * self . tail . get ( ) = next;
112113 return Some ( tail) ;
113114 }
114115 let head = self . head . load ( atomics:: Acquire ) as * mut Node < T > ;
@@ -119,7 +120,7 @@ impl<T: Send> Queue<T> {
119120 self . push ( stub) ;
120121 next = ( * tail) . next ( atomics:: Relaxed ) ;
121122 if !next. is_null ( ) {
122- self . tail = next;
123+ * self . tail . get ( ) = next;
123124 return Some ( tail) ;
124125 }
125126 return None
@@ -133,7 +134,7 @@ impl<T: Send> Node<T> {
133134 next : atomics:: AtomicUint :: new ( 0 ) ,
134135 }
135136 }
136- pub unsafe fn next ( & mut self , ord : atomics:: Ordering ) -> * mut Node < T > {
137+ pub unsafe fn next ( & self , ord : atomics:: Ordering ) -> * mut Node < T > {
137138 cast:: transmute :: < uint , * mut Node < T > > ( self . next . load ( ord) )
138139 }
139140}
0 commit comments