// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) 2022-2023 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Magic Leap 2 Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using System.Threading; namespace MagicLeap.Spectator { public class SafeBool { #region Static public static implicit operator bool(SafeBool sb) => sb.value; #endregion #region Private variables private int _value = 0; #endregion #region Private properties private bool value { get { return Interlocked.CompareExchange(ref _value, 1, 1) == 1; } set { if (value) Interlocked.CompareExchange(ref _value, 1, 0); else Interlocked.CompareExchange(ref _value, 0, 1); } } #endregion #region Constructors / Destructor public SafeBool() { } public SafeBool(bool value) { this.value = value; } #endregion #region Public methods public void Set(bool value) { this.value = value; } #endregion } }