public void AtomicDataResource_Allocate_Deallocate_InJob() { const int MAX = 5000; var resource = new AtomicFloatResource(MAX, Allocator.Persistent); var holder = new NativeArray <AtomicFloat>(MAX, Allocator.Persistent); var job0 = new Job0() { resource = resource, holder = holder, }; job0.Schedule(MAX, 32).Complete(); Assert.AreEqual(MAX, resource.getCountInUse()); var job1 = new Job1() { resource = resource, holder = holder, }; job1.Schedule(MAX, 32).Complete(); Assert.AreEqual(0, resource.getCountInUse()); holder.Dispose(); resource.Dispose(); }
public void AtomicDataResource_Atomic_Self_Dispose_Repeating() { const int MAX = 5000; var resource = new AtomicFloatResource(MAX, Allocator.Persistent); var holder = new NativeArray <AtomicFloat>(MAX, Allocator.Persistent); AtomicFloat special_afloat = new AtomicFloat(); for (var k = 0; k < 8; ++k) { var job0 = new Job0() { resource = resource, holder = holder, }; job0.Schedule(MAX, 32).Complete(); Assert.AreEqual(MAX, resource.getCountInUse()); if (k == 0) { special_afloat = holder[MAX / 3]; } for (var i = 0; i < MAX; ++i) { var afloat = holder[i]; Assert.IsTrue(afloat.Exists()); } var job3 = new Job3() { holder = holder, }; job3.Schedule(MAX, 32).Complete(); Assert.AreEqual(0, resource.getCountInUse()); for (var i = 0; i < MAX; ++i) { var afloat = holder[i]; Assert.IsFalse(afloat.Exists()); } } { var job0 = new Job0() { resource = resource, holder = holder, }; job0.Schedule(MAX, 32).Complete(); Assert.AreEqual(MAX, resource.getCountInUse()); // all slots are in use. Assert.IsFalse(special_afloat.Exists()); // too old. } holder.Dispose(); resource.Dispose(); }
public void NativeBucket_Job0() { int NUM = 1024; var bucket = new NativeBucket <int>(NUM, Allocator.Persistent); var job = new Job0(); job.bucket = bucket; job.Schedule(NUM, 8).Complete(); Assert.AreEqual(bucket.Length, NUM); bucket.Dispose(); }
public void NativeLimitedCounter_JustTheNumber() { const int MAX = 1000; var counter = new NativeLimitedCounter(Allocator.Persistent); var job = new Job0(); job.counter = counter; job.maximum = MAX; job.Schedule(MAX, 32).Complete(); Assert.AreEqual(MAX, counter.Count); counter.Dispose(); }
public void AtomicDataResource_Atomic_Self_Dispose() { const int MAX = 5000; var resource = new AtomicFloatResource(MAX, Allocator.Persistent); var holder = new NativeArray <AtomicFloat>(MAX, Allocator.Persistent); var job0 = new Job0() { resource = resource, holder = holder, }; job0.Schedule(MAX, 32).Complete(); Assert.AreEqual(MAX, resource.getCountInUse()); for (var i = 0; i < MAX; ++i) { var afloat = holder[i]; Assert.IsTrue(afloat.Exists()); } var job3 = new Job3() { holder = holder, }; job3.Schedule(MAX, 32).Complete(); Assert.AreEqual(0, resource.getCountInUse()); for (var i = 0; i < MAX; ++i) { var afloat = holder[i]; Assert.IsFalse(afloat.Exists()); } holder.Dispose(); resource.Dispose(); }