private static unsafe void CreateScopeSafetyHandle() { AtomicSafetyHandle *handle = (AtomicSafetyHandle *)UnsafeUtility.Malloc(sizeof(AtomicSafetyHandle), 0, Allocator.Temp); *handle = AtomicSafetyHandle.Create(); UnsafeUtility.SetTempScopeUser(handle); }
public unsafe void CheckAccess() { AtomicSafetyHandle *handlePtr = &this.m_Safety0; int index = 0; while (true) { if (index >= this.m_SafetyReadOnlyCount) { int safetyReadOnlyCount = this.m_SafetyReadOnlyCount; while (true) { if (safetyReadOnlyCount >= (this.m_SafetyReadOnlyCount + this.m_SafetyReadWriteCount)) { fixed(AtomicSafetyHandle *handleRef = null) { return; } } AtomicSafetyHandle.CheckWriteAndThrow(handlePtr[safetyReadOnlyCount]); safetyReadOnlyCount++; } } AtomicSafetyHandle.CheckReadAndThrow(handlePtr[index]); index++; } }
internal void InvalidateDependents() { if (!NeedsUseAfterFreeTracking()) { return; } for (var i = 0; i < ChildSafetyHandles.Length; ++i) { unsafe { AtomicSafetyHandle *handle = ChildSafetyHandles.Ptr + i; if (CheckExists(*handle)) { AtomicSafetyHandle.Release(*handle); } } } ChildSafetyHandles.Clear(); if (Parent.IsValid) { Parent.TryRemoveChildAllocator(this, IndexInParent); } Parent = default; IndexInParent = InvalidChildAllocatorIndex; for (var i = 0; i < ChildAllocators.Length; ++i) { unsafe { AllocatorHandle *handle = (AllocatorHandle *)ChildAllocators.Ptr + i; if (handle->IsValid) { handle->Unregister(); } } } ChildAllocators.Clear(); }
internal static unsafe void Initialize(ComponentSystemBase system, Type jobType, Type wrapperJobType, bool isParallelFor, ref JobProcessComponentDataCache cache, out ProcessIterationData iterator) { int num; int num1; if (!isParallelFor || !(cache.JobReflectionDataParallelFor == IntPtr.Zero)) { num1 = isParallelFor ? 0 : ((int)(cache.JobReflectionData == IntPtr.Zero)); } else { num1 = 1; } if (num1 != 0) { Type iJobProcessComponentDataInterface = GetIJobProcessComponentDataInterface(jobType); if (cache.Types == null) { cache.Types = GetComponentTypes(jobType, iJobProcessComponentDataInterface, out cache.ProcessTypesCount, out cache.FilterChanged); } IntPtr ptr = GetJobReflection(jobType, wrapperJobType, iJobProcessComponentDataInterface, isParallelFor); if (isParallelFor) { cache.JobReflectionDataParallelFor = ptr; } else { cache.JobReflectionData = ptr; } } if (cache.ComponentSystem != system) { cache.ComponentGroup = system.GetComponentGroupInternal(cache.Types); if (cache.FilterChanged.Length != 0) { cache.ComponentGroup.SetFilterChanged(cache.FilterChanged); } else { cache.ComponentGroup.ResetFilter(); } cache.ComponentSystem = system; } ComponentGroup componentGroup = cache.ComponentGroup; iterator.IsReadOnly3 = num = 0; iterator.IsReadOnly2 = num = num; iterator.IsReadOnly1 = num = num; iterator.IsReadOnly0 = num; int *numPtr = &iterator.IsReadOnly0; int index = 0; while (true) { if (index == cache.ProcessTypesCount) { fixed(int *numRef = null) { componentGroup.GetComponentChunkIterator(out iterator.Iterator); iterator.IndexInGroup3 = num = -1; iterator.IndexInGroup2 = num = num; iterator.IndexInGroup0 = iterator.IndexInGroup1 = num; int *numPtr2 = &iterator.IndexInGroup0; int num3 = 0; while (true) { if (num3 == cache.ProcessTypesCount) { fixed(int *numRef2 = null) { iterator.m_IsParallelFor = isParallelFor; iterator.m_Length = componentGroup.CalculateNumberOfChunksWithoutFiltering(); iterator.m_MaxIndex = iterator.m_Length - 1; iterator.m_MinIndex = 0; AtomicSafetyHandle handle = new AtomicSafetyHandle(); iterator.m_Safety3 = handle = handle; iterator.m_Safety2 = handle = handle; iterator.m_Safety0 = iterator.m_Safety1 = handle; iterator.m_SafetyReadOnlyCount = 0; AtomicSafetyHandle *handlePtr = &iterator.m_Safety0; int num4 = 0; while (true) { if (num4 == cache.ProcessTypesCount) { fixed(AtomicSafetyHandle *handleRef = null) { iterator.m_SafetyReadWriteCount = 0; AtomicSafetyHandle *handlePtr2 = &iterator.m_Safety0; int num5 = 0; while (true) { if (num5 == cache.ProcessTypesCount) { fixed(AtomicSafetyHandle *handleRef2 = null) { Assert.AreEqual(cache.ProcessTypesCount, iterator.m_SafetyReadWriteCount + iterator.m_SafetyReadOnlyCount); return; } } if (cache.Types[num5].AccessModeType == ComponentType.AccessMode.ReadWrite) { handlePtr2[iterator.m_SafetyReadOnlyCount + iterator.m_SafetyReadWriteCount] = componentGroup.GetSafetyHandle(componentGroup.GetIndexInComponentGroup(cache.Types[num5].TypeIndex)); int *numPtr1 = (int *)ref iterator.m_SafetyReadWriteCount; numPtr1[0]++; } num5++; } } } if (cache.Types[num4].AccessModeType == ComponentType.AccessMode.ReadOnly) { handlePtr[iterator.m_SafetyReadOnlyCount] = componentGroup.GetSafetyHandle(componentGroup.GetIndexInComponentGroup(cache.Types[num4].TypeIndex)); int *numPtr3 = (int *)ref iterator.m_SafetyReadOnlyCount; numPtr3[0]++; } num4++; } } } numPtr2[num3] = componentGroup.GetIndexInComponentGroup(cache.Types[num3].TypeIndex); num3++; } } } numPtr[index] = (cache.Types[index].AccessModeType == ComponentType.AccessMode.ReadOnly) ? 1 : 0; index++; } }
public unsafe ComponentGroupArrayData(ComponentGroupArrayStaticCache staticCache) { int outLength = 0; staticCache.ComponentGroup.GetComponentChunkIterator(out outLength, out this.m_ChunkIterator); this.m_ChunkIterator.IndexInComponentGroup = 0; this.m_Length = outLength; this.m_MinIndex = 0; this.m_MaxIndex = outLength - 1; this.CacheBeginIndex = 0; this.CacheEndIndex = 0; this.m_ArchetypeManager = staticCache.ComponentGroup.GetArchetypeManager(); this.m_ComponentDataCount = staticCache.ComponentDataCount; this.m_ComponentCount = staticCache.ComponentCount; int * numPtr = &this.m_IndexInComponentGroup.FixedElementField; bool *flagPtr = &this.m_IsWriting.FixedElementField; ComponentGroupStream *streamPtr = (ComponentGroupStream *)&this.m_Caches.FixedElementField; int index = 0; while (true) { if (index >= (staticCache.ComponentDataCount + staticCache.ComponentCount)) { fixed(bool **flagPtrRef = null) { fixed(byte **numPtrRef2 = null) { fixed(int **numPtrRef = null) { this.m_Safety0 = new AtomicSafetyHandle(); this.m_Safety1 = new AtomicSafetyHandle(); this.m_Safety2 = new AtomicSafetyHandle(); this.m_Safety3 = new AtomicSafetyHandle(); this.m_Safety4 = new AtomicSafetyHandle(); this.m_Safety5 = new AtomicSafetyHandle(); Assert.AreEqual(6, 6); this.m_SafetyReadWriteCount = 0; this.m_SafetyReadOnlyCount = 0; ComponentJobSafetyManager safetyManager = staticCache.SafetyManager; AtomicSafetyHandle * handlePtr = &this.m_Safety0; int num3 = 0; while (true) { if (num3 == staticCache.ComponentTypes.Length) { int num4 = 0; while (true) { if (num4 == staticCache.ComponentTypes.Length) { fixed(AtomicSafetyHandle *handleRef = null) { return; } } ComponentType type2 = staticCache.ComponentTypes[num4]; if (type2.AccessModeType == ComponentType.AccessMode.ReadWrite) { handlePtr[this.m_SafetyReadOnlyCount + this.m_SafetyReadWriteCount] = safetyManager.GetSafetyHandle(type2.TypeIndex, false); this.m_SafetyReadWriteCount++; } num4++; } } ComponentType type = staticCache.ComponentTypes[num3]; if (type.AccessModeType == ComponentType.AccessMode.ReadOnly) { handlePtr[this.m_SafetyReadOnlyCount] = safetyManager.GetSafetyHandle(type.TypeIndex, true); this.m_SafetyReadOnlyCount++; } num3++; } } } } } numPtr[index] = staticCache.ComponentGroup.GetIndexInComponentGroup(staticCache.ComponentTypes[index].TypeIndex); streamPtr[index].FieldOffset = (ushort)staticCache.ComponentFieldOffsets[index]; *((sbyte *)(flagPtr + index)) = staticCache.ComponentTypes[index].AccessModeType == ComponentType.AccessMode.ReadWrite; index++; } }