├── .gitignore
├── DisruptorUnity3d
├── Assembly-CSharp-vs.csproj
├── Assembly-CSharp.csproj
├── Assets
│ ├── BasicBenchmark.unity
│ ├── BasicBenchmark.unity.meta
│ ├── ConcurrentQueue.cs
│ ├── ConcurrentQueue.cs.meta
│ ├── RingBuffer.cs
│ ├── RingBuffer.cs.meta
│ ├── Test.cs
│ └── Test.cs.meta
├── DisruptorUnity3d-csharp.sln
├── DisruptorUnity3d.sln
├── DisruptorUnity3d.v12.suo
└── ProjectSettings
│ ├── AudioManager.asset
│ ├── DynamicsManager.asset
│ ├── EditorBuildSettings.asset
│ ├── EditorSettings.asset
│ ├── GraphicsSettings.asset
│ ├── InputManager.asset
│ ├── NavMeshAreas.asset
│ ├── NetworkManager.asset
│ ├── Physics2DSettings.asset
│ ├── ProjectSettings.asset
│ ├── ProjectVersion.txt
│ ├── QualitySettings.asset
│ ├── TagManager.asset
│ └── TimeManager.asset
├── LICENSE
├── README.md
└── readme-img
├── ConcurrentQueueProfile.png
└── RingBufferProfile.png
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 | [Bb]uild/
5 |
6 | # Autogenerated VS/MD solution and project files
7 | /*.csproj
8 | /*.unityproj
9 | /*.sln
10 | /*.suo
11 | /*.user
12 | /*.userprefs
13 | /*.pidb
14 | /*.booproj
15 |
16 | #Unity3D Generated File On Crash Reports
17 | sysinfo.txt
18 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assembly-CSharp-vs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {B82A8DAA-65CD-1450-2295-651F0AD06589}
9 | Library
10 | Properties
11 |
12 | Assembly-CSharp
13 | v3.5
14 | 512
15 | Assets
16 |
17 |
18 | true
19 | full
20 | false
21 | Temp\bin\Debug\
22 | DEBUG;TRACE;UNITY_5_0_0;UNITY_5_0;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_MONO;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN
23 | prompt
24 | 4
25 | 0169
26 |
27 |
28 | pdbonly
29 | true
30 | Temp\bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | 0169
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | C:/Program Files/Unity/Editor/Data/Managed/UnityEngine.dll
43 |
44 |
45 | C:/Program Files/Unity/Editor/Data/Managed/UnityEditor.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll
54 |
55 |
56 |
57 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assembly-CSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {B82A8DAA-65CD-1450-2295-651F0AD06589}
9 | Library
10 | Properties
11 |
12 | Assembly-CSharp
13 | v3.5
14 | 512
15 | Assets
16 |
17 |
18 | true
19 | full
20 | false
21 | Temp\bin\Debug\
22 | DEBUG;TRACE;UNITY_5_0_0;UNITY_5_0;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_MONO;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN
23 | prompt
24 | 4
25 | 0169
26 |
27 |
28 | pdbonly
29 | true
30 | Temp\bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | 0169
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | C:/Program Files/Unity/Editor/Data/Managed/UnityEngine.dll
43 |
44 |
45 | C:/Program Files/Unity/Editor/Data/Managed/UnityEditor.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | C:/Program Files/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll
54 |
55 |
56 |
57 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/BasicBenchmark.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/Assets/BasicBenchmark.unity
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/BasicBenchmark.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bcce797dc7719ff4ca37171989fef5d9
3 | timeCreated: 1425935652
4 | licenseType: Free
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/ConcurrentQueue.cs:
--------------------------------------------------------------------------------
1 | // ConcurrentQueue.cs
2 | //
3 | // Copyright (c) 2008 Jérémie "Garuma" Laval
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 | //
23 | //
24 |
25 | // Note this is slightly modified from the original from Mono for compatibility with .Net 3.5
26 |
27 | using System;
28 | using System.Collections;
29 | using System.Collections.Generic;
30 | using System.Runtime.Serialization;
31 |
32 | namespace System.Threading.Collections
33 | {
34 | public class ConcurrentQueue : IEnumerable, ICollection, ISerializable, IDeserializationCallback
35 | {
36 | class Node
37 | {
38 | public T Value;
39 | public Node Next;
40 | }
41 |
42 | Node _head = new Node();
43 | Node _tail;
44 | int _count;
45 |
46 | ///
47 | ///
48 | public ConcurrentQueue()
49 | {
50 | _tail = _head;
51 | }
52 |
53 | public ConcurrentQueue(IEnumerable enumerable)
54 | : this()
55 | {
56 | foreach (T item in enumerable)
57 | Enqueue(item);
58 | }
59 |
60 | public void Enqueue(T item)
61 | {
62 | var node = new Node { Value = item };
63 |
64 | Node oldTail = null;
65 |
66 | bool update = false;
67 | while (!update)
68 | {
69 | oldTail = _tail;
70 | var oldNext = oldTail.Next;
71 |
72 | // Did tail was already updated ?
73 | if (_tail == oldTail)
74 | {
75 | if (oldNext == null)
76 | {
77 | // The place is for us
78 | update = Interlocked.CompareExchange(ref _tail.Next, node, null) == null;
79 | }
80 | else
81 | {
82 | // another Thread already used the place so give him a hand by putting tail where it should be
83 | Interlocked.CompareExchange(ref _tail, oldNext, oldTail);
84 | }
85 | }
86 | }
87 | // At this point we added correctly our node, now we have to update tail. If it fails then it will be done by another thread
88 | Interlocked.CompareExchange(ref _tail, node, oldTail);
89 |
90 | Interlocked.Increment(ref _count);
91 | }
92 |
93 |
94 | ///
95 | ///
96 | ///
97 | public bool TryDequeue(out T value)
98 | {
99 | value = default(T);
100 | bool advanced = false;
101 | while (!advanced)
102 | {
103 | Node oldHead = _head;
104 | Node oldTail = _tail;
105 | Node oldNext = oldHead.Next;
106 |
107 | if (oldHead == _head)
108 | {
109 | // Empty case ?
110 | if (oldHead == oldTail)
111 | {
112 | // This should be false then
113 | if (oldNext != null)
114 | {
115 | // If not then the linked list is mal formed, update tail
116 | Interlocked.CompareExchange(ref _tail, oldNext, oldTail);
117 | }
118 | value = default(T);
119 | return false;
120 | }
121 | else
122 | {
123 | value = oldNext.Value;
124 | advanced = Interlocked.CompareExchange(ref _head, oldNext, oldHead) == oldHead;
125 | }
126 | }
127 | }
128 |
129 | Interlocked.Decrement(ref _count);
130 | return true;
131 | }
132 |
133 | ///
134 | ///
135 | ///
136 | public bool TryPeek(out T value)
137 | {
138 | if (IsEmpty)
139 | {
140 | value = default(T);
141 | return false;
142 | }
143 |
144 | Node first = _head.Next;
145 | value = first.Value;
146 | return true;
147 | }
148 |
149 | public void Clear()
150 | {
151 | _count = 0;
152 | _tail = _head = new Node();
153 | }
154 |
155 | IEnumerator IEnumerable.GetEnumerator()
156 | {
157 | return InternalGetEnumerator();
158 | }
159 |
160 | IEnumerator IEnumerable.GetEnumerator()
161 | {
162 | return InternalGetEnumerator();
163 | }
164 |
165 | public IEnumerator GetEnumerator()
166 | {
167 | return InternalGetEnumerator();
168 | }
169 |
170 | IEnumerator InternalGetEnumerator()
171 | {
172 | Node myHead = _head;
173 | while ((myHead = myHead.Next) != null)
174 | {
175 | yield return myHead.Value;
176 | }
177 | }
178 |
179 | void ICollection.CopyTo(Array array, int index)
180 | {
181 | T[] dest = array as T[];
182 | if (dest == null)
183 | return;
184 | CopyTo(dest, index);
185 | }
186 |
187 | public void CopyTo(T[] dest, int index)
188 | {
189 | IEnumerator e = InternalGetEnumerator();
190 | int i = index;
191 | while (e.MoveNext())
192 | {
193 | dest[i++] = e.Current;
194 | }
195 | }
196 |
197 | public T[] ToArray()
198 | {
199 | T[] dest = new T[_count];
200 | CopyTo(dest, 0);
201 | return dest;
202 | }
203 |
204 | public void GetObjectData(SerializationInfo info, StreamingContext context)
205 | {
206 | throw new NotImplementedException();
207 | }
208 |
209 | bool ICollection.IsSynchronized
210 | {
211 | get { return true; }
212 | }
213 |
214 | public void OnDeserialization(object sender)
215 | {
216 | throw new NotImplementedException();
217 | }
218 |
219 | readonly object _syncRoot = new object();
220 | object ICollection.SyncRoot
221 | {
222 | get { return _syncRoot; }
223 | }
224 |
225 | public int Count
226 | {
227 | get
228 | {
229 | return _count;
230 | }
231 | }
232 |
233 | public bool IsEmpty
234 | {
235 | get
236 | {
237 | return _count == 0;
238 | }
239 | }
240 | }
241 | }
242 |
243 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/ConcurrentQueue.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 13a495889b422dc4a867161d1f69dde8
3 | timeCreated: 1425935504
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/RingBuffer.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 | using System.Threading;
4 |
5 | namespace DisruptorUnity3d
6 | {
7 | ///
8 | /// Implementation of the Disruptor pattern
9 | ///
10 | /// the type of item to be stored
11 | public class RingBuffer
12 | {
13 | private readonly T[] _entries;
14 | private readonly int _modMask;
15 | private Volatile.PaddedLong _consumerCursor = new Volatile.PaddedLong();
16 | private Volatile.PaddedLong _producerCursor = new Volatile.PaddedLong();
17 |
18 | ///
19 | /// Creates a new RingBuffer with the given capacity
20 | ///
21 | /// The capacity of the buffer
22 | /// Only a single thread may attempt to consume at any one time
23 | public RingBuffer(int capacity)
24 | {
25 | capacity = NextPowerOfTwo(capacity);
26 | _modMask = capacity - 1;
27 | _entries = new T[capacity];
28 | }
29 |
30 | ///
31 | /// The maximum number of items that can be stored
32 | ///
33 | public int Capacity
34 | {
35 | get { return _entries.Length; }
36 | }
37 |
38 | public T this[long index]
39 | {
40 | get { unchecked { return _entries[index & _modMask]; } }
41 | set { unchecked { _entries[index & _modMask] = value; } }
42 | }
43 |
44 | ///
45 | /// Removes an item from the buffer.
46 | ///
47 | /// The next available item
48 | public T Dequeue()
49 | {
50 | var next = _consumerCursor.ReadAcquireFence() + 1;
51 | while (_producerCursor.ReadAcquireFence() < next) // makes sure we read the data from _entries after we have read the producer cursor
52 | {
53 | Thread.SpinWait(1);
54 | }
55 | var result = this[next];
56 | _consumerCursor.WriteReleaseFence(next); // makes sure we read the data from _entries before we update the consumer cursor
57 | return result;
58 | }
59 |
60 | ///
61 | /// Attempts to remove an items from the queue
62 | ///
63 | /// the items
64 | /// True if successful
65 | public bool TryDequeue(out T obj)
66 | {
67 | var next = _consumerCursor.ReadAcquireFence() + 1;
68 |
69 | if (_producerCursor.ReadAcquireFence() < next)
70 | {
71 | obj = default(T);
72 | return false;
73 | }
74 | obj = Dequeue();
75 | return true;
76 | }
77 |
78 | ///
79 | /// Add an item to the buffer
80 | ///
81 | ///
82 | public void Enqueue(T item)
83 | {
84 | var next = _producerCursor.ReadAcquireFence() + 1;
85 |
86 | long wrapPoint = next - _entries.Length;
87 | long min = _consumerCursor.ReadAcquireFence();
88 |
89 | while (wrapPoint > min)
90 | {
91 | min = _consumerCursor.ReadAcquireFence();
92 | Thread.SpinWait(1);
93 | }
94 |
95 | this[next] = item;
96 | _producerCursor.WriteReleaseFence(next); // makes sure we write the data in _entries before we update the producer cursor
97 | }
98 |
99 | ///
100 | /// The number of items in the buffer
101 | ///
102 | /// for indicative purposes only, may contain stale data
103 | public int Count { get { return (int)(_producerCursor.ReadFullFence() - _consumerCursor.ReadFullFence()); } }
104 |
105 | private static int NextPowerOfTwo(int x)
106 | {
107 | var result = 2;
108 | while (result < x)
109 | {
110 | result <<= 1;
111 | }
112 | return result;
113 | }
114 |
115 |
116 | }
117 | public static class Volatile
118 | {
119 | private const int CacheLineSize = 64;
120 |
121 | [StructLayout(LayoutKind.Explicit, Size = CacheLineSize * 2)]
122 | public struct PaddedLong
123 | {
124 | [FieldOffset(CacheLineSize)]
125 | private long _value;
126 |
127 | ///
128 | /// Create a new with the given initial value.
129 | ///
130 | /// Initial value
131 | public PaddedLong(long value)
132 | {
133 | _value = value;
134 | }
135 |
136 | ///
137 | /// Read the value without applying any fence
138 | ///
139 | /// The current value
140 | public long ReadUnfenced()
141 | {
142 | return _value;
143 | }
144 |
145 | ///
146 | /// Read the value applying acquire fence semantic
147 | ///
148 | /// The current value
149 | public long ReadAcquireFence()
150 | {
151 | var value = _value;
152 | Thread.MemoryBarrier();
153 | return value;
154 | }
155 |
156 | ///
157 | /// Read the value applying full fence semantic
158 | ///
159 | /// The current value
160 | public long ReadFullFence()
161 | {
162 | Thread.MemoryBarrier();
163 | return _value;
164 | }
165 |
166 | ///
167 | /// Read the value applying a compiler only fence, no CPU fence is applied
168 | ///
169 | /// The current value
170 | [MethodImpl(MethodImplOptions.NoOptimization)]
171 | public long ReadCompilerOnlyFence()
172 | {
173 | return _value;
174 | }
175 |
176 | ///
177 | /// Write the value applying release fence semantic
178 | ///
179 | /// The new value
180 | public void WriteReleaseFence(long newValue)
181 | {
182 | Thread.MemoryBarrier();
183 | _value = newValue;
184 | }
185 |
186 | ///
187 | /// Write the value applying full fence semantic
188 | ///
189 | /// The new value
190 | public void WriteFullFence(long newValue)
191 | {
192 | Thread.MemoryBarrier();
193 | _value = newValue;
194 | }
195 |
196 | ///
197 | /// Write the value applying a compiler fence only, no CPU fence is applied
198 | ///
199 | /// The new value
200 | [MethodImpl(MethodImplOptions.NoOptimization)]
201 | public void WriteCompilerOnlyFence(long newValue)
202 | {
203 | _value = newValue;
204 | }
205 |
206 | ///
207 | /// Write without applying any fence
208 | ///
209 | /// The new value
210 | public void WriteUnfenced(long newValue)
211 | {
212 | _value = newValue;
213 | }
214 |
215 | ///
216 | /// Atomically set the value to the given updated value if the current value equals the comparand
217 | ///
218 | /// The new value
219 | /// The comparand (expected value)
220 | ///
221 | public bool AtomicCompareExchange(long newValue, long comparand)
222 | {
223 | return Interlocked.CompareExchange(ref _value, newValue, comparand) == comparand;
224 | }
225 |
226 | ///
227 | /// Atomically set the value to the given updated value
228 | ///
229 | /// The new value
230 | /// The original value
231 | public long AtomicExchange(long newValue)
232 | {
233 | return Interlocked.Exchange(ref _value, newValue);
234 | }
235 |
236 | ///
237 | /// Atomically add the given value to the current value and return the sum
238 | ///
239 | /// The value to be added
240 | /// The sum of the current value and the given value
241 | public long AtomicAddAndGet(long delta)
242 | {
243 | return Interlocked.Add(ref _value, delta);
244 | }
245 |
246 | ///
247 | /// Atomically increment the current value and return the new value
248 | ///
249 | /// The incremented value.
250 | public long AtomicIncrementAndGet()
251 | {
252 | return Interlocked.Increment(ref _value);
253 | }
254 |
255 | ///
256 | /// Atomically increment the current value and return the new value
257 | ///
258 | /// The decremented value.
259 | public long AtomicDecrementAndGet()
260 | {
261 | return Interlocked.Decrement(ref _value);
262 | }
263 |
264 | ///
265 | /// Returns the string representation of the current value.
266 | ///
267 | /// the string representation of the current value.
268 | public override string ToString()
269 | {
270 | var value = ReadFullFence();
271 | return value.ToString();
272 | }
273 | }
274 | }
275 | }
276 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/RingBuffer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ce496afbbb1748d4187d4e402c111f47
3 | timeCreated: 1425935504
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/Test.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Threading;
3 | using UnityEngine;
4 | using Debug = UnityEngine.Debug;
5 | using Random = System.Random;
6 |
7 | namespace DisruptorUnity3d
8 | {
9 | public class Test : MonoBehaviour
10 | {
11 | static readonly Random Rng = new Random();
12 | static readonly RingBuffer Queue = new RingBuffer(1000);
13 | //static readonly ConcurrentQueue Queue = new ConcurrentQueue();
14 |
15 | static readonly Stopwatch sw = new Stopwatch();
16 | private const long Count = 5000000;//100000000;
17 | private long _queued = 0;
18 | private const long BatchSize = 20000;
19 | private Thread _consumerThread;
20 | private bool _printed = false;
21 |
22 | private int numberToEnqueue;
23 |
24 | public void Start()
25 | {
26 | Debug.Log("Started Test");
27 | _consumerThread = new Thread(() =>
28 | {
29 | Debug.Log("Started consumer");
30 | int expectedNumber = 0;
31 | int previousNumber = 0;
32 | for (long i = 0; i < Count; )
33 | {
34 | int val;
35 | var dequeued = Queue.TryDequeue(out val);
36 | if (dequeued)
37 | {
38 | if (expectedNumber != val)
39 | Debug.Log("wrong value " + val + " ,correct: " + i + " ,previous: " + previousNumber);
40 | previousNumber = val;
41 | expectedNumber++;
42 | ++i;
43 | }
44 |
45 | }
46 | Debug.Log(string.Format("Consumer done {0}", sw.Elapsed));
47 | });
48 | _consumerThread.Start();
49 | sw.Start();
50 | }
51 |
52 |
53 |
54 | // Update is called once per frame
55 | public void Update()
56 | {
57 | if (_queued >= Count && !_printed)
58 | {
59 | sw.Stop();
60 | Debug.Log(string.Format("Producer done {0} {1}", sw.Elapsed, _queued));
61 | _printed = true;
62 |
63 | }
64 | else
65 | {
66 | for (long i = 0; i < BatchSize && _queued < Count; ++i)
67 | {
68 | Queue.Enqueue(numberToEnqueue++);
69 | ++_queued;
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/Assets/Test.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 991b6f2de77c4054d90c8d0b1fb1da3c
3 | timeCreated: 1425935504
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/DisruptorUnity3d-csharp.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 11.00
2 | # Visual Studio 2008
3 |
4 | Project("{64688A2B-C973-08D1-059A-FC78696BE082}") = "DisruptorUnity3d", "Assembly-CSharp-vs.csproj", "{B82A8DAA-65CD-1450-2295-651F0AD06589}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(MonoDevelopProperties) = preSolution
21 | StartupItem = Assembly-CSharp.csproj
22 | Policies = $0
23 | $0.TextStylePolicy = $1
24 | $1.inheritsSet = null
25 | $1.scope = text/x-csharp
26 | $0.CSharpFormattingPolicy = $2
27 | $2.inheritsSet = Mono
28 | $2.inheritsScope = text/x-csharp
29 | $2.scope = text/x-csharp
30 | $0.TextStylePolicy = $3
31 | $3.FileWidth = 120
32 | $3.TabWidth = 4
33 | $3.IndentWidth = 4
34 | $3.EolMarker = Unix
35 | $3.inheritsSet = Mono
36 | $3.inheritsScope = text/plain
37 | $3.scope = text/plain
38 | EndGlobalSection
39 |
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/DisruptorUnity3d.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 11.00
2 | # Visual Studio 2008
3 |
4 | Project("{64688A2B-C973-08D1-059A-FC78696BE082}") = "DisruptorUnity3d", "Assembly-CSharp.csproj", "{B82A8DAA-65CD-1450-2295-651F0AD06589}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {B82A8DAA-65CD-1450-2295-651F0AD06589}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(MonoDevelopProperties) = preSolution
21 | StartupItem = Assembly-CSharp.csproj
22 | Policies = $0
23 | $0.TextStylePolicy = $1
24 | $1.inheritsSet = null
25 | $1.scope = text/x-csharp
26 | $0.CSharpFormattingPolicy = $2
27 | $2.inheritsSet = Mono
28 | $2.inheritsScope = text/x-csharp
29 | $2.scope = text/x-csharp
30 | $0.TextStylePolicy = $3
31 | $3.FileWidth = 120
32 | $3.TabWidth = 4
33 | $3.IndentWidth = 4
34 | $3.EolMarker = Unix
35 | $3.inheritsSet = Mono
36 | $3.inheritsScope = text/plain
37 | $3.scope = text/plain
38 | EndGlobalSection
39 |
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/DisruptorUnity3d.v12.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/DisruptorUnity3d.v12.suo
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/NavMeshAreas.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 5.0.0f3
2 | m_StandardAssetsVersion: 0
3 |
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/DisruptorUnity3d/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/DisruptorUnity3d/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # disruptor-unity3d
2 | Basic, self contained, implementation of Disruptor for Unity3d. Only supports a single producer/single consumer. Only tested on x86 platforms. Bugs in Mono prevent this is working on iOS and Android before Unity 5.5.
3 |
4 | ## Usage
5 |
6 | Copy [RingBuffer.cs](https://github.com/dave-hillier/disruptor-unity3d/blob/master/DisruptorUnity3d/Assets/RingBuffer.cs) into your Unity project's assets folder (or sub-folder) and use the generic `RingBuffer` class.
7 | For example:
8 |
9 | ```csharp
10 | var buffer = new RingBuffer(8);
11 | for (int i = 1; i < 6; ++i)
12 | buffer.Enqueue(i);
13 | for (int i = 1; i < 6; ++i)
14 | buffer.Dequeue();
15 | ```
16 |
17 | ## Motivation
18 |
19 | [Unity3d](http://unity3d.com/) is a game engine with Mono embedded in it. The version of Mono inside Unity is very old; it doesnt have the SGen collector and uses the [Boehm GC](http://www.hboehm.info/gc/). The Boehm GC does not have great performance.
20 |
21 | When working on a Unity project I've found myself in need of a [Queue](http://en.wikipedia.org/wiki/Queue_%28abstract_data_type%29) for sending messages between threads. The current version of Mono contains an implementation of [ConcurrentQueue](https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/corlib/System.Collections.Concurrent/ConcurrentQueue.cs).
22 |
23 | My game uses a queue pretty intensively. When I want to send a message, it is enqueued to a queue and then subsequently dequeued by another thread, which serializes and sends it. When profiling, I've seen that the queue seems to be the source of the ocasional slow frame because it allocates with every message that is queued. The allocations can cause GC stalls at any time, but sometimes it doesnt doesnt explicitly appear on the profiler (for example, the profiler will show a long time in allocation itself and a reduction in total memory usage).
24 |
25 | I wanted to replace the `ConcurrentQueue` with something that did not have any extra allocation overhead. A [circular buffer](http://en.wikipedia.org/wiki/Circular_buffer) is a fixed size data structure that could be used in this case. When searching for an existing implementation I remembered the [Disruptor](https://lmax-exchange.github.io/disruptor/); a high performance lockless queue. Disruptor has many good qualities, but in my case, I only care about the lack of allocations.
26 |
27 | There is a [.Net port](https://github.com/disruptor-net/Disruptor-net) of the Disruptor, but it is for .Net 4 which is not supported by Unity and it actually makes some allocations. I did not want to spend the time porting it and I have a very much simpler use case. I don't need most of the functionality.
28 |
29 | I've implemented a very simple, self-contained version that uses the volatile long that is key to the implementation. It is intended to be self contained; just drop the source into your project. This project is not intended to rival the functionality of disruptor-net but provide an easy to use drop in queue. If you need a fully featured disruptor library then you should port or check out the forks incase someone has already done it.
30 |
31 | ## Benchmark
32 |
33 | I've created a benchmark in Test.cs for my single producer/single consumer RingBuffer. Each frame a batch of random integers are queued. The values are dequeued and discarded by the other thread.
34 |
35 | This benchmark is not intended as an example use case or to take performance, but allowed me to profile for allocations.
36 |
37 |
38 | ### Concurrent Queue
39 | Note:
40 | * the yellow spikes represent time spent on GC.
41 | * All frames are longer than 5ms some frames are longer than 16ms.
42 |
43 | 
44 |
45 | ### RingBuffer
46 | Note:
47 | * No yellow GC spikes
48 | * Most frames are under 5ms, no frames are longer than 16ms.
49 |
50 | 
51 |
52 |
--------------------------------------------------------------------------------
/readme-img/ConcurrentQueueProfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/readme-img/ConcurrentQueueProfile.png
--------------------------------------------------------------------------------
/readme-img/RingBufferProfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dave-hillier/disruptor-unity3d/717491f41d8663949b2d05056bb42bde17f61ce3/readme-img/RingBufferProfile.png
--------------------------------------------------------------------------------