auto commit
This commit is contained in:
@@ -5,27 +5,27 @@
|
||||
* 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
|
||||
* 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yitter.IdGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 雪花漂移算法
|
||||
/// </summary>
|
||||
internal class SnowWorkerM1 : ISnowWorker
|
||||
namespace Yitter.IdGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 雪花漂移算法
|
||||
/// </summary>
|
||||
internal class SnowWorkerM1 : ISnowWorker
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础时间
|
||||
/// </summary>
|
||||
protected readonly DateTime BaseTime;
|
||||
protected readonly DateTime BaseTime;
|
||||
|
||||
/// <summary>
|
||||
/// 机器码
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// 机器码
|
||||
/// </summary>
|
||||
protected readonly ushort WorkerId = 0;
|
||||
|
||||
/// <summary>
|
||||
@@ -40,7 +40,7 @@ namespace Yitter.IdGenerator
|
||||
|
||||
/// <summary>
|
||||
/// 最大序列数(含)
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
protected readonly int MaxSeqNumber = 0;
|
||||
|
||||
/// <summary>
|
||||
@@ -57,11 +57,11 @@ namespace Yitter.IdGenerator
|
||||
protected static object _SyncLock = new object();
|
||||
|
||||
protected ushort _CurrentSeqNumber;
|
||||
protected long _LastTimeTick = 0; // -1L
|
||||
protected long _TurnBackTimeTick = 0; // -1L;
|
||||
protected byte _TurnBackIndex = 0;
|
||||
|
||||
protected bool _IsOverCost = false;
|
||||
protected long _LastTimeTick = 0; // -1L
|
||||
protected long _TurnBackTimeTick = 0; // -1L;
|
||||
protected byte _TurnBackIndex = 0;
|
||||
|
||||
protected bool _IsOverCost = false;
|
||||
protected int _OverCostCountInOneTerm = 0;
|
||||
protected int _GenCountInOneTerm = 0;
|
||||
protected int _TermIndex = 0;
|
||||
@@ -71,8 +71,8 @@ namespace Yitter.IdGenerator
|
||||
|
||||
public Action<OverCostActionArg> GenAction { get; set; }
|
||||
|
||||
|
||||
public SnowWorkerM1(IdGeneratorOptions options)
|
||||
|
||||
public SnowWorkerM1(IdGeneratorOptions options)
|
||||
{
|
||||
// 1.BaseTime
|
||||
if (options.BaseTime != DateTime.MinValue)
|
||||
@@ -117,17 +117,17 @@ namespace Yitter.IdGenerator
|
||||
MinSeqNumber = options.MinSeqNumber;
|
||||
|
||||
// 7.Others
|
||||
TopOverCostCount = options.TopOverCostCount;
|
||||
TopOverCostCount = options.TopOverCostCount;
|
||||
if (TopOverCostCount == 0)
|
||||
{
|
||||
TopOverCostCount = 2000;
|
||||
}
|
||||
|
||||
_TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength);
|
||||
_CurrentSeqNumber = options.MinSeqNumber;
|
||||
|
||||
//_BaseTimeTick = BaseTime.Ticks;
|
||||
//_StartTimeTick = (long)(DateTime.UtcNow.Subtract(BaseTime).TotalMilliseconds) - Environment.TickCount;
|
||||
_TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength);
|
||||
_CurrentSeqNumber = options.MinSeqNumber;
|
||||
|
||||
//_BaseTimeTick = BaseTime.Ticks;
|
||||
//_StartTimeTick = (long)(DateTime.UtcNow.Subtract(BaseTime).TotalMilliseconds) - Environment.TickCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace Yitter.IdGenerator
|
||||
{
|
||||
GenAction(arg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginOverCostAction(in long useTimeTick)
|
||||
{
|
||||
@@ -338,11 +338,11 @@ namespace Yitter.IdGenerator
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual long GetCurrentTimeTick()
|
||||
{
|
||||
//return (long)(DateTime.UtcNow - BaseTime).Ticks;
|
||||
//return (long)(_StartTimeTick + Environment.TickCount);
|
||||
return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds;
|
||||
protected virtual long GetCurrentTimeTick()
|
||||
{
|
||||
//return (long)(DateTime.UtcNow - BaseTime).Ticks;
|
||||
//return (long)(_StartTimeTick + Environment.TickCount);
|
||||
return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds;
|
||||
}
|
||||
|
||||
protected virtual long GetNextTimeTick()
|
||||
@@ -364,6 +364,6 @@ namespace Yitter.IdGenerator
|
||||
{
|
||||
return _IsOverCost ? NextOverCostId() : NextNormalId();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user