aboutsummaryrefslogtreecommitdiffstats
path: root/miner/worker.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-10-29 20:28:00 +0800
committerFelix Lange <fjl@twurst.com>2015-10-30 00:26:26 +0800
commitfbdb44dcc17240a01b45e55d3aa4e4b8db0868cd (patch)
tree2363ce8738074226cfedf8ede1612e0ef3a03494 /miner/worker.go
parent56f8699a6c6bfe613d2ab28c47631a1f4a29e36f (diff)
downloaddexon-fbdb44dcc17240a01b45e55d3aa4e4b8db0868cd.tar.gz
dexon-fbdb44dcc17240a01b45e55d3aa4e4b8db0868cd.tar.zst
dexon-fbdb44dcc17240a01b45e55d3aa4e4b8db0868cd.zip
cmd/utils, rpc/comms: stop XEth when IPC connection ends
There are a bunch of changes required to make this work: - in miner: allow unregistering agents, fix RemoteAgent.Stop - in eth/filters: make FilterSystem.Stop not crash - in rpc/comms: move listen loop to platform-independent code Fixes #1930. I ran the shell loop there for a few minutes and didn't see any changes in the memory profile.
Diffstat (limited to 'miner/worker.go')
-rw-r--r--miner/worker.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/miner/worker.go b/miner/worker.go
index 3519e1506..2d072ef60 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -92,7 +92,7 @@ type Result struct {
type worker struct {
mu sync.Mutex
- agents []Agent
+ agents map[Agent]struct{}
recv chan *Result
mux *event.TypeMux
quit chan struct{}
@@ -136,6 +136,7 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker {
coinbase: coinbase,
txQueue: make(map[common.Hash]*types.Transaction),
quit: make(chan struct{}),
+ agents: make(map[Agent]struct{}),
fullValidation: false,
}
go worker.update()
@@ -180,7 +181,7 @@ func (self *worker) start() {
atomic.StoreInt32(&self.mining, 1)
// spin up agents
- for _, agent := range self.agents {
+ for agent := range self.agents {
agent.Start()
}
}
@@ -190,16 +191,14 @@ func (self *worker) stop() {
defer self.mu.Unlock()
if atomic.LoadInt32(&self.mining) == 1 {
- var keep []Agent
- // stop all agents
- for _, agent := range self.agents {
+ // Stop all agents.
+ for agent := range self.agents {
agent.Stop()
- // keep all that's not a cpu agent
- if _, ok := agent.(*CpuAgent); !ok {
- keep = append(keep, agent)
+ // Remove CPU agents.
+ if _, ok := agent.(*CpuAgent); ok {
+ delete(self.agents, agent)
}
}
- self.agents = keep
}
atomic.StoreInt32(&self.mining, 0)
@@ -209,10 +208,17 @@ func (self *worker) stop() {
func (self *worker) register(agent Agent) {
self.mu.Lock()
defer self.mu.Unlock()
- self.agents = append(self.agents, agent)
+ self.agents[agent] = struct{}{}
agent.SetReturnCh(self.recv)
}
+func (self *worker) unregister(agent Agent) {
+ self.mu.Lock()
+ defer self.mu.Unlock()
+ delete(self.agents, agent)
+ agent.Stop()
+}
+
func (self *worker) update() {
eventSub := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
defer eventSub.Unsubscribe()
@@ -341,11 +347,9 @@ func (self *worker) push(work *Work) {
glog.Infoln("You turn back and abort mining")
return
}
-
// push new work to agents
- for _, agent := range self.agents {
+ for agent := range self.agents {
atomic.AddInt32(&self.atWork, 1)
-
if agent.Work() != nil {
agent.Work() <- work
}