From acaefa52f5e71817e6ae5dcb67c2c81c6b596196 Mon Sep 17 00:00:00 2001 From: yitter Date: Mon, 5 Apr 2021 15:01:33 +0800 Subject: [PATCH] auto commit --- Go/source/idgen/YitIdHelper.go | 48 +++------------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) diff --git a/Go/source/idgen/YitIdHelper.go b/Go/source/idgen/YitIdHelper.go index e1084b3..7aeeb5c 100644 --- a/Go/source/idgen/YitIdHelper.go +++ b/Go/source/idgen/YitIdHelper.go @@ -1,68 +1,28 @@ -/* - * 版权属于:yitter(yitter@126.com) - * 代码编辑:guoyahao - * 代码修订:yitter - * 开源地址:https://gitee.com/yitter/idgenerator - */ package idgen import ( "sync" ) -//var yitIdHelper *YitIdHelper -//var once sync.Once - -var idGenerator *DefaultIdGenerator var singletonMutex sync.Mutex +var idGenerator *DefaultIdGenerator -type YitIdHelper struct { - idGenInstance interface { - NewLong() uint64 - } -} - -// -//func GetIns() *YitIdHelper { -// once.Do(func() { -// yitIdHelper = &YitIdHelper{} -// }) -// return yitIdHelper -//} -// -//func (yih *YitIdHelper) GetIdGenInstance() interface{} { -// return yih.idGenInstance -//} -// -//func (yih *YitIdHelper) SetIdGenerator(options *contract.IdGeneratorOptions) { -// yih.idGenInstance = NewDefaultIdGenerator(options) -//} -// -//func (yih *YitIdHelper) NextId() uint64 { -// once.Do(func() { -// if yih.idGenInstance == nil { -// options := contract.NewIdGeneratorOptions(1) -// yih.idGenInstance = NewDefaultIdGenerator(options) -// } -// }) -// -// return yih.idGenInstance.NewLong() -//} - +// SetIdGenerator . func SetIdGenerator(options *IdGeneratorOptions) { singletonMutex.Lock() idGenerator = NewDefaultIdGenerator(options) singletonMutex.Unlock() } +// NextId . func NextId() uint64 { if idGenerator == nil { singletonMutex.Lock() + defer singletonMutex.Unlock() if idGenerator == nil { options := NewIdGeneratorOptions(1) idGenerator = NewDefaultIdGenerator(options) } - singletonMutex.Unlock() } return idGenerator.NewLong()