Changeset 229 in code for trunk/ring.go
- Timestamp:
- Apr 6, 2020, 4:18:50 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ring.go
r228 r229 3 3 import ( 4 4 "fmt" 5 "sync"6 5 7 6 "gopkg.in/irc.v3" … … 14 13 cap uint64 15 14 16 lock sync.Mutex17 15 cur uint64 18 16 consumers []*RingConsumer … … 30 28 // Produce appends a new message to the ring buffer. 31 29 func (r *Ring) Produce(msg *irc.Message) { 32 r.lock.Lock()33 defer r.lock.Unlock()34 35 30 if r.closed { 36 31 panic("soju: Ring.Produce called after Close") … … 43 38 44 39 func (r *Ring) Close() { 45 r.lock.Lock()46 defer r.lock.Unlock()47 48 40 if r.closed { 49 41 panic("soju: Ring.Close called twice") … … 63 55 consumer := &RingConsumer{ring: r} 64 56 65 r.lock.Lock()66 57 if seq != nil { 67 58 consumer.cur = *seq … … 70 61 } 71 62 r.consumers = append(r.consumers, consumer) 72 r.lock.Unlock()73 63 74 64 return consumer … … 96 86 panic("soju: RingConsumer.Peek called after Close") 97 87 } 98 99 rc.ring.lock.Lock()100 defer rc.ring.lock.Unlock()101 88 102 89 diff := rc.diff() … … 130 117 // argument to Ring.NewConsumer to resume the message stream. 131 118 func (rc *RingConsumer) Close() uint64 { 132 rc.ring.lock.Lock()133 119 for i := range rc.ring.consumers { 134 120 if rc.ring.consumers[i] == rc { … … 137 123 } 138 124 } 139 rc.ring.lock.Unlock()140 125 141 126 rc.closed = true
Note:
See TracChangeset
for help on using the changeset viewer.