Add staticcheck tool

This commit is contained in:
dwrz
2026-06-06 01:17:20 +00:00
parent 6fb63c8c90
commit ad58cd78ff
315 changed files with 56337 additions and 4 deletions

View File

@@ -0,0 +1,36 @@
package sync
type Semaphore struct {
ch chan struct{}
}
func NewSemaphore(size int) Semaphore {
return Semaphore{
ch: make(chan struct{}, size),
}
}
func (sem Semaphore) Acquire() {
sem.ch <- struct{}{}
}
func (sem Semaphore) AcquireMaybe() bool {
select {
case sem.ch <- struct{}{}:
return true
default:
return false
}
}
func (sem Semaphore) Release() {
<-sem.ch
}
func (sem Semaphore) Len() int {
return len(sem.ch)
}
func (sem Semaphore) Cap() int {
return cap(sem.ch)
}