summaryrefslogtreecommitdiffhomepage
path: root/pkg/ilist/list.go
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2021-01-11 13:15:38 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-11 13:18:01 -0800
commit4c4de66443174f2ed7f4fa533a1d09c709be9427 (patch)
treef2bc5a63a75c664c8d8cc7f61b1077bce78d3308 /pkg/ilist/list.go
parent321552f0ad365f8ca0d69f669c543d159b04721c (diff)
Make ilist split safe.
This allows for use in restricted contexts. Updates #5039 PiperOrigin-RevId: 351220385
Diffstat (limited to 'pkg/ilist/list.go')
-rw-r--r--pkg/ilist/list.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/ilist/list.go b/pkg/ilist/list.go
index f4a4c33d3..557051d18 100644
--- a/pkg/ilist/list.go
+++ b/pkg/ilist/list.go
@@ -72,16 +72,22 @@ func (l *List) Reset() {
}
// Empty returns true iff the list is empty.
+//
+//go:nosplit
func (l *List) Empty() bool {
return l.head == nil
}
// Front returns the first element of list l or nil.
+//
+//go:nosplit
func (l *List) Front() Element {
return l.head
}
// Back returns the last element of list l or nil.
+//
+//go:nosplit
func (l *List) Back() Element {
return l.tail
}
@@ -89,6 +95,8 @@ func (l *List) Back() Element {
// Len returns the number of elements in the list.
//
// NOTE: This is an O(n) operation.
+//
+//go:nosplit
func (l *List) Len() (count int) {
for e := l.Front(); e != nil; e = (ElementMapper{}.linkerFor(e)).Next() {
count++
@@ -97,6 +105,8 @@ func (l *List) Len() (count int) {
}
// PushFront inserts the element e at the front of list l.
+//
+//go:nosplit
func (l *List) PushFront(e Element) {
linker := ElementMapper{}.linkerFor(e)
linker.SetNext(l.head)
@@ -111,6 +121,8 @@ func (l *List) PushFront(e Element) {
}
// PushBack inserts the element e at the back of list l.
+//
+//go:nosplit
func (l *List) PushBack(e Element) {
linker := ElementMapper{}.linkerFor(e)
linker.SetNext(nil)
@@ -125,6 +137,8 @@ func (l *List) PushBack(e Element) {
}
// PushBackList inserts list m at the end of list l, emptying m.
+//
+//go:nosplit
func (l *List) PushBackList(m *List) {
if l.head == nil {
l.head = m.head
@@ -140,6 +154,8 @@ func (l *List) PushBackList(m *List) {
}
// InsertAfter inserts e after b.
+//
+//go:nosplit
func (l *List) InsertAfter(b, e Element) {
bLinker := ElementMapper{}.linkerFor(b)
eLinker := ElementMapper{}.linkerFor(e)
@@ -158,6 +174,8 @@ func (l *List) InsertAfter(b, e Element) {
}
// InsertBefore inserts e before a.
+//
+//go:nosplit
func (l *List) InsertBefore(a, e Element) {
aLinker := ElementMapper{}.linkerFor(a)
eLinker := ElementMapper{}.linkerFor(e)
@@ -175,6 +193,8 @@ func (l *List) InsertBefore(a, e Element) {
}
// Remove removes e from l.
+//
+//go:nosplit
func (l *List) Remove(e Element) {
linker := ElementMapper{}.linkerFor(e)
prev := linker.Prev()
@@ -207,21 +227,29 @@ type Entry struct {
}
// Next returns the entry that follows e in the list.
+//
+//go:nosplit
func (e *Entry) Next() Element {
return e.next
}
// Prev returns the entry that precedes e in the list.
+//
+//go:nosplit
func (e *Entry) Prev() Element {
return e.prev
}
// SetNext assigns 'entry' as the entry that follows e in the list.
+//
+//go:nosplit
func (e *Entry) SetNext(elem Element) {
e.next = elem
}
// SetPrev assigns 'entry' as the entry that precedes e in the list.
+//
+//go:nosplit
func (e *Entry) SetPrev(elem Element) {
e.prev = elem
}