Beispiel #1
0
        /// <summary>
        /// Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
        /// </summary>
        /// <remarks>You can call this function dispose of the container immediately after scheduling the job. Pass
        /// the [JobHandle](https://docs.unity3d.com/ScriptReference/Unity.Jobs.JobHandle.html) returned by
        /// the [Job.Schedule](https://docs.unity3d.com/ScriptReference/Unity.Jobs.IJobExtensions.Schedule.html)
        /// method using the `jobHandle` parameter so the job scheduler can dispose the container after all jobs
        /// using it have run.</remarks>
        /// <param name="dependency">All jobs spawned will depend on this JobHandle.</param>
        /// <returns>A new job handle containing the prior handles as well as the handle for the job that deletes
        /// the container.</returns>
        public JobHandle Dispose(JobHandle dependency)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            // [DeallocateOnJobCompletion] is not supported, but we want the deallocation
            // to happen in a thread. DisposeSentinel needs to be cleared on main thread.
            // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling
            // will check that no jobs are writing to the container).
            DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif
            var jobHandle = m_Stream.Dispose(dependency);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.Release(m_Safety);
#endif
            return(jobHandle);
        }
Beispiel #2
0
        /// <summary>
        /// Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
        /// </summary>
        /// <remarks>You can call this function dispose of the container immediately after scheduling the job. Pass
        /// the [JobHandle](https://docs.unity3d.com/ScriptReference/Unity.Jobs.JobHandle.html) returned by
        /// the [Job.Schedule](https://docs.unity3d.com/ScriptReference/Unity.Jobs.IJobExtensions.Schedule.html)
        /// method using the `jobHandle` parameter so the job scheduler can dispose the container after all jobs
        /// using it have run.</remarks>
        /// <param name="jobHandle">The job handle or handles for any scheduled jobs that use this container.</param>
        /// <returns>A new job handle containing the prior handles as well as the handle for the job that deletes
        /// the container.</returns>
        public JobHandle Dispose(JobHandle inputDeps)
        {
            // [DeallocateOnJobCompletion] is not supported, but we want the deallocation
            // to happen in a thread. DisposeSentinel needs to be cleared on main thread.
            // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling
            // will check that no jobs are writing to the container).
            DisposeSentinel.Clear(ref m_DisposeSentinel);
            var jobHandle = new DisposeJob {
                Container = this
            }.Schedule(inputDeps);

            AtomicSafetyHandle.Release(m_Safety);
            m_Buffer = null;
            m_Length = 0;

            return(jobHandle);
        }
Beispiel #3
0
        /// <summary>
        /// Safely disposes of this list and deallocates its memory when the jobs that use it have completed.
        /// </summary>
        /// <remarks>You can call this function dispose of the list immediately after scheduling the job. Pass
        /// the [JobHandle](https://docs.unity3d.com/ScriptReference/Unity.Jobs.JobHandle.html) returned by
        /// the [Job.Schedule](https://docs.unity3d.com/ScriptReference/Unity.Jobs.IJobExtensions.Schedule.html)
        /// method using the `jobHandle` parameter so the job scheduler can dispose the list after all jobs
        /// using it have run.</remarks>
        /// <param name="jobHandle">The job handle or handles for any scheduled jobs that use this list.</param>
        /// <returns>A new job handle containing the prior handles as well as the handle for the job that deletes
        /// the list.</returns>
        public JobHandle Dispose(JobHandle jobHandle)
        {
            // [DeallocateOnJobCompletion] is not supported, but we want the deallocation to happen in a thread.
            // DisposeSentinel needs to be cleared on main thread.
            // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling will check that no jobs are writing to the container)
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif
            var jobData = new DisposeListJob {
                List = this
            };
            jobHandle  = jobData.Schedule(jobHandle);
            m_ListData = null;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.Release(m_Safety);
#endif

            return(jobHandle);
        }
Beispiel #4
0
        public JobHandle Dispose(JobHandle inputDeps)
        {
            bool flag = this.m_AllocatorLabel == Allocator.Invalid;

            if (flag)
            {
                throw new InvalidOperationException("The NativeArray can not be Disposed because it was not allocated with a valid allocator.");
            }
            bool flag2 = this.m_Buffer == null;

            if (flag2)
            {
                throw new InvalidOperationException("The NativeArray is already disposed.");
            }
            bool      flag3 = this.m_AllocatorLabel > Allocator.None;
            JobHandle result;

            if (flag3)
            {
                DisposeSentinel.Clear(ref this.m_DisposeSentinel);
                JobHandle jobHandle = new NativeArrayDisposeJob
                {
                    Data = new NativeArrayDispose
                    {
                        m_Buffer         = this.m_Buffer,
                        m_AllocatorLabel = this.m_AllocatorLabel,
                        m_Safety         = this.m_Safety
                    }
                }.Schedule(inputDeps);
                AtomicSafetyHandle.Release(this.m_Safety);
                this.m_Buffer         = null;
                this.m_Length         = 0;
                this.m_AllocatorLabel = Allocator.Invalid;
                result = jobHandle;
            }
            else
            {
                this.m_Buffer = null;
                this.m_Length = 0;
                result        = inputDeps;
            }
            return(result);
        }
Beispiel #5
0
        public JobHandle Dispose(JobHandle inputDeps)
        {
            if (m_Buffer == null)
            {
                return(inputDeps);
            }
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif
            var jobHandle = new DisposeJob {
                Container = this
            }.Schedule(inputDeps);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.Release(m_Safety);
#endif
            m_Buffer = null;

            return(jobHandle);
        }
Beispiel #6
0
        public JobHandle ScheduleDispose(JobHandle inputDeps)
        {
            // [DeallocateOnJobCompletion] is not supported, but we want the deallocation to happen in a thread.
            // DisposeSentinel needs to be cleared on main thread.
            // AtomicSafetyHandle can be destroyed after the job was scheduled
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif
            var jobHandle = new DisposeJob {
                BlockStream = this
            }.Schedule(inputDeps);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.Release(m_Safety);
#endif

            m_Block = null;

            return(jobHandle);
        }
        public JobHandle Dispose(JobHandle inputDeps)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            // [DeallocateOnJobCompletion] is not supported, but we want the deallocation
            // to happen in a thread. DisposeSentinel needs to be cleared on main thread.
            // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling
            // will check that no jobs are writing to the container).
            DisposeSentinel.Clear(ref m_DisposeSentinel);

            var jobHandle = new UnsafeDisposeJob {
                vertices = m_Vertices, chainedIndices = m_ChainedIndices, hashTable = m_HashTable, allocator = m_AllocatorLabel
            }.Schedule(inputDeps);

            AtomicSafetyHandle.Release(m_Safety);
#else
            var jobHandle = new UnsafeDisposeJob {
                vertices = m_Vertices, chainedIndices = m_ChainedIndices, hashTable = m_HashTable, allocator = m_AllocatorLabel
            }.Schedule(inputDeps);
#endif
            return(jobHandle);
        }
Beispiel #8
0
        public JobHandle Dispose(JobHandle dependsOn)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Clear(ref m_DisposeSentinel);

            var jobHandle = new NativeArrayViewHandleDisposeJob
            {
                Data = new NativeArrayViewHandleDispose(m_GCHandle, m_Safety),
            }
            .Schedule(dependsOn);

            AtomicSafetyHandle.Release(m_Safety);
            return(jobHandle);
#else
            return(new NativeArrayViewHandleDisposeJob
            {
                Data = new NativeArrayViewHandleDispose(m_GCHandle),
            }
                   .Schedule(dependsOn));
#endif
        }
Beispiel #9
0
        public JobHandle Dispose(JobHandle inputDeps)
        {
            if (m_AllocatorLabel == Allocator.Invalid)
            {
                throw new InvalidOperationException("The NativeArray can not be Disposed because it was not allocated with a valid allocator.");
            }

            if (m_Buffer == null)
            {
                throw new InvalidOperationException("The NativeArray is already disposed.");
            }

            if (m_AllocatorLabel > Allocator.None)
            {
                // [DeallocateOnJobCompletion] is not supported, but we want the deallocation
                // to happen in a thread. DisposeSentinel needs to be cleared on main thread.
                // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling
                // will check that no jobs are writing to the container).
                DisposeSentinel.Clear(ref m_DisposeSentinel);

                var jobHandle = new NativeArrayDisposeJob {
                    Data = new NativeArrayDispose {
                        m_Buffer = m_Buffer, m_AllocatorLabel = m_AllocatorLabel, m_Safety = m_Safety
                    }
                }.Schedule(inputDeps);

                AtomicSafetyHandle.Release(m_Safety);

                m_Buffer         = null;
                m_Length         = 0;
                m_AllocatorLabel = Allocator.Invalid;

                return(jobHandle);
            }

            m_Buffer = null;
            m_Length = 0;

            return(inputDeps);
        }
Beispiel #10
0
        public JobHandle Dispose(JobHandle inputDeps)
        {
            CheckNotDisposed();

            if (CollectionHelper.ShouldDeallocate(m_AllocatorLabel))
            {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                // [DeallocateOnJobCompletion] is not supported, but we want the deallocation
                // to happen in a thread. DisposeSentinel needs to be cleared on main thread.
                // AtomicSafetyHandle can be destroyed after the job was scheduled (Job scheduling
                // will check that no jobs are writing to the container).
                DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif

                var jobHandle = new NativeReferenceDisposeJob
                {
                    Data = new NativeReferenceDispose
                    {
                        m_Data           = m_Data,
                        m_AllocatorLabel = m_AllocatorLabel,
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                        m_Safety = m_Safety
#endif
                    }
                }.Schedule(inputDeps);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
                AtomicSafetyHandle.Release(m_Safety);
#endif

                m_Data           = null;
                m_AllocatorLabel = Allocator.Invalid;

                return(jobHandle);
            }

            m_Data = null;

            return(inputDeps);
        }
Beispiel #11
0
        /// <summary>
        /// Schedule a job to release the set's unmanaged memory after the given
        /// dependency jobs. Do not use it after this job executes. Do
        /// not call <see cref="Dispose()"/> on copies of the set either.
        ///
        /// This operation requires write access.
        ///
        /// This complexity of this operation is O(1) plus the allocator's
        /// deallocation complexity.
        /// </summary>
        public JobHandle Dispose(JobHandle inputDeps)
        {
            RequireWriteAccess();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            // Clear the dispose sentinel, but don't Dispose it
            DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif

            // Schedule the job
            DisposeJob disposeJob = new DisposeJob {
                Set = this
            };
            JobHandle jobHandle = disposeJob.Schedule(inputDeps);

            // Release the atomic safety handle now that the job is scheduled
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.Release(m_Safety);
#endif

            m_State = null;
            return(jobHandle);
        }
        public unsafe JobHandle Dispose(JobHandle inputDeps)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Clear(ref m_DisposeSentinel);
#endif
            JobHandle jobHandle = new TypeHandleArrayDisposeJob()
            {
                DisposeJobData = new TypeHandleArrayDisposeJobData()
                {
                    m_Buffer         = m_Buffer,
                    m_AllocatorLabel = m_AllocatorLabel,
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                    m_Safety = m_Safety
#endif
                }
            }.Schedule(inputDeps);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.Release(m_Safety);
#endif
            m_Buffer = (void *)null;
            m_Length = 0;
            return(jobHandle);
        }
 public void Dispose()
 {
     DisposeSentinel.Clear(ref m_DisposeSentinel);
 }