
* update staticcheck Don't fork staticcheck: use the upstream version. Remove unneeded SSA loading. * Cache go/analysis facts Don't load unneeded packages for go/analysis. Repeated run of go/analysis linters now 10x faster (2s vs 20s on this repo) than before.
36 lines
638 B
Go
36 lines
638 B
Go
package load
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"golang.org/x/tools/go/packages"
|
|
)
|
|
|
|
type Guard struct {
|
|
loadMutexes map[*packages.Package]*sync.Mutex
|
|
mutexForExportData sync.Mutex
|
|
mutex sync.Mutex
|
|
}
|
|
|
|
func NewGuard() *Guard {
|
|
return &Guard{
|
|
loadMutexes: map[*packages.Package]*sync.Mutex{},
|
|
}
|
|
}
|
|
|
|
func (g *Guard) AddMutexForPkg(pkg *packages.Package) {
|
|
g.loadMutexes[pkg] = &sync.Mutex{}
|
|
}
|
|
|
|
func (g *Guard) MutexForPkg(pkg *packages.Package) *sync.Mutex {
|
|
return g.loadMutexes[pkg]
|
|
}
|
|
|
|
func (g *Guard) MutexForExportData() *sync.Mutex {
|
|
return &g.mutexForExportData
|
|
}
|
|
|
|
func (g *Guard) Mutex() *sync.Mutex {
|
|
return &g.mutex
|
|
}
|