This repository has been archived on 2022-07-30. You can view files and clone it, but cannot push or open issues/pull-requests.
2022-07-26 12:02:32 +00:00
|
|
|
package mdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"encoding/hex"
|
|
|
|
mrand "math/rand"
|
2022-07-28 05:29:10 +00:00
|
|
|
"sync/atomic"
|
2022-07-26 12:02:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func randString() string {
|
|
|
|
buf := make([]byte, 1+mrand.Intn(10))
|
|
|
|
if _, err := rand.Read(buf); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return hex.EncodeToString(buf)
|
|
|
|
}
|
2022-07-28 05:29:10 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|