48 lines
764 B
Go
48 lines
764 B
Go
package mdb
|
|
|
|
/*Copyright (c) 2022, John David Lee
|
|
All rights reserved.
|
|
|
|
This source code is licensed under the BSD-style license found in the
|
|
LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
mrand "math/rand"
|
|
"sync/atomic"
|
|
)
|
|
|
|
func randStringShort() string {
|
|
s := randString()
|
|
if len(s) > 2 {
|
|
return s[:2]
|
|
}
|
|
return s
|
|
}
|
|
|
|
func randString() string {
|
|
buf := make([]byte, 1+mrand.Intn(10))
|
|
if _, err := rand.Read(buf); err != nil {
|
|
panic(err)
|
|
}
|
|
return hex.EncodeToString(buf)
|
|
}
|
|
|
|
type atomicBool struct {
|
|
i int64
|
|
}
|
|
|
|
func (a *atomicBool) Get() bool {
|
|
return atomic.LoadInt64(&a.i) == 1
|
|
}
|
|
|
|
func (a *atomicBool) Set(b bool) {
|
|
if b {
|
|
atomic.StoreInt64(&a.i, 1)
|
|
} else {
|
|
atomic.StoreInt64(&a.i, 0)
|
|
}
|
|
}
|