fusen-render/unique_id.go

24 lines
346 B
Go
Raw Normal View History

2023-07-29 21:11:04 +00:00
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,
}
}