Exemple #1
0
        internal void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
#endif
            if (m_Data != null)
            {
                EntitySharedComponentCommand *cleanup_list = m_Data->m_CleanupList;
                while (cleanup_list != null)
                {
                    cleanup_list->BoxedObject.Free();
                    cleanup_list = cleanup_list->Prev;
                }
                m_Data->m_CleanupList = null;

                var label = m_Data->m_Allocator;

                while (m_Data->m_Tail != null)
                {
                    var prev = m_Data->m_Tail->Prev;
                    UnsafeUtility.Free(m_Data->m_Tail, m_Data->m_Allocator);
                    m_Data->m_Tail = prev;
                }

                m_Data->m_Head = null;
                UnsafeUtility.Free(m_Data, label);
                m_Data = null;
            }
        }
Exemple #2
0
        protected void Dispose(bool disposing)
        {
            if (isCreated)
            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                // dispose of atomic safety handle:
                if (m_AsNativeArray)
                {
                    AtomicSafetyHandle.CheckDeallocateAndThrow(m_SafetyHandle);
                    AtomicSafetyHandle.Release(m_SafetyHandle);
                    m_AsNativeArray = false;
                }
#endif

                // dispose of compuse buffer representation:
                if (m_ComputeBuffer != null)
                {
                    m_ComputeBuffer.Dispose();
                }

                // free unmanaged memory buffer:
                UnsafeUtility.Free(m_AlignedPtr, Allocator.Persistent);
                m_AlignedPtr = null;
            }
        }
        public static unsafe void Execute(ref T data, IntPtr listDataPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
        {
            NativeParticleData particleData;
            var listData = (NativeListData *)listDataPtr;

            ParticleSystem.CopyManagedJobData(listData->system, out particleData);

            ParticleSystemJobData jobData = new ParticleSystemJobData(ref particleData);

            while (true)
            {
                int begin;
                int end;
                if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out begin, out end))
                {
                    break;
                }

                JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf(ref data), begin, end - begin);

                data.Execute(jobData, begin, end - begin);
            }

            AtomicSafetyHandle.CheckDeallocateAndThrow(jobData.m_Safety);
            AtomicSafetyHandle.Release(jobData.m_Safety);
        }
 public unsafe void Dispose()
 {
     *m_Ptr = 0;
     Memory.Unmanaged.Free(m_Ptr, m_Allocator);
     AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
     AtomicSafetyHandle.Release(m_Safety);
 }
Exemple #5
0
        public void BeginExclusiveTransaction()
        {
            if (IsInTransaction)
            {
                return;
            }

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            for (var i = 0; i != TypeManager.GetTypeCount(); i++)
            {
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].BufferHandle);
            }

            for (var i = 0; i != TypeManager.GetTypeCount(); i++)
            {
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].BufferHandle);
            }
#endif

            IsInTransaction = true;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            ExclusiveTransactionSafety = AtomicSafetyHandle.Create();
#endif
            m_ExclusiveTransactionDependency = GetAllDependencies();
        }
Exemple #6
0
        public unsafe static void Execute(ref T data, IntPtr listDataPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
        {
            NativeListData *   ptr = (NativeListData *)((void *)listDataPtr);
            NativeParticleData nativeParticleData;

            ParticleSystem.CopyManagedJobData(ptr->system, out nativeParticleData);
            ParticleSystemJobData particleSystemJobData = new ParticleSystemJobData(ref nativeParticleData);

            while (true)
            {
                int  num;
                int  num2;
                bool flag = !JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out num, out num2);
                if (flag)
                {
                    break;
                }
                JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf <T>(ref data), num, num2 - num);
                for (int i = num; i < num2; i++)
                {
                    data.Execute(particleSystemJobData, i);
                }
            }
            AtomicSafetyHandle.CheckDeallocateAndThrow(particleSystemJobData.m_Safety);
            AtomicSafetyHandle.Release(particleSystemJobData.m_Safety);
        }
 public unsafe void Dispose()
 {
     *m_Ptr = 0;
     UnsafeUtility.Free(m_Ptr, m_Allocator);
     AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
     AtomicSafetyHandle.Release(m_Safety);
 }
        void ReleaseTemporaryHandle()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_TemporaryHandle);
            AtomicSafetyHandle.Release(m_TemporaryHandle);
#endif
        }
        public void CompleteAllJobsAndInvalidateArrays()
        {
            if (m_ComponentSafetyHandlesCount == 0)
            {
                return;
            }

            m_InvalidateArraysMarker.Begin();
            for (var i = 0; i != m_ComponentSafetyHandlesCount; i++)
            {
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].BufferHandle);
            }

            for (var i = 0; i != m_ComponentSafetyHandlesCount; i++)
            {
                if (m_ComponentSafetyHandles[i].IsSafetyHandleOwner)
                {
                    AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].SafetyHandle);
                }
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].BufferHandle);
            }

            ClearAllTypeArrayIndices();
            m_InvalidateArraysMarker.End();
        }
        public void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
            DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel);
#endif
            Deallocate();
        }
        public void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
            DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel);
#endif
            NativeHashSetData.DeallocateHashSet(buffer, allocator);
            buffer = null;
        }
        public void CheckDeallocateShouldThrow()
        {
            AtomicSafetyHandle handle = AtomicSafetyHandle.Create();
            AtomicSafetyHandle clone  = handle;

            AtomicSafetyHandle.CheckDeallocateAndThrow(clone);
            AtomicSafetyHandle.Release(handle);
            Assert.Throws <InvalidOperationException>(() => AtomicSafetyHandle.CheckDeallocateAndThrow(clone));
        }
Exemple #13
0
 public void Dispose()
 {
     AtomicSafetyHandle.CheckDeallocateAndThrow(this.m_Safety);
     AtomicSafetyHandle.Release(this.m_Safety);
     DisposeSentinel.Clear(ref this.m_DisposeSentinel);
     UnsafeUtility.Free(this.m_Buffer, this.m_AllocatorLabel);
     this.m_Buffer = IntPtr.Zero;
     this.m_Length = 0;
 }
Exemple #14
0
        internal void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
            AtomicSafetyHandle.Release(m_Safety);
#endif
            UnsafeUtility.Free(m_Impl, Allocator.Persistent);
            m_Impl = null;
        }
 public bool HasBeenDisposed()
 {
     try
     {
         AtomicSafetyHandle.CheckDeallocateAndThrow(Handle);
     }
     catch
     {
         return(true);
     }
     return(false);
 }
Exemple #16
0
        public void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
            if (AtomicSafetyHandle.IsTempMemoryHandle(m_Safety))
            {
                m_Safety = AtomicSafetyHandle.Create();
            }
            AtomicSafetyHandle.Release(m_Safety);
#endif
            m_Impl.Dispose();
        }
Exemple #17
0
        public unsafe static void Execute(ref T data, IntPtr listDataPtr, IntPtr unusedPtr, ref JobRanges ranges, int jobIndex)
        {
            NativeListData *   ptr = (NativeListData *)((void *)listDataPtr);
            NativeParticleData nativeParticleData;

            ParticleSystem.CopyManagedJobData(ptr->system, out nativeParticleData);
            ParticleSystemJobData particleSystemJobData = new ParticleSystemJobData(ref nativeParticleData);

            data.Execute(particleSystemJobData);
            AtomicSafetyHandle.CheckDeallocateAndThrow(particleSystemJobData.m_Safety);
            AtomicSafetyHandle.Release(particleSystemJobData.m_Safety);
        }
        public static unsafe void Execute(ref T data, IntPtr listDataPtr, IntPtr unusedPtr, ref JobRanges ranges, int jobIndex)
        {
            NativeParticleData particleData;
            var listData = (NativeListData *)listDataPtr;

            ParticleSystem.CopyManagedJobData(listData->system, out particleData);

            ParticleSystemJobData jobData = new ParticleSystemJobData(ref particleData);

            data.Execute(jobData);

            AtomicSafetyHandle.CheckDeallocateAndThrow(jobData.m_Safety);
            AtomicSafetyHandle.Release(jobData.m_Safety);
        }
Exemple #19
0
        public static unsafe void ExecuteProcessParticleSystem(ref T data, IntPtr particleSystemPtr, IntPtr unusedPtr, ref JobRanges ranges, int jobIndex)
        {
            JobDataInternal jobDataInternal;

            UnsafeUtility.CopyPtrToStructure((void *)particleSystemPtr, out jobDataInternal);

            object safetyHandle;
            ParticleSystemJobData jobData = new ParticleSystemJobData(ref jobDataInternal, out safetyHandle);

            data.ProcessParticleSystem(jobData);

            AtomicSafetyHandle.CheckDeallocateAndThrow((AtomicSafetyHandle)safetyHandle);
            AtomicSafetyHandle.Release((AtomicSafetyHandle)safetyHandle);
        }
        public void CheckDeallocateShouldThrow()
        {
            AtomicSafetyHandle handle = AtomicSafetyHandle.Create();
                                                                  AtomicSafetyHandle clone = handle;

                                                                  AtomicSafetyHandle.CheckDeallocateAndThrow(clone);
                                                                                                             AtomicSafetyHandle.Release(handle);
#if UNITY_2020_2_OR_NEWER
                                                                                                                                        Assert.Throws <ObjectDisposedException>(
#else
                                                                                                                                        Assert.Throws <InvalidOperationException>(
#endif
                                                                                                                                            () => AtomicSafetyHandle.CheckDeallocateAndThrow(clone));
        }
 public unsafe bool HasBeenDisposed()
 {
     try
     {
         AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
         if (*m_Ptr == 54321)
         {
             return(false);
         }
     }
     catch
     {
         return(true);
     }
     return(false);
 }
        //@TODO: Optimize as one function call to in batch bump version on every single handle...
        public void CompleteAllJobsAndInvalidateArrays()
        {
            if (m_HasCleanHandles)
            {
                return;
            }

            Profiler.BeginSample("CompleteAllJobsAndInvalidateArrays");

            var count = TypeManager.GetTypeCount();

            for (var t = 0; t != count; t++)
            {
                m_ComponentSafetyHandles[t].WriteFence.Complete();

                var readFencesCount = m_ComponentSafetyHandles[t].NumReadFences;
                var readFences      = m_ReadJobFences + t * kMaxReadJobHandles;
                for (var r = 0; r != readFencesCount; r++)
                {
                    readFences[r].Complete();
                }
                m_ComponentSafetyHandles[t].NumReadFences = 0;
            }

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            for (var i = 0; i != count; i++)
            {
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].BufferHandle);
            }

            for (var i = 0; i != count; i++)
            {
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].SafetyHandle);
                m_ComponentSafetyHandles[i].SafetyHandle = AtomicSafetyHandle.Create();
                AtomicSafetyHandle.SetAllowSecondaryVersionWriting(m_ComponentSafetyHandles[i].SafetyHandle, false);

                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].BufferHandle);
                m_ComponentSafetyHandles[i].BufferHandle = AtomicSafetyHandle.Create();
            }
#endif

            m_HasCleanHandles = true;

            Profiler.EndSample();
        }
Exemple #23
0
        public void BeginExclusiveTransaction()
        {
            for (var i = 0; i != m_ComponentSafetyHandlesCount; i++)
            {
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].BufferHandle);
            }

            for (var i = 0; i != m_ComponentSafetyHandlesCount; i++)
            {
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].BufferHandle);
            }

            ExclusiveTransactionSafety = AtomicSafetyHandle.Create();
            ClearAllTypeArrayIndices();
        }
Exemple #24
0
        private unsafe void HandlePositionsChangedCallback(int count, IntPtr positionsIntPtr)
        {
            if (Tilemap.tilemapPositionsChanged == null)
            {
                return;
            }

            void *positionsPtr = positionsIntPtr.ToPointer();
            var   positions    = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Vector3Int>(positionsPtr, count, Allocator.Invalid);
            var   safety       = AtomicSafetyHandle.Create();

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref positions, safety);

            SendTilemapPositionsChangedCallback(positions);

            AtomicSafetyHandle.CheckDeallocateAndThrow(safety);
            AtomicSafetyHandle.Release(safety);
        }
        internal void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckDeallocateAndThrow(m_Safety);
#endif
            if (m_Data != null)
            {
                var label = m_Data->m_Allocator;

                while (m_Data->m_Tail != null)
                {
                    var prev = m_Data->m_Tail->Prev;
                    UnsafeUtility.Free(m_Data->m_Tail, m_Data->m_Allocator);
                    m_Data->m_Tail = prev;
                }

                m_Data->m_Head = null;
                UnsafeUtility.Free(m_Data, label);
                m_Data = null;
            }
        }
        //@TODO: Optimize as one function call to in batch bump version on every single handle...
        public void CompleteAllJobsAndInvalidateArrays()
        {
            if (m_TypeCount == 0)
            {
                return;
            }

            Profiler.BeginSample("CompleteAllJobsAndInvalidateArrays");
            for (int t = 0; t < m_TypeCount; ++t)
            {
                m_ComponentSafetyHandles[t].WriteFence.Complete();

                var readFencesCount = m_ComponentSafetyHandles[t].NumReadFences;
                var readFences      = m_ReadJobFences + t * kMaxReadJobHandles;
                for (var r = 0; r != readFencesCount; r++)
                {
                    readFences[r].Complete();
                }
                m_ComponentSafetyHandles[t].NumReadFences = 0;
            }


#if ENABLE_UNITY_COLLECTIONS_CHECKS
            for (var i = 0; i != m_TypeCount; i++)
            {
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].BufferHandle);
            }

            for (var i = 0; i != m_TypeCount; i++)
            {
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].BufferHandle);
            }
#endif

            ClearAllTypeArrayIndices();
            Profiler.EndSample();
        }
Exemple #27
0
        public void CompleteAllJobsAndInvalidateArrays()
        {
            if (m_ComponentSafetyHandlesCount == 0)
            {
                return;
            }

            Profiler.BeginSample("InvalidateArrays");
            for (var i = 0; i != m_ComponentSafetyHandlesCount; i++)
            {
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.CheckDeallocateAndThrow(m_ComponentSafetyHandles[i].BufferHandle);
            }

            for (var i = 0; i != m_ComponentSafetyHandlesCount; i++)
            {
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].SafetyHandle);
                AtomicSafetyHandle.Release(m_ComponentSafetyHandles[i].BufferHandle);
            }

            ClearAllTypeArrayIndices();
            Profiler.EndSample();
        }
Exemple #28
0
            public bool Complete(TimeSlice timeSlice)
            {
                JobHandle.ScheduleBatchedJobs();
                // Calling 'Complete' can cause rare deadlocks.
                // A slightly less efficient solution is to use the dependenciesDoneEvent.
                // This seems to work without any rare deadlocks.
                //
                // This happens because if Complete is called the main thread may be scheduled to run the
                // job that waits for the main thread job. This will cause a deadlock.
                // dependsOn.Complete();
                dependenciesDoneEvent.WaitOne();
                UnityEngine.Profiling.Profiler.BeginSample("Main thread job");
                bool finished = true;

                try {
                    // Note: if this method throws an exception then finished will be true and the job marked as completed
                    if (job is IJobTimeSliced sliced)
                    {
                        finished = sliced.Execute(timeSlice);
                    }
                    else
                    {
                        job.Execute();
                    }
                } finally {
                    UnityEngine.Profiling.Profiler.EndSample();
                    if (finished)
                    {
                        doneEvent.Set();
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                        AtomicSafetyHandle.CheckDeallocateAndThrow(safetyHandle);
                        AtomicSafetyHandle.Release(safetyHandle);
#endif
                    }
                }
                return(finished);
            }
 public void Dispose()
 {
     AtomicSafetyHandle.CheckDeallocateAndThrow(Handle);
     AtomicSafetyHandle.Release(Handle);
 }