comparison Implab/Parallels/MTQueue.cs @ 19:e3935fdf59a2 promises

Promise is rewritten to use interlocked operations instead of locks
author cin
date Sun, 10 Nov 2013 00:21:33 +0400
parents e943453e5039
children ee04e1fa78da
comparison
equal deleted inserted replaced
17:7cd4a843b4e4 19:e3935fdf59a2
40 if (first == null) 40 if (first == null)
41 return false; 41 return false;
42 next = first.next; 42 next = first.next;
43 if (next == null) { 43 if (next == null) {
44 // this is the last element, 44 // this is the last element,
45 // then try to update tail 45 // then try to update the tail
46 if (first != Interlocked.CompareExchange(ref m_last, null, first)) { 46 if (first != Interlocked.CompareExchange(ref m_last, null, first)) {
47 // this is inconsistent situation which means that the queue is empty 47 // this is a ace condition
48 if (m_last == null) 48 if (m_last == null)
49 // the queue is empty
49 return false; 50 return false;
50 // tail has been changed, that means that we need to restart 51 // tail has been changed, than we need to restart
51 continue; 52 continue;
52 } 53 }
53 54
54 // tail succesfully updated and first.next will never be changed 55 // tail succesfully updated and first.next will never be changed
55 // other readers will fail due to inconsistency m_last != m_fist, but m_first.next == null 56 // other readers will fail due to inconsistency m_last != m_fist, but m_first.next == null