Example #1
0
        public unsafe void TempAllocatorRenestingUserNull()
        {
            void *[] mem = new void *[4096];
            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < mem.Length; i++)
                {
                    UnsafeUtility.EnterTempScope();
                    if (j == 0)
                    {
                        UnsafeUtility.SetTempScopeUser((void *)(i + 1));
                    }
                    else
                    {
                        Assert.IsTrue(UnsafeUtility.GetTempScopeUser() == null);
                    }
                    mem[i] = UnsafeUtility.Malloc(4096, 0, Collections.Allocator.Temp);
                }

                for (int i = mem.Length - 1; i >= 0; i--)
                {
                    UnsafeUtility.Free(mem[i], Collections.Allocator.Temp);
                    UnsafeUtility.ExitTempScope();
                }
            }
        }
Example #2
0
        private static unsafe void ReleaseScopeSafetyHandle()
        {
            void *user = UnsafeUtility.GetTempScopeUser();

            AtomicSafetyHandle.Release(*(AtomicSafetyHandle *)user);
            UnsafeUtility.Free(user, Allocator.Temp);
            UnsafeUtility.SetTempScopeUser(null);
        }
Example #3
0
        public unsafe void TempAllocatorNullIfNoScope()
        {
            ExitTempScopesLocally();

            // Try to alloc
            Assert.IsTrue(UnsafeUtility.Malloc(24, 0, Collections.Allocator.Temp) == null);

            // Try get user
            Assert.IsTrue(UnsafeUtility.GetTempScopeUser() == null);

            EnterTempScopesLocally();
        }
Example #4
0
        public unsafe void TempAllocatorRewindSavesUserData()
        {
            void *[] mem = new void *[4096];
            for (int i = 0; i < mem.Length; i++)
            {
                UnsafeUtility.EnterTempScope();
                UnsafeUtility.SetTempScopeUser((void *)(i + 1));
                mem[i] = UnsafeUtility.Malloc(4096, 0, Collections.Allocator.Temp);
            }

            for (int i = mem.Length - 1; i >= 0; i--)
            {
                Assert.IsTrue((void *)(i + 1) == UnsafeUtility.GetTempScopeUser());
                UnsafeUtility.Free(mem[i], Collections.Allocator.Temp);
                UnsafeUtility.ExitTempScope();
            }
        }
Example #5
0
        internal static unsafe AtomicSafetyHandle GetSafetyHandle()
        {
            void *user = UnsafeUtility.GetTempScopeUser();

            return(*(AtomicSafetyHandle *)user);
        }