comparison Implab/AbstractEvent.cs @ 233:d6fe09f5592c v2

Improved AsyncQueue Removed ImplabFx
author cin
date Wed, 04 Oct 2017 15:44:47 +0300
parents 75103928da09
children fa6cbf4d8841
comparison
equal deleted inserted replaced
229:5f7a3e1d32b9 233:d6fe09f5592c
22 Exception m_error; 22 Exception m_error;
23 int m_handlersCount; 23 int m_handlersCount;
24 24
25 //readonly THandler[] m_handlers = new THandler[RESERVED_HANDLERS_COUNT]; 25 //readonly THandler[] m_handlers = new THandler[RESERVED_HANDLERS_COUNT];
26 THandler[] m_handlers; 26 THandler[] m_handlers;
27 MTQueue<THandler> m_extraHandlers; 27 SimpleAsyncQueue<THandler> m_extraHandlers;
28 int m_handlerPointer = -1; 28 int m_handlerPointer = -1;
29 int m_handlersCommited; 29 int m_handlersCommited;
30 30
31 int m_cancelRequest; 31 int m_cancelRequest;
32 Exception m_cancelationReason; 32 Exception m_cancelationReason;
33 MTQueue<Action<Exception>> m_cancelationHandlers; 33 SimpleAsyncQueue<Action<Exception>> m_cancelationHandlers;
34 34
35 35
36 #region state managment 36 #region state managment
37 bool BeginTransit() { 37 bool BeginTransit() {
38 return UNRESOLVED_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, UNRESOLVED_SATE); 38 return UNRESOLVED_SATE == Interlocked.CompareExchange(ref m_state, TRANSITIONAL_STATE, UNRESOLVED_SATE);
180 break; 180 break;
181 } while(true); 181 } while(true);
182 } 182 }
183 } else { 183 } else {
184 if (slot == RESERVED_HANDLERS_COUNT) { 184 if (slot == RESERVED_HANDLERS_COUNT) {
185 m_extraHandlers = new MTQueue<THandler>(); 185 m_extraHandlers = new SimpleAsyncQueue<THandler>();
186 } else { 186 } else {
187 while (m_extraHandlers == null) 187 while (m_extraHandlers == null)
188 Thread.MemoryBarrier(); 188 Thread.MemoryBarrier();
189 } 189 }
190 190
243 Safe.ArgumentNotNull(handler, "handler"); 243 Safe.ArgumentNotNull(handler, "handler");
244 if (IsCancellationRequested) 244 if (IsCancellationRequested)
245 handler(CancellationReason); 245 handler(CancellationReason);
246 246
247 if (m_cancelationHandlers == null) 247 if (m_cancelationHandlers == null)
248 Interlocked.CompareExchange(ref m_cancelationHandlers, new MTQueue<Action<Exception>>(), null); 248 Interlocked.CompareExchange(ref m_cancelationHandlers, new SimpleAsyncQueue<Action<Exception>>(), null);
249 249
250 m_cancelationHandlers.Enqueue(handler); 250 m_cancelationHandlers.Enqueue(handler);
251 251
252 if (IsCancellationRequested && m_cancelationHandlers.TryDequeue(out handler)) 252 if (IsCancellationRequested && m_cancelationHandlers.TryDequeue(out handler))
253 // TryDeque implies MemoryBarrier() 253 // TryDeque implies MemoryBarrier()