From a818830babc690b86dae04a15b63f66f63a0eb45 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Wed, 16 Mar 2022 10:24:41 -0400 Subject: [PATCH] libs/clist: remove unused surface area --- internal/libs/clist/bench_test.go | 2 +- internal/libs/clist/clist.go | 58 +++++++------------------------ internal/libs/clist/clist_test.go | 2 +- 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/internal/libs/clist/bench_test.go b/internal/libs/clist/bench_test.go index 95973cc76..ee5d836a7 100644 --- a/internal/libs/clist/bench_test.go +++ b/internal/libs/clist/bench_test.go @@ -12,7 +12,7 @@ func BenchmarkDetaching(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { start.removed = true - start.DetachNext() + start.detachNext() start.DetachPrev() tmp := nxt nxt = nxt.Next() diff --git a/internal/libs/clist/clist.go b/internal/libs/clist/clist.go index 99e5f05bf..fbe4eccae 100644 --- a/internal/libs/clist/clist.go +++ b/internal/libs/clist/clist.go @@ -72,27 +72,9 @@ func (e *CElement) NextWait() *CElement { } } -// Blocking implementation of Prev(). -// May return nil iff CElement was head and got removed. -func (e *CElement) PrevWait() *CElement { - for { - e.mtx.RLock() - prev := e.prev - removed := e.removed - signal := e.prevWaitCh - e.mtx.RUnlock() - - if prev != nil || removed { - return prev - } - - <-signal - } -} - -// PrevWaitChan can be used to wait until Prev becomes not nil. Once it does, +// prevWaitChan can be used to wait until Prev becomes not nil. Once it does, // channel will be closed. -func (e *CElement) PrevWaitChan() <-chan struct{} { +func (e *CElement) prevWaitChan() <-chan struct{} { e.mtx.RLock() defer e.mtx.RUnlock() @@ -131,7 +113,7 @@ func (e *CElement) Removed() bool { return isRemoved } -func (e *CElement) DetachNext() { +func (e *CElement) detachNext() { e.mtx.Lock() if !e.removed { e.mtx.Unlock() @@ -153,7 +135,7 @@ func (e *CElement) DetachPrev() { // NOTE: This function needs to be safe for // concurrent goroutines waiting on nextWg. -func (e *CElement) SetNext(newNext *CElement) { +func (e *CElement) setNext(newNext *CElement) { e.mtx.Lock() oldNext := e.next @@ -174,7 +156,7 @@ func (e *CElement) SetNext(newNext *CElement) { // NOTE: This function needs to be safe for // concurrent goroutines waiting on prevWg -func (e *CElement) SetPrev(newPrev *CElement) { +func (e *CElement) setPrev(newPrev *CElement) { e.mtx.Lock() defer e.mtx.Unlock() @@ -188,7 +170,7 @@ func (e *CElement) SetPrev(newPrev *CElement) { } } -func (e *CElement) SetRemoved() { +func (e *CElement) setRemoved() { e.mtx.Lock() defer e.mtx.Unlock() @@ -250,7 +232,7 @@ func (l *CList) Front() *CElement { return head } -func (l *CList) FrontWait() *CElement { +func (l *CList) frontWait() *CElement { // Loop until the head is non-nil else wait and try again for { l.mtx.RLock() @@ -273,22 +255,6 @@ func (l *CList) Back() *CElement { return back } -func (l *CList) BackWait() *CElement { - for { - l.mtx.RLock() - tail := l.tail - wg := l.wg - l.mtx.RUnlock() - - if tail != nil { - return tail - } - wg.Wait() - // l.tail doesn't necessarily exist here. - // That's why we need to continue a for-loop. - } -} - // WaitChan can be used to wait until Front or Back becomes not nil. Once it // does, channel will be closed. func (l *CList) WaitChan() <-chan struct{} { @@ -326,8 +292,8 @@ func (l *CList) PushBack(v interface{}) *CElement { l.head = e l.tail = e } else { - e.SetPrev(l.tail) // We must init e first. - l.tail.SetNext(e) // This will make e accessible. + e.setPrev(l.tail) // We must init e first. + l.tail.setNext(e) // This will make e accessible. l.tail = e // Update the list. } l.mtx.Unlock() @@ -365,16 +331,16 @@ func (l *CList) Remove(e *CElement) interface{} { if prev == nil { l.head = next } else { - prev.SetNext(next) + prev.setNext(next) } if next == nil { l.tail = prev } else { - next.SetPrev(prev) + next.setPrev(prev) } // Set .Done() on e, otherwise waiters will wait forever. - e.SetRemoved() + e.setRemoved() return e.Value } diff --git a/internal/libs/clist/clist_test.go b/internal/libs/clist/clist_test.go index a0482fc40..c7c8ce535 100644 --- a/internal/libs/clist/clist_test.go +++ b/internal/libs/clist/clist_test.go @@ -320,7 +320,7 @@ FOR_LOOP: FOR_LOOP2: for { select { - case <-prev.PrevWaitChan(): + case <-prev.prevWaitChan(): prev = prev.Prev() seen++ if prev == nil {