Example #1
0
        internal static void Exit(object obj)
        {
            var sync = (uint)(Intrinsic.GetObjectAddress(obj) + IntPtr.Size);

            var value = Native.Get32(sync);

            Native.Set32(sync, 0);

            Uninterruptible.Exit(value == 2);
        }
Example #2
0
        internal static void Enter(object obj)
        {
            var sync = (int)Intrinsic.GetObjectAddress(obj) + IntPtr.Size;

            if (Uninterruptible.Enter())
            {
                while (Native.CmpXChgLoad32(sync, 2, 0) != 0)
                {
                }
            }
            else
            {
                while (Native.CmpXChgLoad32(sync, 1, 0) != 0)
                {
                }
            }
        }