Xprize update

Former-commit-id: d38919a897961e4d40da3b844057c3fb94fdb6d7
This commit is contained in:
Eric Coissac
2024-07-25 18:09:03 -04:00
parent 4e4fac491f
commit 67665a6b40
18 changed files with 895 additions and 29 deletions

42
pkg/obiutils/counter.go Normal file
View File

@ -0,0 +1,42 @@
package obiutils
import "sync"
type Counter struct {
Inc func() int
Dec func() int
Value func() int
}
func NewCounter(initial ...int) *Counter {
value := 0
lock := sync.Mutex{}
if len(initial) > 0 {
value = initial[0]
}
c := Counter{
Inc: func() int {
lock.Lock()
defer lock.Unlock()
value++
return value
},
Dec: func() int {
lock.Lock()
defer lock.Unlock()
value--
return value
},
Value: func() int {
lock.Lock()
defer lock.Unlock()
return value
},
}
return &c
}

12
pkg/obiutils/strings.go Normal file
View File

@ -0,0 +1,12 @@
package obiutils
import "unsafe"
func UnsafeStringFreomBytes(data []byte) string {
if len(data) > 0 {
s := unsafe.String(unsafe.SliceData(data), len(data))
return s
}
return ""
}