fusen-render/unique_id.go
2023-07-30 05:11:04 +08:00

24 lines
346 B
Go

package fusenrender
import "sync"
type UniqueId struct {
nodeId uint64
count uint64
mu sync.Mutex
}
func (uid *UniqueId) Get() uint64 {
uid.mu.Lock()
defer uid.mu.Unlock()
uid.count++
return (uid.count << 8) | uid.nodeId
}
func NewUniqueIdd(NodeId uint8) *UniqueId {
return &UniqueId{
nodeId: uint64(NodeId),
count: 0,
}
}