| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationSeamEditToken.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Threading; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Provides process-unique nonwrapping ownership for seam edit sessions.</summary> |
| | | 14 | | internal readonly struct NavigationSeamEditToken |
| | | 15 | | { |
| | | 16 | | private static long _highWater; |
| | | 17 | | |
| | 3284 | 18 | | private NavigationSeamEditToken(long value) => Value = value; |
| | | 19 | | |
| | | 20 | | internal long Value { get; } |
| | | 21 | | |
| | | 22 | | internal static NavigationSeamEditToken Create() |
| | | 23 | | { |
| | 3283 | 24 | | long value = Interlocked.Increment(ref _highWater); |
| | 3283 | 25 | | return FromIncrementedValue(value); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | internal static NavigationSeamEditToken FromIncrementedValue(long value) |
| | | 29 | | { |
| | 3285 | 30 | | SwiftThrowHelper.ThrowIfTrue( |
| | 3285 | 31 | | value <= 0, |
| | 3285 | 32 | | message: "The seam edit ownership token space was exhausted."); |
| | 3284 | 33 | | return new NavigationSeamEditToken(value); |
| | | 34 | | } |
| | | 35 | | } |