summaryrefslogtreecommitdiffhomepage
path: root/pkg/refs
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2018-09-04 09:18:00 -0700
committerShentubot <shentubot@google.com>2018-09-04 09:19:11 -0700
commitc09f9acd7c7a2e85472b1ee47bf26f7c89ded43e (patch)
tree27965206558459ba7505053cbfe9fd3d0e7167fb /pkg/refs
parent66c03b3dd79c45014da19f36973a85290e9a4458 (diff)
Distinguish Element and Linker for ilist.
Furthermore, allow for the specification of an ElementMapper. This allows a single "Element" type to exist on multiple inline lists, and work without having to embed the entry type. This is a requisite change for supporting a per-Inode list of Dirents. PiperOrigin-RevId: 211467497 Change-Id: If2768999b43e03fdaecf8ed15f435fe37518d163
Diffstat (limited to 'pkg/refs')
-rw-r--r--pkg/refs/BUILD15
-rw-r--r--pkg/refs/refcounter.go8
2 files changed, 17 insertions, 6 deletions
diff --git a/pkg/refs/BUILD b/pkg/refs/BUILD
index 3ea877ccf..98150ba8f 100644
--- a/pkg/refs/BUILD
+++ b/pkg/refs/BUILD
@@ -1,16 +1,29 @@
package(licenses = ["notice"]) # Apache 2.0
+load("//tools/go_generics:defs.bzl", "go_template_instance")
load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+go_template_instance(
+ name = "weak_ref_list",
+ out = "weak_ref_list.go",
+ package = "refs",
+ prefix = "weakRef",
+ template = "//pkg/ilist:generic_list",
+ types = {
+ "Element": "*WeakRef",
+ "Linker": "*WeakRef",
+ },
+)
+
go_library(
name = "refs",
srcs = [
"refcounter.go",
"refcounter_state.go",
+ "weak_ref_list.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/refs",
visibility = ["//:sandbox"],
- deps = ["//pkg/ilist"],
)
go_test(
diff --git a/pkg/refs/refcounter.go b/pkg/refs/refcounter.go
index 0d44c2499..638a93bab 100644
--- a/pkg/refs/refcounter.go
+++ b/pkg/refs/refcounter.go
@@ -20,8 +20,6 @@ import (
"reflect"
"sync"
"sync/atomic"
-
- "gvisor.googlesource.com/gvisor/pkg/ilist"
)
// RefCounter is the interface to be implemented by objects that are reference
@@ -61,7 +59,7 @@ type WeakRefUser interface {
//
// +stateify savable
type WeakRef struct {
- ilist.Entry `state:"nosave"`
+ weakRefEntry `state:"nosave"`
// obj is an atomic value that points to the refCounter.
obj atomic.Value `state:".(savedReference)"`
@@ -195,7 +193,7 @@ type AtomicRefCount struct {
mu sync.Mutex `state:"nosave"`
// weakRefs is our collection of weak references.
- weakRefs ilist.List `state:"nosave"`
+ weakRefs weakRefList `state:"nosave"`
}
// ReadRefs returns the current number of references. The returned count is
@@ -276,7 +274,7 @@ func (r *AtomicRefCount) DecRefWithDestructor(destroy func()) {
// return false due to the reference count check.
r.mu.Lock()
for !r.weakRefs.Empty() {
- w := r.weakRefs.Front().(*WeakRef)
+ w := r.weakRefs.Front()
// Capture the callback because w cannot be touched
// after it's zapped -- the owner is free it reuse it
// after that.