.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.1.1 / internal / sync / sync.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/honnef.co/go/tools@v0.1.1/internal/sync/sync.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/honnef.co/go/tools@v0.1.1/internal/sync/sync.go
new file mode 100644 (file)
index 0000000..e78ad50
--- /dev/null
@@ -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)
+}