コード例 #1
0
ファイル: ArrayEdgeMap.cs プロジェクト: KhaledSMQ/aml
        public override T this[int key]
        {
            get
            {
                if (key < minIndex || key > maxIndex)
                {
                    return(null);
                }

#if NET45PLUS
                return(Volatile.Read(ref arrayData[key - minIndex]));
#else
                return(Interlocked.CompareExchange(ref arrayData[key - minIndex], null, null));
#endif
            }
        }
コード例 #2
0
            void OnApplicationQuit()
            {
                Volatile.Write(ref _quitThread, true);

                OtherThreadFlushLogger();
            }
コード例 #3
0
        public void Log(string txt, LogType type         = LogType.Log, bool showLogStack = true, Exception e = null,
                        Dictionary <string, string> data = null)
        {
            var dataString = string.Empty;

            if (data != null)
            {
                dataString = DataToString.DetailString(data);
            }

            var frame = $"[{DateTime.UtcNow.ToString("HH:mm:ss.fff")}] thread: {Environment.CurrentManagedThreadId}";

            try
            {
                if (MAINTHREADID == Environment.CurrentManagedThreadId)
                {
                    frame += $" frame: {Time.frameCount}";
                }
            }
            catch
            {
                //there is something wrong with  Environment.CurrentManagedThreadId
            }

            StackTrace stack = null;

#if UNITY_EDITOR
            stack = new StackTrace(3, true);
#else
            if (type == LogType.Error || type == LogType.Exception)
            {
                stack = new StackTrace(3, true);
            }
#endif

            if (Volatile.Read(ref Console.batchLog) == true)
            {
                var stackString = stack == null ? string.Empty : stack.GetFrame(0).ToString();
                var strArray    = Encoding.UTF8.GetBytes(txt.FastConcat(stackString));
                var logHash     = Murmur3.MurmurHash3_x86_32(strArray, SEED);

                if (_batchedErrorLogs.ContainsKey(logHash))
                {
                    _batchedErrorLogs[logHash] = new ErrorLogObject(_batchedErrorLogs[logHash]);
                }
                else
                {
#if !UNITY_EDITOR
                    if (type == LogType.Error)
                    {
                        stack = new StackTrace(3, true);
                    }
#endif

                    _batchedErrorLogs[logHash] =
                        new ErrorLogObject(txt, stack, type, e, frame, showLogStack, dataString);
                }
            }
            else
            {
#if !UNITY_EDITOR
                if (type == LogType.Error)
                {
                    stack = new StackTrace(3, true);
                }
#endif

                _notBatchedQueue.Enqueue(new ErrorLogObject(txt, stack, type, e, frame, showLogStack, dataString,
                                                            0));
            }
        }
コード例 #4
0
 public static unsafe object LoadReferenceTypeField(IntPtr address)
 {
     return(Volatile.Read <Object>(ref Unsafe.As <IntPtr, object>(ref *(IntPtr *)address)));
 }
コード例 #5
0
 public static unsafe void StoreReferenceTypeField(IntPtr address, object fieldValue)
 {
     Volatile.Write <Object>(ref Unsafe.As <IntPtr, object>(ref *(IntPtr *)address), fieldValue);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a target reference type with the type's default constructor if the target has not
 /// already been initialized.
 /// </summary>
 /// <typeparam name="T">The reference type of the reference to be initialized.</typeparam>
 /// <param name="target">A reference of type <typeparamref name="T"/> to initialize if it has not
 /// already been initialized.</param>
 /// <returns>The initialized reference of type <typeparamref name="T"/>.</returns>
 /// <exception cref="T:System.MissingMemberException">Type <typeparamref name="T"/> does not have a default
 /// constructor.</exception>
 /// <exception cref="T:System.MemberAccessException">
 /// Permissions to access the constructor of type <typeparamref name="T"/> were missing.
 /// </exception>
 /// <remarks>
 /// <para>
 /// This method may only be used on reference types. To ensure initialization of value
 /// types, see other overloads of EnsureInitialized.
 /// </para>
 /// <para>
 /// This method may be used concurrently by multiple threads to initialize <paramref name="target"/>.
 /// In the event that multiple threads access this method concurrently, multiple instances of <typeparamref name="T"/>
 /// may be created, but only one will be stored into <paramref name="target"/>. In such an occurrence, this method will not dispose of the
 /// objects that were not stored.  If such objects must be disposed, it is up to the caller to determine
 /// if an object was not used and to then dispose of the object appropriately.
 /// </para>
 /// </remarks>
 public static T EnsureInitialized <T>([NotNull] ref T?target) where T : class =>
 Volatile.Read(ref target) ?? EnsureInitializedCore(ref target);
コード例 #7
0
 /// <summary>
 /// Initializes a target reference type with a specified function if it has not already been initialized.
 /// </summary>
 /// <typeparam name="T">The type of the reference to be initialized. Has to be reference type.</typeparam>
 /// <param name="target">A reference of type <typeparamref name="T"/> to initialize if it has not already been initialized.</param>
 /// <param name="syncLock">A reference to an object used as the mutually exclusive lock for initializing
 /// <paramref name="target"/>. If <paramref name="syncLock"/> is null, a new object will be instantiated.</param>
 /// <param name="valueFactory">The <see cref="T:System.Func{T}"/> invoked to initialize the reference.</param>
 /// <returns>The initialized value of type <typeparamref name="T"/>.</returns>
 public static T EnsureInitialized <T>([NotNull] ref T?target, [NotNull] ref object?syncLock, Func <T> valueFactory) where T : class =>
 Volatile.Read(ref target) ?? EnsureInitializedCore(ref target, ref syncLock, valueFactory);