From d541587701f7894190208e67f527d986807026ba Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 6 Apr 2020 18:13:46 +0200 Subject: [PATCH] Remove channel from ring buffer consumers This is unused. --- downstream.go | 6 +----- ring.go | 30 +++--------------------------- user.go | 3 +-- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/downstream.go b/downstream.go index 2f0dc1c..92de9cd 100644 --- a/downstream.go +++ b/downstream.go @@ -694,11 +694,7 @@ func (dc *downstreamConn) welcome() error { } } - consumer, _ := net.ring.NewConsumer(seqPtr) - - if _, ok := dc.ringConsumers[net]; ok { - panic("network has been added twice") - } + consumer := net.ring.NewConsumer(seqPtr) dc.ringConsumers[net] = consumer // TODO: this means all history is lost when trying to send it while the diff --git a/ring.go b/ring.go index 24923db..f5df032 100644 --- a/ring.go +++ b/ring.go @@ -39,15 +39,6 @@ func (r *Ring) Produce(msg *irc.Message) { i := int(r.cur % r.cap) r.buffer[i] = msg r.cur++ - - for _, consumer := range r.consumers { - select { - case consumer.ch <- struct{}{}: - // This space is intentionally left blank - default: - // The channel already has a pending item - } - } } func (r *Ring) Close() { @@ -58,10 +49,6 @@ func (r *Ring) Close() { panic("soju: Ring.Close called twice") } - for _, rc := range r.consumers { - close(rc.ch) - } - r.closed = true } @@ -71,15 +58,9 @@ func (r *Ring) Close() { // producer message. If seq is non-nil, the consumer will get messages starting // from the specified history sequence number (see RingConsumer.Close). // -// The returned channel yields a value each time the consumer has a new message -// available. Consume should be called to drain the consumer. -// // The consumer can only be used from a single goroutine. -func (r *Ring) NewConsumer(seq *uint64) (*RingConsumer, <-chan struct{}) { - consumer := &RingConsumer{ - ring: r, - ch: make(chan struct{}, 1), - } +func (r *Ring) NewConsumer(seq *uint64) *RingConsumer { + consumer := &RingConsumer{ring: r} r.lock.Lock() if seq != nil { @@ -87,20 +68,16 @@ func (r *Ring) NewConsumer(seq *uint64) (*RingConsumer, <-chan struct{}) { } else { consumer.cur = r.cur } - if consumer.diff() > 0 { - consumer.ch <- struct{}{} - } r.consumers = append(r.consumers, consumer) r.lock.Unlock() - return consumer, consumer.ch + return consumer } // RingConsumer is a ring buffer consumer. type RingConsumer struct { ring *Ring cur uint64 - ch chan struct{} closed bool } @@ -161,7 +138,6 @@ func (rc *RingConsumer) Close() uint64 { } rc.ring.lock.Unlock() - close(rc.ch) rc.closed = true return rc.cur } diff --git a/user.go b/user.go index ee4d4f8..5ffa3dd 100644 --- a/user.go +++ b/user.go @@ -351,8 +351,7 @@ func (u *user) createNetwork(net *Network) (*network, error) { u.forEachDownstream(func(dc *downstreamConn) { if dc.network == nil { - consumer, _ := network.ring.NewConsumer(nil) - dc.ringConsumers[network] = consumer + dc.ringConsumers[network] = network.ring.NewConsumer(nil) } })