Skip to content

Commit

Permalink
fix: use resenje multex (#4883)
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill authored Oct 30, 2024
1 parent a50e693 commit 074602b
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions pkg/storer/internal/reserve/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,11 @@ import (
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/ethersphere/bee/v2/pkg/topology"
"golang.org/x/sync/errgroup"
"resenje.org/multex"
)

const reserveScope = "reserve"

type multexLock struct {
mul map[string]struct{}
mu chan struct{}
}

func (m *multexLock) Lock(id string) {
m.mu <- struct{}{}
m.mul[id] = struct{}{}
<-m.mu
}

func (m *multexLock) Unlock(id string) {
m.mu <- struct{}{}
delete(m.mul, id)
<-m.mu
}

type Reserve struct {
baseAddr swarm.Address
radiusSetter topology.SetStorageRadiuser
Expand All @@ -55,7 +39,7 @@ type Reserve struct {
size atomic.Int64
radius atomic.Uint32

multx multexLock
multx *multex.Multex
st transaction.Storage
}

Expand All @@ -73,7 +57,7 @@ func New(
capacity: capacity,
radiusSetter: radiusSetter,
logger: logger.WithName(reserveScope).Register(),
multx: multexLock{mul: make(map[string]struct{}), mu: make(chan struct{}, 1)},
multx: multex.New(),
}

err := st.Run(context.Background(), func(s transaction.Store) error {
Expand Down

0 comments on commit 074602b

Please sign in to comment.