state struct {
// state holds the device's state. It is accessed atomically.
// Use the device.deviceState method to read it.
- // If state.mu is (r)locked, state is the current state of the device.
- // Without state.mu (r)locked, state is either the current state
- // of the device or the intended future state of the device.
+ // If state is not locked, state is the current state of the device.
+ // If state is locked, state is the current state or intended future state of the device.
// For example, while executing a call to Up, state will be deviceStateUp.
// There is no guarantee that that intended future state of the device
// will become the actual state; Up can fail.
// stopping blocks until all inputs to Device have been closed.
stopping sync.WaitGroup
// mu protects state changes.
- mu sync.Mutex
+ sync.Mutex
}
net struct {
// changeState attempts to change the device state to match want.
func (device *Device) changeState(want deviceState) {
- device.state.mu.Lock()
- defer device.state.mu.Unlock()
+ device.state.Lock()
+ defer device.state.Unlock()
old := device.deviceState()
if old == deviceStateClosed {
// once closed, always closed
}
func (device *Device) Close() {
- device.state.mu.Lock()
- defer device.state.mu.Unlock()
+ device.state.Lock()
+ defer device.state.Unlock()
if device.isClosed() {
return
}
}
state struct {
- mu sync.Mutex // protects against concurrent Start/Stop
+ sync.Mutex // protects against concurrent Start/Stop
}
queue struct {
}
// prevent simultaneous start/stop operations
- peer.state.mu.Lock()
- defer peer.state.mu.Unlock()
+ peer.state.Lock()
+ defer peer.state.Unlock()
if peer.isRunning.Get() {
return
}
func (peer *Peer) Stop() {
- peer.state.mu.Lock()
- defer peer.state.mu.Unlock()
+ peer.state.Lock()
+ defer peer.state.Unlock()
if !peer.isRunning.Swap(false) {
return