A game framework written with osu! in mind.

Remove AtomicCounter to reduce draw node object allocations slightly

+5 -31
+5 -5
osu.Framework/Graphics/DrawNode.cs
··· 1 1 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 2 // See the LICENCE file in the repository root for full licence text. 3 3 4 - using osu.Framework.Graphics.OpenGL; 5 4 using System; 6 5 using System.Runtime.CompilerServices; 6 + using System.Threading; 7 7 using osu.Framework.Graphics.Batches; 8 8 using osu.Framework.Graphics.Colour; 9 + using osu.Framework.Graphics.OpenGL; 9 10 using osu.Framework.Graphics.OpenGL.Buffers; 10 11 using osu.Framework.Graphics.OpenGL.Textures; 11 12 using osu.Framework.Graphics.OpenGL.Vertices; 12 13 using osu.Framework.Graphics.Primitives; 13 14 using osu.Framework.Graphics.Textures; 14 - using osu.Framework.Threading; 15 15 using osu.Framework.Utils; 16 16 using osuTK; 17 17 ··· 45 45 /// </summary> 46 46 protected IDrawable Source { get; private set; } 47 47 48 - private readonly AtomicCounter referenceCount = new AtomicCounter(); 48 + private long referenceCount; 49 49 50 50 /// <summary> 51 51 /// The depth at which drawing should take place. ··· 282 282 /// <remarks> 283 283 /// All <see cref="DrawNode"/>s start with a reference count of 1. 284 284 /// </remarks> 285 - internal void Reference() => referenceCount.Increment(); 285 + internal void Reference() => Interlocked.Increment(ref referenceCount); 286 286 287 287 protected internal bool IsDisposed { get; private set; } 288 288 289 289 public void Dispose() 290 290 { 291 - if (referenceCount.Decrement() != 0) 291 + if (Interlocked.Decrement(ref referenceCount) != 0) 292 292 return; 293 293 294 294 GLWrapper.ScheduleDisposal(() => Dispose(true));
-26
osu.Framework/Threading/AtomicCounter.cs
··· 1 - // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 - // See the LICENCE file in the repository root for full licence text. 3 - 4 - using System.Threading; 5 - 6 - namespace osu.Framework.Threading 7 - { 8 - public class AtomicCounter 9 - { 10 - private long count; 11 - 12 - public long Increment() => Interlocked.Increment(ref count); 13 - 14 - public long Decrement() => Interlocked.Decrement(ref count); 15 - 16 - public long Add(long value) => Interlocked.Add(ref count, value); 17 - 18 - public long Reset() => Interlocked.Exchange(ref count, 0); 19 - 20 - public long Value 21 - { 22 - set => Interlocked.Exchange(ref count, value); 23 - get => Interlocked.Read(ref count); 24 - } 25 - } 26 - }