diff --git a/pkg/storer/internal/reserve/reserve.go b/pkg/storer/internal/reserve/reserve.go index 45af6919a4c..25aa8d119a6 100644 --- a/pkg/storer/internal/reserve/reserve.go +++ b/pkg/storer/internal/reserve/reserve.go @@ -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 @@ -55,7 +39,7 @@ type Reserve struct { size atomic.Int64 radius atomic.Uint32 - multx multexLock + multx *multex.Multex st transaction.Storage } @@ -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 {