mirror of
https://codeberg.org/frosty/modbot.git
synced 2024-09-19 03:36:35 -04:00
remove mutex to potentially improve performance and fix deadlocks
This commit is contained in:
parent
633a3a7e6b
commit
d87187f61b
7
main.go
7
main.go
|
@ -26,7 +26,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -37,7 +36,6 @@ import (
|
||||||
var (
|
var (
|
||||||
updateChan = make(chan int)
|
updateChan = make(chan int)
|
||||||
moduleOutputs = make([][]byte, len(modules))
|
moduleOutputs = make([][]byte, len(modules))
|
||||||
mutex sync.Mutex
|
|
||||||
|
|
||||||
sigChan = make(chan os.Signal, 1024)
|
sigChan = make(chan os.Signal, 1024)
|
||||||
signalMap = make(map[os.Signal][]*Module)
|
signalMap = make(map[os.Signal][]*Module)
|
||||||
|
@ -91,10 +89,8 @@ func (m *Module) Run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.Lock()
|
|
||||||
moduleOutputs[m.pos] = output.Bytes()
|
moduleOutputs[m.pos] = output.Bytes()
|
||||||
updateChan <- 1
|
updateChan <- 1
|
||||||
mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) Init(pos int) {
|
func (m *Module) Init(pos int) {
|
||||||
|
@ -153,11 +149,8 @@ func monitorUpdates(setXRootName bool) {
|
||||||
var combinedOutput bytes.Buffer
|
var combinedOutput bytes.Buffer
|
||||||
|
|
||||||
for range updateChan {
|
for range updateChan {
|
||||||
mutex.Lock()
|
|
||||||
combinedOutput.Reset()
|
combinedOutput.Reset()
|
||||||
createOutput(&combinedOutput)
|
createOutput(&combinedOutput)
|
||||||
mutex.Unlock()
|
|
||||||
|
|
||||||
combinedOutputBytes := combinedOutput.Bytes()
|
combinedOutputBytes := combinedOutput.Bytes()
|
||||||
|
|
||||||
if !bytes.Equal(combinedOutputBytes, lastOutput) {
|
if !bytes.Equal(combinedOutputBytes, lastOutput) {
|
||||||
|
|
Loading…
Reference in a new issue