This repository has been archived on 2022-07-30. You can view files and clone it, but cannot push or open issues/pull-requests.
mdb/util_test.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)
}
}