diff --git a/src/sync/mutex.go b/src/sync/mutex.go index 59f320d5d7..3db705af0c 100644 --- a/src/sync/mutex.go +++ b/src/sync/mutex.go @@ -3,12 +3,10 @@ package sync import ( "internal/task" _ "unsafe" - - "runtime/volatile" ) type Mutex struct { - state uint8 // Set to non-zero if locked. + locked bool blocked task.Stack } @@ -16,18 +14,18 @@ type Mutex struct { func scheduleTask(*task.Task) func (m *Mutex) Lock() { - if m.islocked() { + if m.locked { // Push self onto stack of blocked tasks, and wait to be resumed. m.blocked.Push(task.Current()) task.Pause() return } - m.setlock(true) + m.locked = true } func (m *Mutex) Unlock() { - if !m.islocked() { + if !m.locked { panic("sync: unlock of unlocked Mutex") } @@ -35,7 +33,7 @@ func (m *Mutex) Unlock() { if t := m.blocked.Pop(); t != nil { scheduleTask(t) } else { - m.setlock(false) + m.locked = false } } @@ -45,28 +43,13 @@ func (m *Mutex) Unlock() { // and use of TryLock is often a sign of a deeper problem // in a particular use of mutexes. func (m *Mutex) TryLock() bool { - if m.islocked() { + if m.locked { return false } m.Lock() return true } -func (m *Mutex) islocked() bool { - return volatile.LoadUint8(&m.state) != 0 -} - -func (m *Mutex) setlock(b bool) { - volatile.StoreUint8(&m.state, boolToU8(b)) -} - -func boolToU8(b bool) uint8 { - if b { - return 1 - } - return 0 -} - type RWMutex struct { // waitingWriters are all of the tasks waiting for write locks. waitingWriters task.Stack