code refactor

This commit is contained in:
MaysWind
2023-09-02 00:05:31 +08:00
parent b0fc5752e2
commit 158563f387
2 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -35,7 +35,7 @@ type InternalUuidInfo struct {
// InternalUuidGenerator represents internal bundled uuid generator
type InternalUuidGenerator struct {
uuidSeqNumbers [1 << internalUuidTypeBits]uint64
uuidSeqNumbers [1 << internalUuidTypeBits]atomic.Uint64
uuidServerId uint8
}
@@ -71,7 +71,7 @@ func (u *InternalUuidGenerator) GenerateUuids(idType UuidType, count uint8) []in
for {
unixTime = uint64(time.Now().Unix())
newLastSeqId = atomic.AddUint64(&u.uuidSeqNumbers[uuidType], uint64(count))
newLastSeqId = u.uuidSeqNumbers[uuidType].Add(uint64(count))
if newLastSeqId>>seqNumberIdBits == unixTime {
newFirstSeqId = newLastSeqId - uint64(count-1)
@@ -82,7 +82,7 @@ func (u *InternalUuidGenerator) GenerateUuids(idType UuidType, count uint8) []in
newFirstSeqId = unixTime << seqNumberIdBits
newLastSeqId = newFirstSeqId + uint64(count-1)
if atomic.CompareAndSwapUint64(&u.uuidSeqNumbers[uuidType], currentSeqId, newLastSeqId) {
if u.uuidSeqNumbers[uuidType].CompareAndSwap(currentSeqId, newLastSeqId) {
break
}
}