mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-16 07:40:44 -07:00
28 lines
353 B
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--
|
|
}
|