33 lines
476 B
Go
33 lines
476 B
Go
package mdb
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
mrand "math/rand"
|
|
"sync/atomic"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|