use a named lock instead of a single per-pool mutex.
This commit is contained in:
12
utils.go
12
utils.go
@@ -3,10 +3,22 @@ package nostr
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/dgraph-io/ristretto/z"
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
const MAX_LOCKS = 50
|
||||
|
||||
var namedMutexPool = make([]sync.Mutex, MAX_LOCKS)
|
||||
|
||||
func namedLock(name string) (unlock func()) {
|
||||
idx := z.MemHashString(name) % MAX_LOCKS
|
||||
namedMutexPool[idx].Lock()
|
||||
return namedMutexPool[idx].Unlock
|
||||
}
|
||||
|
||||
func similar[E constraints.Ordered](as, bs []E) bool {
|
||||
if len(as) != len(bs) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user