예제 #1
0
        public ulong Next()
        {
            ulong result = 0;

            System.Threading.SpinLock slock = new System.Threading.SpinLock();
            bool gotLock = false;

            try
            {
                while (!gotLock)
                {
                    slock.Enter(ref gotLock);
                    if (gotLock)
                    {
                        ulong cms = (ulong)mWatch.Elapsed.TotalMilliseconds - InitMillisecond;
                        if (cms != mCurrentMillisecond)
                        {
                            mSeed = 0;
                            mCurrentMillisecond = cms;
                        }
                        result = ((ulong)Group << 48) | (mCurrentMillisecond << 8) | (ulong)mSeed;
                        mSeed++;
                    }
                }
            }
            finally
            {
                if (gotLock)
                {
                    slock.Exit();
                }
            }
            return(result);
        }
예제 #2
0
            /// <summary>
            /// Creates the pool with numberOfBuffers arrays where each buffer is of bufferLength length.
            /// </summary>
            internal Bucket(int bufferLength, int numberOfBuffers, int poolId)
            {
#if SERVERSIDE
                _lock = new System.Threading.SpinLock(System.Diagnostics.Debugger.IsAttached); // only enable thread tracking if debugger is attached; it adds non-trivial overheads to Enter/Exit
#endif
                this._buffers     = new T[numberOfBuffers][];
                this.bufferLength = bufferLength;
                this._poolId      = poolId;
            }
예제 #3
0
 public LocalCache(CachedConfiguration config)
 {
     _config = config;
     _lock = new System.Threading.SpinLock(false);
     _tickTrac = Environment.TickCount;
     TimeOrigin = (uint)Pbs.DateToMsecs(DateTime.UtcNow);
     // init bitmasks for opcodes.
     QuietOps = new BitSet64(xGetQ, xSetQ, xGetKQ, xAddQ, xReplaceQ, xDeleteQ, xIncQ, xDecQ, xFlushQ, xAppendQ, xPrependQ, xQuitQ, xGatQ, xGatKQ);
     ReqsAdds = new BitSet64(xSet, xSetQ, xAdd, xAddQ, xAppend, xAppendQ, xPrepend, xPrependQ, xInc, xIncQ, xDec, xDecQ);
     ReqsSpecial = new BitSet64(xQuit, xQuitQ, xFlush, xVersion, xFlushQ, xStat, xNoop);
     RespWithExt = new BitSet64(xGet, xGetQ, xGetK, xGetKQ);
     RespWithKey = new BitSet64(xGetK, xGetKQ);
     IncDecOps = new BitSet64(xInc, xIncQ, xDec, xDecQ);
     // setup initial memory states.
     _virtual_memory = new WindowsVirtualMemory(config.UseLargePages);
     Stats.Init(config.CacheSize);
     ResetSlabs();
     // calculate hash bits controls.
     _hashBits = 1; _hashMask = _config.HashTableSize - 1;
     for (var i = 1; i < _hashMask; i *= 2) _hashBits++;
     _hashBits -= 1;
     // sign for clock notifications.
     //todo:Clock.System.Append(OnClock, 1000);
 }