fusen-render/unique_id.go
2023-08-03 18:34:20 +08:00

24 lines
345 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 NewUniqueId(NodeId uint8) *UniqueId {
return &UniqueId{
nodeId: uint64(NodeId),
count: 0,
}
}