Mercurial > pub > ImplabNet
comparison Implab/Parallels/MTQueue.cs @ 80:4f20870d0816 v2
added memory barriers
author | cin |
---|---|
date | Fri, 26 Sep 2014 03:32:34 +0400 |
parents | 1714fd8678ef |
children | dc4942d09e74 |
comparison
equal
deleted
inserted
replaced
79:05e6468f066f | 80:4f20870d0816 |
---|---|
16 | 16 |
17 Node m_first; | 17 Node m_first; |
18 Node m_last; | 18 Node m_last; |
19 | 19 |
20 public void Enqueue(T value) { | 20 public void Enqueue(T value) { |
21 Thread.MemoryBarrier(); | |
22 | |
21 var last = m_last; | 23 var last = m_last; |
22 var next = new Node(value); | 24 var next = new Node(value); |
23 | 25 |
24 while (last != Interlocked.CompareExchange(ref m_last, next, last)) | 26 while (last != Interlocked.CompareExchange(ref m_last, next, last)) |
25 last = m_last; | 27 last = m_last; |
33 public bool TryDequeue(out T value) { | 35 public bool TryDequeue(out T value) { |
34 Node first; | 36 Node first; |
35 Node next = null; | 37 Node next = null; |
36 value = default(T); | 38 value = default(T); |
37 | 39 |
40 Thread.MemoryBarrier(); | |
38 do { | 41 do { |
39 first = m_first; | 42 first = m_first; |
40 if (first == null) | 43 if (first == null) |
41 return false; | 44 return false; |
42 next = first.next; | 45 next = first.next; |