Commit 9567fcf5 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Drop object from HandleMap interface.

parent 4e5298c2
......@@ -118,7 +118,7 @@ func (c *FileSystemConnector) toInode(nodeid uint64) *Inode {
func (c *FileSystemConnector) lookupUpdate(node *Inode) uint64 {
node.treeLock.Lock()
if node.lookupCount == 0 {
node.nodeId = c.inodeMap.Register(&node.handled, node)
node.nodeId = c.inodeMap.Register(&node.handled)
}
node.lookupCount += 1
id := node.nodeId
......
......@@ -130,7 +130,7 @@ func (m *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, fl
b.WithFlags.File.SetInode(node)
}
node.openFiles = append(node.openFiles, b)
handle := m.openFiles.Register(&b.Handled, b)
handle := m.openFiles.Register(&b.Handled)
node.openFilesMutex.Unlock()
return handle, b
}
......
......@@ -20,7 +20,7 @@ import (
//
// This structure is thread-safe.
type HandleMap interface {
Register(obj *Handled, asInt interface{}) uint64
Register(obj *Handled) uint64
Count() int
Decode(uint64) *Handled
Forget(uint64) *Handled
......@@ -29,7 +29,6 @@ type HandleMap interface {
type Handled struct {
check uint32
object interface{}
}
const _ALREADY_MSG = "Object already has a handle"
......@@ -44,7 +43,7 @@ type portableHandleMap struct {
freeIds []uint64
}
func (m *portableHandleMap) Register(obj *Handled, asInt interface{}) (handle uint64) {
func (m *portableHandleMap) Register(obj *Handled) (handle uint64) {
if obj.check != 0 {
panic(_ALREADY_MSG)
}
......@@ -100,7 +99,7 @@ type int32HandleMap struct {
handles map[uint32]*Handled
}
func (m *int32HandleMap) Register(obj *Handled, asInt interface{}) uint64 {
func (m *int32HandleMap) Register(obj *Handled) uint64 {
m.mutex.Lock()
handle := uint32(uintptr(unsafe.Pointer(obj)))
m.handles[handle] = obj
......@@ -193,7 +192,7 @@ func (m *int64HandleMap) Count() int {
return c
}
func (m *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handle uint64) {
func (m *int64HandleMap) Register(obj *Handled) (handle uint64) {
defer m.verify()
m.mutex.Lock()
......@@ -219,8 +218,6 @@ func (m *int64HandleMap) Register(obj *Handled, asInterface interface{}) (handle
panic(_ALREADY_MSG)
}
obj.check = check
obj.object = asInterface
m.handles[handle] = obj
return handle
}
......@@ -249,8 +246,8 @@ func (m *int64HandleMap) Decode(handle uint64) (val *Handled) {
check := uint32(handle >> 45)
val = (*Handled)(unsafe.Pointer(ptrBits << 3))
if val.check != check {
msg := fmt.Sprintf("handle check mismatch; handle has 0x%x, object has 0x%x: %v",
check, val.check, val.object)
msg := fmt.Sprintf("handle check mismatch; handle has 0x%x, object has 0x%x",
check, val.check)
panic(msg)
}
return val
......
......@@ -29,10 +29,10 @@ func TestHandleMapDoubleRegister(t *testing.T) {
defer markSeen(t, "already has a handle")
hm := NewHandleMap(false)
obj := &Handled{}
hm.Register(obj, obj)
hm.Register(obj)
v := &Handled{}
hm.Register(v, v)
hm.Register(v, v)
hm.Register(v)
hm.Register(v)
t.Error("Double register did not panic")
}
......@@ -47,7 +47,7 @@ func TestHandleMapUnaligned(t *testing.T) {
v := (*Handled)(unsafe.Pointer(&b[1]))
defer markSeen(t, "unaligned")
hm.Register(v, v)
hm.Register(v)
t.Error("Unaligned register did not panic")
}
......@@ -62,7 +62,7 @@ func TestHandleMapPointerLayout(t *testing.T) {
p := uintptr(bogus)
v := (*Handled)(unsafe.Pointer(p))
defer markSeen(t, "48")
hm.Register(v, v)
hm.Register(v)
t.Error("bogus register did not panic")
}
......@@ -70,7 +70,7 @@ func TestHandleMapBasic(t *testing.T) {
for _, portable := range []bool{true, false} {
v := new(Handled)
hm := NewHandleMap(portable)
h := hm.Register(v, v)
h := hm.Register(v)
t.Logf("Got handle 0x%x", h)
if !hm.Has(h) {
t.Fatal("Does not have handle")
......@@ -98,7 +98,7 @@ func TestHandleMapMultiple(t *testing.T) {
hm := NewHandleMap(false)
for i := 0; i < 10; i++ {
v := &Handled{}
h := hm.Register(v, v)
h := hm.Register(v)
if hm.Decode(h) != v {
t.Fatal("address mismatch")
}
......@@ -117,7 +117,7 @@ func TestHandleMapCheckFail(t *testing.T) {
v := new(Handled)
hm := NewHandleMap(false)
h := hm.Register(v, v)
h := hm.Register(v)
hm.Decode(h | (uint64(1) << 63))
t.Error("Borked decode did not panic")
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment