public long NextId()
{
var incrementedCurrentLow = Interlocked.Increment(ref currentLo);
if (incrementedCurrentLow > Capacity)
{
lock (generatorLock)
{
if (Thread.VolatileRead(ref currentLo) > Capacity)
{
currentHi = GetNextHi();
currentLo = 1;
incrementedCurrentLow = 1;
}
}
}
return (currentHi - 1)*Capacity + (incrementedCurrentLow);
}