示例#1
0
        /// <summary>
        /// Accepts the invite to a <see cref="IGuild"/>. This method will also make sure that this member
        /// has an outstanding invite to the guild.
        /// </summary>
        /// <param name="guild">The guild to join.</param>
        /// <param name="currentTime">The current time.</param>
        /// <returns>
        /// True if this member successfully joined the <paramref name="guild"/>; otherwise false.
        /// </returns>
        public bool AcceptInvite(IGuild guild, TickCount currentTime)
        {
            if (Owner.Guild != null)
            {
                return(false);
            }

            if (guild == null)
            {
                return(false);
            }

            // Update the invites
            UpdateInvites(currentTime);

            // Make sure there is an invite to this guild
            if (!_invites.Any(x => x.Guild == guild))
            {
                return(false);
            }

            // Join the guild
            Owner.Guild = guild;

            // Remove all outstanding invites
            foreach (var current in _invites)
            {
                _guildInvitePool.Free(current);
            }

            _invites.Clear();

            return(true);
        }
示例#2
0
        public void Free_WhenCalledAfterItemIsAdded_ShouldReturnAlreadyCreatedInstanceToPoolSoLaterCanBeReused()
        {
            // Arrange
            var firstInstace = sut.Allocate();

            // Act
            sut.Free(firstInstace);

            // Assert
            Assert.AreSame(firstInstace, sut.Allocate());
        }
 public void Free()
 {
     if (pool != null)
     {
         pool.Free(this.target);
     }
 }
示例#4
0
 public void Free()
 {
     if (pool != null)
     {
         pool.Free(this.gameObject);
     }
 }
示例#5
0
        /// <summary>
        /// Returns item to pool
        /// </summary>
        public void Dispose()
        {
            IObjectPool <T> localPool = Interlocked.Exchange(ref pool, null);

            if (localPool != null)
            {
                OnResetState();
                localPool.Free((T)this);
            }
        }
        public void Dispose()
        {
            IObjectPool <T> localPool = Interlocked.Exchange(ref pool, null);

            if (localPool != null)
            {
                OnDispose();
                localPool.Free(this as T);
            }
        }
示例#7
0
        public void TestPool(IObjectPool <DummyPoolable> pool)
        {
            var sw = new Stopwatch();
            //while (true) {
            int gen0 = GC.CollectionCount(0);

            sw.Restart();
            Task.WaitAll(Enumerable.Range(0, Environment.ProcessorCount * 2).Select(_ => Task.Run(() =>
            {
                for (int i = 0; i < 1000000; i++)
                {
                    var x1 = pool.Allocate();
                    var x2 = pool.Allocate();
                    Interlocked.MemoryBarrier();
                    //Thread.SpinWait(500);
                    pool.Free(x1);
                    pool.Free(x2);
                }
            })).ToArray());
            sw.Stop();
            Console.WriteLine(pool.GetType().Name + ": " + sw.Elapsed + " " + (GC.CollectionCount(0) - gen0) + " count:" + pool.Count);
            //}
        }
示例#8
0
        /// <summary>
        /// Writes the log event to the underlying logger.
        /// </summary>
        /// <param name="callerMemberName">The method or property name of the caller to the method. This is set at by the compiler.</param>
        /// <param name="callerFilePath">The full path of the source file that contains the caller. This is set at by the compiler.</param>
        /// <param name="callerLineNumber">The line number in the source file at which the method is called. This is set at by the compiler.</param>
        public void Write(
            [CallerMemberName] string callerMemberName = null,
            [CallerFilePath] string callerFilePath     = null,
            [CallerLineNumber] int callerLineNumber    = 0)
        {
            if (callerMemberName != null)
            {
                _data.MemberName = callerMemberName;
            }
            if (callerFilePath != null)
            {
                _data.FilePath = callerFilePath;
            }
            if (callerLineNumber != 0)
            {
                _data.LineNumber = callerLineNumber;
            }

            _writer.WriteLog(_data);

            // return to object pool
            _objectPool?.Free(this);
        }
示例#9
0
 /// <summary>
 /// When overridden in the derived class, performs disposing of the object.
 /// </summary>
 protected override void HandleDispose()
 {
     _objectPool.Free(this);
 }