|
|
@@ -13,7 +13,6 @@ pub struct YitIdHelper; |
|
|
|
static mut idGenInstance: Option<Arc<Mutex<DefaultIdGenerator>>> = None;
|
|
|
|
|
|
|
|
impl YitIdHelper {
|
|
|
|
|
|
|
|
fn IdGenInstance() -> Arc<Mutex<DefaultIdGenerator>> {
|
|
|
|
unsafe {
|
|
|
|
idGenInstance.get_or_insert_with(|| {
|
|
|
@@ -28,6 +27,13 @@ impl YitIdHelper { |
|
|
|
idgen.Worker.SetOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn SetWorkerId(workerId: u32) {
|
|
|
|
let mut idgenArc = YitIdHelper::IdGenInstance();
|
|
|
|
let mut idgen = idgenArc.lock().unwrap();
|
|
|
|
let mut options = IdGeneratorOptions::New(workerId);
|
|
|
|
idgen.Worker.SetOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn NextId() -> i64 {
|
|
|
|
let mut idgenArc = YitIdHelper::IdGenInstance();
|
|
|
|
let mut idgen = idgenArc.lock().unwrap();
|
|
|
|