mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-07 06:39:54 +02:00
remove dependency for github.com/dgraph-io/ristretto/z
dgraph-io/ristretto use google/glog. glog rewrites flags on its own, which causes unexpected behaviour.
This commit is contained in:
committed by
fiatjaf_
parent
781aecc6ac
commit
8b1839bfc1
10
helpers.go
10
helpers.go
@ -1,9 +1,10 @@
|
|||||||
package nostr
|
package nostr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/dgraph-io/ristretto/z"
|
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,8 +12,13 @@ const MAX_LOCKS = 50
|
|||||||
|
|
||||||
var namedMutexPool = make([]sync.Mutex, MAX_LOCKS)
|
var namedMutexPool = make([]sync.Mutex, MAX_LOCKS)
|
||||||
|
|
||||||
|
//go:noescape
|
||||||
|
//go:linkname memhash runtime.memhash
|
||||||
|
func memhash(p unsafe.Pointer, h, s uintptr) uintptr
|
||||||
|
|
||||||
func namedLock(name string) (unlock func()) {
|
func namedLock(name string) (unlock func()) {
|
||||||
idx := z.MemHashString(name) % MAX_LOCKS
|
ss := (*reflect.StringHeader)(unsafe.Pointer(&name))
|
||||||
|
idx := uint64(memhash(unsafe.Pointer(ss.Data), 0, uintptr(ss.Len))) % MAX_LOCKS
|
||||||
namedMutexPool[idx].Lock()
|
namedMutexPool[idx].Lock()
|
||||||
return namedMutexPool[idx].Unlock
|
return namedMutexPool[idx].Unlock
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user