コード例 #1
0
ファイル: Sharpflake.cs プロジェクト: inthefabric/Fabric
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public int GetNextIndex(out long pMilli)
        {
            long m;
            int  i;

            lock (this) {
                m = Sharpflake.GetMilli();

                if (m > vLastMilli)
                {
                    vLastMilli = m;
                    vIndex     = 0;
                }
                else if (++vIndex >= Sharpflake.SequenceMax)
                {
                    m      = SpinUntilNextMilli();
                    vIndex = 0;
                }

                i = vIndex;                 //capture value before leaving the lock
            }

            pMilli = m;
            return(i);
        }
コード例 #2
0
ファイル: Sharpflake.cs プロジェクト: inthefabric/Fabric
        /*--------------------------------------------------------------------------------------------*/
        private long SpinUntilNextMilli()
        {
            long m = Sharpflake.GetMilli();

            while (m <= vLastMilli)
            {
                m = Sharpflake.GetMilli();
            }

            vLastMilli = m;
            return(m);
        }