···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.
34-using osu.Framework.Graphics.OpenGL;
5using System;
6using System.Runtime.CompilerServices;
07using osu.Framework.Graphics.Batches;
8using osu.Framework.Graphics.Colour;
09using osu.Framework.Graphics.OpenGL.Buffers;
10using osu.Framework.Graphics.OpenGL.Textures;
11using osu.Framework.Graphics.OpenGL.Vertices;
12using osu.Framework.Graphics.Primitives;
13using osu.Framework.Graphics.Textures;
14-using osu.Framework.Threading;
15using osu.Framework.Utils;
16using osuTK;
17···45 /// </summary>
46 protected IDrawable Source { get; private set; }
4748- private readonly AtomicCounter referenceCount = new AtomicCounter();
4950 /// <summary>
51 /// The depth at which drawing should take place.
···282 /// <remarks>
283 /// All <see cref="DrawNode"/>s start with a reference count of 1.
284 /// </remarks>
285- internal void Reference() => referenceCount.Increment();
286287 protected internal bool IsDisposed { get; private set; }
288289 public void Dispose()
290 {
291- if (referenceCount.Decrement() != 0)
292 return;
293294 GLWrapper.ScheduleDisposal(() => Dispose(true));
···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.
304using System;
5using System.Runtime.CompilerServices;
6+using System.Threading;
7using osu.Framework.Graphics.Batches;
8using osu.Framework.Graphics.Colour;
9+using osu.Framework.Graphics.OpenGL;
10using osu.Framework.Graphics.OpenGL.Buffers;
11using osu.Framework.Graphics.OpenGL.Textures;
12using osu.Framework.Graphics.OpenGL.Vertices;
13using osu.Framework.Graphics.Primitives;
14using osu.Framework.Graphics.Textures;
015using osu.Framework.Utils;
16using osuTK;
17···45 /// </summary>
46 protected IDrawable Source { get; private set; }
4748+ private long referenceCount;
4950 /// <summary>
51 /// The depth at which drawing should take place.
···282 /// <remarks>
283 /// All <see cref="DrawNode"/>s start with a reference count of 1.
284 /// </remarks>
285+ internal void Reference() => Interlocked.Increment(ref referenceCount);
286287 protected internal bool IsDisposed { get; private set; }
288289 public void Dispose()
290 {
291+ if (Interlocked.Decrement(ref referenceCount) != 0)
292 return;
293294 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-}