Rename lock to mu. (#16)

Rename lock to mu everywhere.
pull/1/head
M-A 10 years ago committed by GitHub
parent aa5269b72f
commit 5fce5c83f9

@ -23,7 +23,8 @@ import (
type Conn struct { type Conn struct {
w net.Conn w net.Conn
c chan ir.Message c chan ir.Message
lock sync.Mutex
mu sync.Mutex
list map[string][]string // list of remotes and associated keys list map[string][]string // list of remotes and associated keys
pendingList map[string][]string // list of remotes and associated keys being created. pendingList map[string][]string // list of remotes and associated keys being created.
} }
@ -66,8 +67,8 @@ func (c *Conn) Channel() <-chan ir.Message {
// //
// Empty if the list was not retrieved yet. // Empty if the list was not retrieved yet.
func (c *Conn) Codes() map[string][]string { func (c *Conn) Codes() map[string][]string {
c.lock.Lock() c.mu.Lock()
defer c.lock.Unlock() defer c.mu.Unlock()
return c.list return c.list
} }
@ -176,10 +177,10 @@ func (c *Conn) readData(r *bufio.Reader) error {
} }
} }
if all { if all {
c.lock.Lock() c.mu.Lock()
c.list = c.pendingList c.list = c.pendingList
c.pendingList = nil c.pendingList = nil
c.lock.Unlock() c.mu.Unlock()
} }
} }
default: default:

@ -25,7 +25,7 @@ const SkipAddr uint16 = 0xFFFF
// I2C represents an I²C master implemented as bit-banging on 2 GPIO pins. // I2C represents an I²C master implemented as bit-banging on 2 GPIO pins.
type I2C struct { type I2C struct {
lock sync.Mutex mu sync.Mutex
scl gpio.PinIO // Clock line scl gpio.PinIO // Clock line
sda gpio.PinIO // Data line sda gpio.PinIO // Data line
halfCycle time.Duration halfCycle time.Duration
@ -42,8 +42,8 @@ func (i *I2C) Close() error {
// Tx implements i2c.Conn. // Tx implements i2c.Conn.
func (i *I2C) Tx(addr uint16, w, r []byte) error { func (i *I2C) Tx(addr uint16, w, r []byte) error {
i.lock.Lock() i.mu.Lock()
defer i.lock.Unlock() defer i.mu.Unlock()
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
//syscall.Setpriority(which, who, prio) //syscall.Setpriority(which, who, prio)
@ -90,8 +90,8 @@ func (i *I2C) Tx(addr uint16, w, r []byte) error {
// Speed implements i2c.Conn. // Speed implements i2c.Conn.
func (i *I2C) Speed(hz int64) error { func (i *I2C) Speed(hz int64) error {
i.lock.Lock() i.mu.Lock()
defer i.lock.Unlock() defer i.mu.Unlock()
i.halfCycle = time.Second / time.Duration(hz) / time.Duration(2) i.halfCycle = time.Second / time.Duration(hz) / time.Duration(2)
return nil return nil
} }

@ -28,7 +28,8 @@ type SPI struct {
sdi gpio.PinIn // MISO sdi gpio.PinIn // MISO
sdo gpio.PinOut // MOSI sdo gpio.PinOut // MOSI
csn gpio.PinOut // CS csn gpio.PinOut // CS
lock sync.Mutex
mu sync.Mutex
mode spi.Mode mode spi.Mode
bits int bits int
halfCycle time.Duration halfCycle time.Duration
@ -45,16 +46,16 @@ func (s *SPI) Close() error {
// Speed implements spi.Conn. // Speed implements spi.Conn.
func (s *SPI) Speed(hz int64) error { func (s *SPI) Speed(hz int64) error {
s.lock.Lock() s.mu.Lock()
defer s.lock.Unlock() defer s.mu.Unlock()
s.halfCycle = time.Second / time.Duration(hz) / time.Duration(2) s.halfCycle = time.Second / time.Duration(hz) / time.Duration(2)
return nil return nil
} }
// Configure implements spi.Conn. // Configure implements spi.Conn.
func (s *SPI) Configure(mode spi.Mode, bits int) error { func (s *SPI) Configure(mode spi.Mode, bits int) error {
s.lock.Lock() s.mu.Lock()
defer s.lock.Unlock() defer s.mu.Unlock()
if mode != spi.Mode3 { if mode != spi.Mode3 {
return errors.New("not implemented") return errors.New("not implemented")
} }
@ -72,8 +73,8 @@ func (s *SPI) Tx(w, r []byte) error {
if len(r) != 0 && len(w) != len(r) { if len(r) != 0 && len(w) != len(r) {
return errors.New("write and read buffers must be the same length") return errors.New("write and read buffers must be the same length")
} }
s.lock.Lock() s.mu.Lock()
defer s.lock.Unlock() defer s.mu.Unlock()
if s.csn != nil { if s.csn != nil {
s.csn.Out(gpio.Low) s.csn.Out(gpio.Low)
s.sleepHalfCycle() s.sleepHalfCycle()

Loading…
Cancel
Save