Browse Source

more deleting thanks wb

pull/8134/head
tycho garen 3 years ago
parent
commit
112cdb29e6
2 changed files with 1 additions and 37 deletions
  1. +1
    -13
      internal/libs/clist/clist.go
  2. +0
    -24
      internal/libs/clist/clist_test.go

+ 1
- 13
internal/libs/clist/clist.go View File

@ -44,7 +44,6 @@ waiting on NextWait() (since it's just a read operation).
type CElement struct {
mtx sync.RWMutex
prev *CElement
prevWaitCh chan struct{}
next *CElement
nextWaitCh chan struct{}
removed bool
@ -151,14 +150,7 @@ func (e *CElement) setPrev(newPrev *CElement) {
e.mtx.Lock()
defer e.mtx.Unlock()
oldPrev := e.prev
e.prev = newPrev
if oldPrev != nil && newPrev == nil {
e.prevWaitCh = make(chan struct{})
}
if oldPrev == nil && newPrev != nil {
close(e.prevWaitCh)
}
}
func (e *CElement) setRemoved() {
@ -167,10 +159,7 @@ func (e *CElement) setRemoved() {
e.removed = true
// This wakes up anyone waiting in either direction.
if e.prev == nil {
close(e.prevWaitCh)
}
// This wakes up anyone waiting.
if e.next == nil {
close(e.nextWaitCh)
}
@ -261,7 +250,6 @@ func (l *CList) PushBack(v interface{}) *CElement {
// Construct a new element
e := &CElement{
prev: nil,
prevWaitCh: make(chan struct{}),
next: nil,
nextWaitCh: make(chan struct{}),
removed: false,


+ 0
- 24
internal/libs/clist/clist_test.go View File

@ -314,30 +314,6 @@ FOR_LOOP:
t.Fatalf("number of pushed items (%d) not equal to number of seen items (%d)", pushed, seen)
}
// 4) test iterating backwards (PrevWaitChan and Prev)
prev := next
seen = 0
FOR_LOOP2:
for {
select {
case <-prev.prevWaitCh:
prev = prev.Prev()
seen++
if prev == nil {
t.Fatal("expected PrevWaitChan to block forever on nil when reached first elem")
}
if pushed == seen {
break FOR_LOOP2
}
case <-time.After(250 * time.Millisecond):
break FOR_LOOP2
}
}
if pushed != seen {
t.Fatalf("number of pushed items (%d) not equal to number of seen items (%d)", pushed, seen)
}
}
func TestRemoved(t *testing.T) {


Loading…
Cancel
Save