Created
June 16, 2016 07:02
-
-
Save zwh8800/91b94bd54eb6574785002764bb462af5 to your computer and use it in GitHub Desktop.
读写锁不能这么用。。。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (bus *EventBus) find(register *Register) int { | |
bus.registersLock.RLock() | |
defer bus.registersLock.RUnlock() | |
for i := 0; i < len(bus.registers); i++ { | |
if bus.registers[i] == register { | |
return i | |
} | |
} | |
return -1 | |
} | |
func (bus *EventBus) remove(i int) { | |
bus.registersLock.Lock() | |
defer bus.registersLock.Unlock() | |
bus.registers = append(bus.registers[:i], bus.registers[i+1:]...) | |
} | |
func (bus *EventBus) Remove(register *Register) { | |
i := bus.find(register) | |
if i != -1 { | |
bus.remove(i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment