aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/LocklessQueue.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/LocklessQueue.cs16
1 files changed, 9 insertions, 7 deletions
diff --git a/OpenSim/Framework/LocklessQueue.cs b/OpenSim/Framework/LocklessQueue.cs
index 84f887c..21b8178 100644
--- a/OpenSim/Framework/LocklessQueue.cs
+++ b/OpenSim/Framework/LocklessQueue.cs
@@ -29,7 +29,7 @@ using System.Threading;
29 29
30namespace OpenSim.Framework 30namespace OpenSim.Framework
31{ 31{
32 public sealed class LocklessQueue<T> 32 public class LocklessQueue<T>
33 { 33 {
34 private sealed class SingleLinkNode 34 private sealed class SingleLinkNode
35 { 35 {
@@ -41,7 +41,7 @@ namespace OpenSim.Framework
41 SingleLinkNode tail; 41 SingleLinkNode tail;
42 int count; 42 int count;
43 43
44 public int Count { get { return count; } } 44 public virtual int Count { get { return count; } }
45 45
46 public LocklessQueue() 46 public LocklessQueue()
47 { 47 {
@@ -76,7 +76,7 @@ namespace OpenSim.Framework
76 Interlocked.Increment(ref count); 76 Interlocked.Increment(ref count);
77 } 77 }
78 78
79 public bool Dequeue(out T item) 79 public virtual bool Dequeue(out T item)
80 { 80 {
81 item = default(T); 81 item = default(T);
82 SingleLinkNode oldHead = null; 82 SingleLinkNode oldHead = null;
@@ -93,13 +93,16 @@ namespace OpenSim.Framework
93 if (oldHead == oldTail) 93 if (oldHead == oldTail)
94 { 94 {
95 if (oldHeadNext == null) 95 if (oldHeadNext == null)
96 {
97 count = 0;
96 return false; 98 return false;
99 }
97 100
98 CAS(ref tail, oldTail, oldHeadNext); 101 CAS(ref tail, oldTail, oldHeadNext);
99 } 102 }
100 else 103 else
101 { 104 {
102 item = oldHeadNext.Item; 105 item = oldHeadNext.Item;
103 haveAdvancedHead = CAS(ref head, oldHead, oldHeadNext); 106 haveAdvancedHead = CAS(ref head, oldHead, oldHeadNext);
104 if (haveAdvancedHead) 107 if (haveAdvancedHead)
105 { 108 {
@@ -118,8 +121,7 @@ namespace OpenSim.Framework
118 { 121 {
119 // ugly 122 // ugly
120 T item; 123 T item;
121 while(count > 0) 124 while(Dequeue(out item));
122 Dequeue(out item);
123 Init(); 125 Init();
124 } 126 }
125 127
@@ -136,4 +138,4 @@ namespace OpenSim.Framework
136 (object)Interlocked.CompareExchange<SingleLinkNode>(ref location, newValue, comparand); 138 (object)Interlocked.CompareExchange<SingleLinkNode>(ref location, newValue, comparand);
137 } 139 }
138 } 140 }
139} \ No newline at end of file 141}