mirror of
https://github.com/minio/minio.git
synced 2025-02-28 13:59:15 -05:00
fix: replace mutex with atomic (#20762)
This commit is contained in:
parent
86d02b17cf
commit
2b008c598b
@ -29,6 +29,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
@ -182,8 +183,7 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
|
|||||||
resultsDone := make(chan metaCacheEntriesSorted)
|
resultsDone := make(chan metaCacheEntriesSorted)
|
||||||
// Copy so we can mutate
|
// Copy so we can mutate
|
||||||
resCh := resultsDone
|
resCh := resultsDone
|
||||||
var done bool
|
var done atomic.Bool
|
||||||
var mu sync.Mutex
|
|
||||||
resErr := io.EOF
|
resErr := io.EOF
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -194,9 +194,7 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
|
|||||||
// past limit
|
// past limit
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mu.Lock()
|
returned = done.Load()
|
||||||
returned = done
|
|
||||||
mu.Unlock()
|
|
||||||
if returned {
|
if returned {
|
||||||
resCh = nil
|
resCh = nil
|
||||||
continue
|
continue
|
||||||
@ -250,9 +248,7 @@ func (o *listPathOptions) gatherResults(ctx context.Context, in <-chan metaCache
|
|||||||
return func() (metaCacheEntriesSorted, error) {
|
return func() (metaCacheEntriesSorted, error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
mu.Lock()
|
done.Store(true)
|
||||||
done = true
|
|
||||||
mu.Unlock()
|
|
||||||
return metaCacheEntriesSorted{}, ctx.Err()
|
return metaCacheEntriesSorted{}, ctx.Err()
|
||||||
case r := <-resultsDone:
|
case r := <-resultsDone:
|
||||||
return r, resErr
|
return r, resErr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user