v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 00:00:16 -07:00
2022-10-24 23:43:20 +08:00

28 lines
358 B
Go

package translate
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--
}