annotate Implab/Parallels/AsyncQueue.cs @ 119:2573b562e328 v2

Promises rewritten, added improved version of AsyncQueue
author cin
date Sun, 11 Jan 2015 19:13:02 +0300
parents
children f1b897999260
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
1 using System.Threading;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
2 using System.Collections.Generic;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
3 using System;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
4 using System.Collections;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
5
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
6 namespace Implab.Parallels {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
7 public class AsyncQueue<T> : IEnumerable<T> {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
8 class Chunk {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
9 public Chunk next;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
10
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
11 int m_low;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
12 int m_hi;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
13 int m_alloc;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
14 readonly int m_size;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
15 readonly T[] m_data;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
16
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
17 public Chunk(int size) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
18 m_size = size;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
19 m_data = new T[size];
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
20 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
21
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
22 public Chunk(int size, T value) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
23 m_size = size;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
24 m_hi = 1;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
25 m_alloc = 1;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
26 m_data = new T[size];
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
27 m_data[0] = value;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
28 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
29
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
30 public int Low {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
31 get { return m_low; }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
32 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
33
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
34 public int Hi {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
35 get { return m_hi; }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
36 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
37
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
38 public bool TryEnqueue(T value,out bool extend) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
39 extend = false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
40 int alloc;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
41 do {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
42 alloc = m_alloc;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
43 if (alloc > m_size)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
44 return false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
45 } while(alloc != Interlocked.CompareExchange(ref m_alloc, alloc+1, alloc));
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
46
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
47 if (alloc == m_size) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
48 extend = true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
49 return false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
50 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
51
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
52 m_data[alloc] = value;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
53
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
54 while (alloc != Interlocked.CompareExchange(ref m_hi, alloc + 1, alloc)) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
55 // spin wait for commit
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
56 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
57 return true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
58 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
59
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
60 public bool TryDequeue(out T value,out bool recycle) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
61 int low;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
62 do {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
63 low = m_low;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
64 if (low >= m_hi) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
65 value = default(T);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
66 recycle = (low == m_size);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
67 return false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
68 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
69 } while(low != Interlocked.CompareExchange(ref m_low, low + 1, low));
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
70
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
71 recycle = (low == m_size - 1);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
72 value = m_data[low];
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
73
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
74 return true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
75 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
76
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
77 public T GetAt(int pos) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
78 return m_data[pos];
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
79 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
80 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
81
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
82 public const int DEFAULT_CHUNK_SIZE = 32;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
83
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
84 readonly int m_chunkSize = DEFAULT_CHUNK_SIZE;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
85
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
86 Chunk m_first;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
87 Chunk m_last;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
88
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
89 public AsyncQueue() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
90 m_last = m_first = new Chunk(m_chunkSize);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
91 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
92
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
93 public void Enqueue(T value) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
94 var last = m_last;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
95 // spin wait to the new chunk
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
96 bool extend = true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
97 while(last == null || !last.TryEnqueue(value, out extend)) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
98 // try to extend queue
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
99 if (extend || last == null) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
100 var chunk = new Chunk(m_chunkSize, value);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
101 if (EnqueueChunk(last, chunk))
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
102 break;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
103 last = m_last;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
104 } else {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
105 while (last != m_last) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
106 Thread.MemoryBarrier();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
107 last = m_last;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
108 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
109 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
110 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
111 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
112
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
113 public bool TryDequeue(out T value) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
114 var chunk = m_first;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
115 bool recycle;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
116 while (chunk != null) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
117
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
118 var result = chunk.TryDequeue(out value, out recycle);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
120 if (recycle) // this chunk is waste
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
121 RecycleFirstChunk(chunk);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
122 else
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
123 return result; // this chunk is usable and returned actual result
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
124
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
125 if (result) // this chunk is waste but the true result is always actual
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
126 return true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
127
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
128 // try again
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
129 chunk = m_first;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
130 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
131
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
132 // the queue is empty
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
133 value = default(T);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
134 return false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
135 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
136
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
137 bool EnqueueChunk(Chunk last, Chunk chunk) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
138 if (Interlocked.CompareExchange(ref m_last, chunk, last) != last)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
139 return false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
140
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
141 if (last != null)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
142 last.next = chunk;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
143 else
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
144 m_first = chunk;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
145 return true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
146 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
147
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
148 void RecycleFirstChunk(Chunk first) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
149 var next = first.next;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
150
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
151 if (next == null) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
152 // looks like this is the last chunk
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
153 if (first != Interlocked.CompareExchange(ref m_last, null, first)) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
154 // race
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
155 // maybe someone already recycled this chunk
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
156 // or a new chunk has been appedned to the queue
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
157
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
158 return; // give up
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
159 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
160 // the tail is updated
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
161 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
162
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
163 // we need to update the head
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
164 Interlocked.CompareExchange(ref m_first, next, first);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
165 // if the head is already updated then give up
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
166 return;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
167
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
168 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
169
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
170 #region IEnumerable implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
171
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
172 class Enumerator : IEnumerator<T> {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
173 Chunk m_current;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
174 int m_pos = -1;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
175
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
176 public Enumerator(Chunk fisrt) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
177 m_current = fisrt;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
178 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
179
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
180 #region IEnumerator implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
181
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
182 public bool MoveNext() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
183 if (m_current == null)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
184 return false;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
185
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
186 if (m_pos == -1)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
187 m_pos = m_current.Low;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
188 else
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
189 m_pos++;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
190 if (m_pos == m_current.Hi) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
191 m_pos = 0;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
192 m_current = m_current.next;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
193 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
194
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
195 return true;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
196 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
197
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
198 public void Reset() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
199 throw new NotSupportedException();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
200 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
201
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
202 object IEnumerator.Current {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
203 get {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
204 return Current;
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
205 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
206 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
207
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
208 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
209
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
210 #region IDisposable implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
211
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
212 public void Dispose() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
213 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
214
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
215 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
216
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
217 #region IEnumerator implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
218
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
219 public T Current {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
220 get {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
221 if (m_pos == -1 || m_current == null)
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
222 throw new InvalidOperationException();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
223 return m_current.GetAt(m_pos);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
224 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
225 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
226
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
227 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
228 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
229
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
230 public IEnumerator<T> GetEnumerator() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
231 return new Enumerator(m_first);
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
232 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
233
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
234 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
235
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
236 #region IEnumerable implementation
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
237
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
238 IEnumerator IEnumerable.GetEnumerator() {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
239 return GetEnumerator();
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
240 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
241
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
242 #endregion
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
243 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents:
diff changeset
244 }