1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-19 13:22:54 +00:00
arikawa/utils/moreatomic/mutex.go

34 lines
436 B
Go

package moreatomic
import "github.com/sasha-s/go-deadlock"
type BusyMutex struct {
busy Bool
mut deadlock.Mutex
}
func (m *BusyMutex) TryLock() bool {
if m.busy.Get() {
return false
}
m.mut.Lock()
m.busy.Set(true)
return true
}
func (m *BusyMutex) IsBusy() bool {
return m.busy.Get()
}
func (m *BusyMutex) Lock() {
m.mut.Lock()
m.busy.Set(true)
}
func (m *BusyMutex) Unlock() {
m.busy.Set(false)
m.mut.Unlock()
}