Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go-fuse
Commits
f0adf638
Commit
f0adf638
authored
Mar 29, 2012
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use slice for portableHandleMap, which is slighty more efficient.
parent
99c5447e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
24 deletions
+19
-24
fuse/handle.go
fuse/handle.go
+19
-24
No files found.
fuse/handle.go
View file @
f0adf638
...
...
@@ -39,41 +39,34 @@ const _ALREADY_MSG = "Object already has a handle"
type
portableHandleMap
struct
{
sync
.
RWMutex
nextFree
uint32
handles
map
[
uint64
]
*
Handled
used
int
handles
[]
*
Handled
freeIds
[]
uint64
}
func
(
m
*
portableHandleMap
)
Register
(
obj
*
Handled
,
asInt
interface
{})
uint64
{
func
(
m
*
portableHandleMap
)
Register
(
obj
*
Handled
,
asInt
interface
{})
(
handle
uint64
)
{
if
obj
.
check
!=
0
{
panic
(
_ALREADY_MSG
)
}
m
.
Lock
()
defer
m
.
Unlock
()
for
{
h
:=
uint64
(
m
.
nextFree
)
m
.
nextFree
++
// HACK - we make sure we start with 1, so we always
// assign root to 1.
if
h
<
1
{
continue
}
old
:=
m
.
handles
[
h
]
if
old
!=
nil
{
continue
}
m
.
handles
[
h
]
=
obj
obj
.
check
=
0xbaabbaab
return
h
if
len
(
m
.
freeIds
)
==
0
{
handle
=
uint64
(
len
(
m
.
handles
))
m
.
handles
=
append
(
m
.
handles
,
obj
)
}
else
{
handle
=
m
.
freeIds
[
len
(
m
.
freeIds
)
-
1
]
m
.
freeIds
=
m
.
freeIds
[
:
len
(
m
.
freeIds
)
-
1
]
m
.
handles
[
handle
]
=
obj
}
return
0
m
.
used
++
return
handle
}
func
(
m
*
portableHandleMap
)
Count
()
int
{
m
.
RLock
()
defer
m
.
RUnlock
()
return
len
(
m
.
handles
)
return
m
.
used
}
func
(
m
*
portableHandleMap
)
Decode
(
h
uint64
)
*
Handled
{
...
...
@@ -86,8 +79,9 @@ func (m *portableHandleMap) Forget(h uint64) *Handled {
m
.
Lock
()
defer
m
.
Unlock
()
v
:=
m
.
handles
[
h
]
v
.
check
=
0
delete
(
m
.
handles
,
h
)
m
.
handles
[
h
]
=
nil
m
.
freeIds
=
append
(
m
.
freeIds
,
h
)
m
.
used
--
return
v
}
...
...
@@ -166,7 +160,8 @@ func (m *int64HandleMap) verify() {
func
NewHandleMap
(
portable
bool
)
(
hm
HandleMap
)
{
if
portable
{
return
&
portableHandleMap
{
handles
:
make
(
map
[
uint64
]
*
Handled
),
// Avoid handing out ID 0 and 1.
handles
:
[]
*
Handled
{
nil
,
nil
},
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment