github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/golinters/goanalysis/load/guard.go (about)

     1  package load
     2  
     3  import (
     4  	"sync"
     5  
     6  	"golang.org/x/tools/go/packages"
     7  )
     8  
     9  type Guard struct {
    10  	loadMutexes map[*packages.Package]*sync.Mutex
    11  	mutex       sync.Mutex
    12  }
    13  
    14  func NewGuard() *Guard {
    15  	return &Guard{
    16  		loadMutexes: map[*packages.Package]*sync.Mutex{},
    17  	}
    18  }
    19  
    20  func (g *Guard) AddMutexForPkg(pkg *packages.Package) {
    21  	g.loadMutexes[pkg] = &sync.Mutex{}
    22  }
    23  
    24  func (g *Guard) MutexForPkg(pkg *packages.Package) *sync.Mutex {
    25  	return g.loadMutexes[pkg]
    26  }
    27  
    28  func (g *Guard) Mutex() *sync.Mutex {
    29  	return &g.mutex
    30  }