v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-16 07:40:44 -07:00
GTT/internal/lock/lock.go

28 lines
353 B
Go

package lock
type Lock struct {
Stop bool
threadCount int8
}
func NewLock() *Lock {
return &Lock{
Stop: true,
threadCount: 0,
}
}
func (l *Lock) Available() bool {
return l.Stop && l.threadCount == 0
}
func (l *Lock) Acquire() {
l.Stop = false
l.threadCount++
}
func (l *Lock) Release() {
l.Stop = true
l.threadCount--
}