The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
woop/utils/singleton.go

28 lines
454 B

/* This module keeps all struct used as singleton */
package utils
import (
"sync"
"sync/atomic"
)
type UniqueValidatorId struct {
uniqueId uint32
}
var instance *UniqueValidatorId
var once sync.Once
func GetUniqueValidatorIdInstance() *UniqueValidatorId {
once.Do(func() {
instance = &UniqueValidatorId{
uniqueId: 0,
}
})
return instance
}
func (s *UniqueValidatorId) GetUniqueId() uint32 {
return atomic.AddUint32(&s.uniqueId, 1)
}