示例#1
0
        private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <Queue <int>, int> test)
        {
            var pool = QueuePool <int> .Create(C);

            void testCore(Queue <int> queue)
            {
                var len = queue.Count;

                Assert.AreEqual(0, len);

                var L = test(queue);

                len = queue.Count;
                Assert.AreEqual(L, len);
            }

            if (useRAII)
            {
                Run(() => pool.New(), o => o.Queue, o => o.Dispose(), testCore, P, M, noisy);
            }
            else
            {
                Run(() => pool.Allocate(), o => o, o => pool.Free(o), testCore, P, M, noisy);
            }
        }
 public void Dispose()
 {
     if (null != Queue)
     {
         QueuePool.Release(Queue);
     }
 }
示例#3
0
 public void Terminate()
 {
     terminate = true;
     if (queue != null)
     {
         while (!SpinLockNB())
         {
             ;
         }
         QueuePool.Free(queue);
         SpinUnLock();
     }
 }
示例#4
0
        private static void PooledQueue_Simple_Impl(QueuePool <string> pool)
        {
            for (var i = 0; i < 100; i++)
            {
                using var obj = i % 2 == 0 ? pool.New() : PooledQueue <string> .New(pool);

                var queue = obj.Queue;

                Assert.AreEqual(0, queue.Count);

                queue.Enqueue("qux");
                queue.Enqueue("foo");
                queue.Enqueue("bar");
                queue.Enqueue("baz");

                Assert.IsTrue(exp.SequenceEqual(queue));
            }
        }
示例#5
0
        public void PooledQueue_GottenTooBig()
        {
            var bigPool = QueuePool <int> .Create(1, 16, 2048);

            var smallPool = QueuePool <int> .Create(1, 16, 16);

            TooBig(() => PooledQueue <int> .New(), h => h.Queue, (h, n) => { for (var i = 0; i < n; i++)
                                                                             {
                                                                                 h.Enqueue(i);
                                                                             }
                   }, 1024);
            TooBig(() => bigPool.New(), h => h.Queue, (h, n) => { for (var i = 0; i < n; i++)
                                                                  {
                                                                      h.Enqueue(i);
                                                                  }
                   }, 2048);
            TooBig(() => smallPool.New(), h => h.Queue, (h, n) => { for (var i = 0; i < n; i++)
                                                                    {
                                                                        h.Enqueue(i);
                                                                    }
                   }, 16);
        }
示例#6
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            QueuePool qPool = new QueuePool();

            qPool.Store(new Person());
            //Person p = qPool.Fetch();

            QueuePool <Person> qPoolPerson = new QueuePool <Person>();

            qPoolPerson.Store(new Person());
            Person p1 = qPoolPerson.Fetch();

            ObjectPoolObject <Person> pPoolObject = new ObjectPoolObject <Person>(10);
            Person a  = pPoolObject.Get();
            Person a1 = pPoolObject.Get();

            a.Name  = "Sophy";
            a1.Name = "Tammy";

            this.TextBox1.Text += string.Format($"\r\n {a.Name } meet {a1.Name} total employee in the queue {pPoolObject.Count()}");
            this.TextBox1.Text += "\r\nQueue is a Simple DataStucture which allows Add or Remove of Items at one of the ends only. It is basically called as First in First out data structure. Enqueue() and Dequeue()";
        }
示例#7
0
 public FastQueueImpl(object name, int maxSize)
 {
     instanceLog = Factory.SysLog.GetLogger("TickZoom.TickUtil.FastQueue." + name);
     if (debug)
     {
         log.Debug("Created with capacity " + maxSize);
     }
     if (name is string)
     {
         this.name = (string)name;
     }
     else if (name is Type)
     {
         this.name = ((Type)name).Name;
     }
     this.maxSize       = maxSize;
     this.lowWaterMark  = maxSize / 2;
     this.highWaterMark = maxSize / 2;
     queue = QueuePool.Create();
     queue.Clear();
     lock ( locker) {
         queueList.Add(this);
     }
 }
示例#8
0
 public void Start()
 {
     if (this.Running != null)
     {
         //服务已经启动
         return;
     }
     //设置服务为启动状态
     this.Running = false;
     if (this.MessageHandle != null)
     {
         this.AddDelegate(this.MessageHandle);
     }
     if (ExitServiceHandle != null)
     {
         this.AddDelegate(ExitServiceHandle);
     }
     if (false == this.Validate())
     {
         return;
     }
     //验证成功
     //清空所有线程 事件
     this.threadpool   = new QueuePool <ThreadShell>();
     this.delegatepool = new QueuePool <Delegate>();
     //准备启动任务
     Begin();
     if (this.Running.Value)
     {
         this.info("服务启动成功!");
     }
     else
     {
         this.DoExitService();
     }
 }
 internal static PooledQueue <T> Make()
 {
     return(new PooledQueue <T>(QueuePool.Get()));
 }
示例#10
0
        public void Pool_Feed16()
        {
            var tested = new QueuePool <object>(() => new object());

            AbstractPool.Pool_NotNullElement_Feed16(tested);
        }
示例#11
0
        public void Pool_TotalCount_Cycles3()
        {
            var tested = new QueuePool <object>(() => new object());

            AbstractPool.Pool_TotalCount_Cycles3(tested);
        }
 public void Recycle()
 {
     QueuePool <ObjectType, PoolIdentifier> .Free(this);
 }
示例#13
0
    private void Explode(Vector3 pos, int cell, int prev_cell, Element element)
    {
        PlayImpactSound(pos);
        Vector3 pos2 = pos;

        pos2.z = Grid.GetLayerZ(Grid.SceneLayer.FXFront2);
        Game.Instance.SpawnFX(explosionEffectHash, pos2, 0f);
        Substance substance = element.substance;
        int       num       = Random.Range(explosionOreCount.x, explosionOreCount.y + 1);
        Vector2   a         = -velocity.normalized;
        Vector2   a2        = new Vector2(a.y, 0f - a.x);

        ListPool <ScenePartitionerEntry, Comet> .PooledList pooledList = ListPool <ScenePartitionerEntry, Comet> .Allocate();

        GameScenePartitioner.Instance.GatherEntries((int)pos.x - 3, (int)pos.y - 3, 6, 6, GameScenePartitioner.Instance.pickupablesLayer, pooledList);
        foreach (ScenePartitionerEntry item in pooledList)
        {
            GameObject gameObject = (item.obj as Pickupable).gameObject;
            if (!((Object)gameObject.GetComponent <MinionIdentity>() != (Object)null) && gameObject.GetDef <CreatureFallMonitor.Def>() == null)
            {
                Vector2 vector = gameObject.transform.GetPosition() - pos;
                vector  = vector.normalized;
                vector += new Vector2(0f, 0.55f);
                vector *= 0.5f * Random.Range(explosionSpeedRange.x, explosionSpeedRange.y);
                if (GameComps.Fallers.Has(gameObject))
                {
                    GameComps.Fallers.Remove(gameObject);
                }
                if (GameComps.Gravities.Has(gameObject))
                {
                    GameComps.Gravities.Remove(gameObject);
                }
                GameComps.Fallers.Add(gameObject, vector);
            }
        }
        pooledList.Recycle();
        int num2 = splashRadius + 1;

        for (int i = -num2; i <= num2; i++)
        {
            for (int j = -num2; j <= num2; j++)
            {
                int num3 = Grid.OffsetCell(cell, j, i);
                if (Grid.IsValidCell(num3) && !destroyedCells.Contains(num3))
                {
                    float num4 = (1f - (float)Mathf.Abs(j) / (float)num2) * (1f - (float)Mathf.Abs(i) / (float)num2);
                    if (num4 > 0f)
                    {
                        DamageTiles(num3, prev_cell, num4 * totalTileDamage * 0.5f);
                    }
                }
            }
        }
        float mass        = (num <= 0) ? 1f : (explosionMass / (float)num);
        float temperature = Random.Range(explosionTemperatureRange.x, explosionTemperatureRange.y);

        for (int k = 0; k < num; k++)
        {
            Vector2 normalized = (a + a2 * Random.Range(-1f, 1f)).normalized;
            Vector3 v          = normalized * Random.Range(explosionSpeedRange.x, explosionSpeedRange.y);
            Vector3 a3         = normalized.normalized * 0.75f;
            a3 += new Vector3(0f, 0.55f, 0f);
            a3 += pos;
            GameObject go = substance.SpawnResource(a3, mass, temperature, byte.MaxValue, 0, false, false, false);
            if (GameComps.Fallers.Has(go))
            {
                GameComps.Fallers.Remove(go);
            }
            GameComps.Fallers.Add(go, v);
        }
        if (addTiles > 0)
        {
            int   depthOfElement = GetDepthOfElement(cell, element);
            float num5           = 1f - (float)(depthOfElement - addTilesMinHeight) / (float)(addTilesMaxHeight - addTilesMinHeight);
            int   num6           = Mathf.Min(addTiles, Mathf.Clamp(Mathf.RoundToInt((float)addTiles * num5), 1, addTiles));
            HashSetPool <int, Comet> .PooledHashSet pooledHashSet = HashSetPool <int, Comet> .Allocate();

            HashSetPool <int, Comet> .PooledHashSet pooledHashSet2 = HashSetPool <int, Comet> .Allocate();

            QueuePool <GameUtil.FloodFillInfo, Comet> .PooledQueue pooledQueue = QueuePool <GameUtil.FloodFillInfo, Comet> .Allocate();

            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = cell,
                depth = 0
            });
            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = prev_cell,
                depth = 0
            });
            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = Grid.OffsetCell(cell, new CellOffset(-1, 0)),
                depth = 0
            });
            pooledQueue.Enqueue(new GameUtil.FloodFillInfo
            {
                cell  = Grid.OffsetCell(cell, new CellOffset(1, 0)),
                depth = 0
            });
            GameUtil.FloodFillConditional(pooledQueue, SpawnTilesCellTest, pooledHashSet2, pooledHashSet, 10);
            float mass2 = (num6 <= 0) ? 1f : (addTileMass / (float)addTiles);
            UnstableGroundManager component = World.Instance.GetComponent <UnstableGroundManager>();
            foreach (int item2 in pooledHashSet)
            {
                if (num6 <= 0)
                {
                    break;
                }
                component.Spawn(item2, element, mass2, temperature, byte.MaxValue, 0);
                num6--;
            }
            pooledHashSet.Recycle();
            pooledHashSet2.Recycle();
            pooledQueue.Recycle();
        }
    }
示例#14
0
 public void PooledQueue_ArgumentChecking()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => QueuePool <int> .Create(4, -1));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => QueuePool <int> .Create(4, 16, -1));
 }
示例#15
0
        public void PooledQueue_Simple2()
        {
            var pool = QueuePool <string> .Create(4, 16);

            PooledQueue_Simple_Impl(pool);
        }