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