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
0abb4be6
Commit
0abb4be6
authored
Jun 22, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide bufferpool implementations to reduce API clutter.
parent
41f74f69
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
fuse/bufferpool.go
fuse/bufferpool.go
+17
-13
No files found.
fuse/bufferpool.go
View file @
0abb4be6
...
@@ -16,25 +16,29 @@ type BufferPool interface {
...
@@ -16,25 +16,29 @@ type BufferPool interface {
String
()
string
String
()
string
}
}
type
G
cBufferPool
struct
{
type
g
cBufferPool
struct
{
}
}
// NewGcBufferPool is just a fallback to the standard allocation routines.
// NewGcBufferPool is just a fallback to the standard allocation routines.
func
NewGcBufferPool
()
*
Gc
BufferPool
{
func
NewGcBufferPool
()
BufferPool
{
return
&
G
cBufferPool
{}
return
&
g
cBufferPool
{}
}
}
func
(
p
*
GcBufferPool
)
AllocBuffer
(
size
uint32
)
[]
byte
{
func
(
p
*
gcBufferPool
)
String
()
string
{
return
"gc"
}
func
(
p
*
gcBufferPool
)
AllocBuffer
(
size
uint32
)
[]
byte
{
return
make
([]
byte
,
size
)
return
make
([]
byte
,
size
)
}
}
func
(
p
*
G
cBufferPool
)
FreeBuffer
(
slice
[]
byte
)
{
func
(
p
*
g
cBufferPool
)
FreeBuffer
(
slice
[]
byte
)
{
}
}
// BufferPool implements a pool of buffers that returns slices with
// BufferPool implements a pool of buffers that returns slices with
// capacity of a multiple of PAGESIZE, which have possibly been used,
// capacity of a multiple of PAGESIZE, which have possibly been used,
// and may contain random contents.
// and may contain random contents.
type
B
ufferPoolImpl
struct
{
type
b
ufferPoolImpl
struct
{
lock
sync
.
Mutex
lock
sync
.
Mutex
// For each page size multiple a list of slice pointers.
// For each page size multiple a list of slice pointers.
...
@@ -48,14 +52,14 @@ type BufferPoolImpl struct {
...
@@ -48,14 +52,14 @@ type BufferPoolImpl struct {
createdBuffers
int
createdBuffers
int
}
}
func
NewBufferPool
()
*
BufferPoolImp
l
{
func
NewBufferPool
()
BufferPoo
l
{
bp
:=
new
(
B
ufferPoolImpl
)
bp
:=
new
(
b
ufferPoolImpl
)
bp
.
buffersBySize
=
make
([][][]
byte
,
0
,
32
)
bp
.
buffersBySize
=
make
([][][]
byte
,
0
,
32
)
bp
.
outstandingBuffers
=
make
(
map
[
uintptr
]
bool
)
bp
.
outstandingBuffers
=
make
(
map
[
uintptr
]
bool
)
return
bp
return
bp
}
}
func
(
p
*
B
ufferPoolImpl
)
String
()
string
{
func
(
p
*
b
ufferPoolImpl
)
String
()
string
{
p
.
lock
.
Lock
()
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
defer
p
.
lock
.
Unlock
()
...
@@ -70,7 +74,7 @@ func (p *BufferPoolImpl) String() string {
...
@@ -70,7 +74,7 @@ func (p *BufferPoolImpl) String() string {
strings
.
Join
(
result
,
", "
))
strings
.
Join
(
result
,
", "
))
}
}
func
(
p
*
B
ufferPoolImpl
)
getBuffer
(
pageCount
int
)
[]
byte
{
func
(
p
*
b
ufferPoolImpl
)
getBuffer
(
pageCount
int
)
[]
byte
{
for
;
pageCount
<
len
(
p
.
buffersBySize
);
pageCount
++
{
for
;
pageCount
<
len
(
p
.
buffersBySize
);
pageCount
++
{
bufferList
:=
p
.
buffersBySize
[
pageCount
]
bufferList
:=
p
.
buffersBySize
[
pageCount
]
if
len
(
bufferList
)
>
0
{
if
len
(
bufferList
)
>
0
{
...
@@ -83,7 +87,7 @@ func (p *BufferPoolImpl) getBuffer(pageCount int) []byte {
...
@@ -83,7 +87,7 @@ func (p *BufferPoolImpl) getBuffer(pageCount int) []byte {
return
nil
return
nil
}
}
func
(
p
*
B
ufferPoolImpl
)
addBuffer
(
slice
[]
byte
,
pages
int
)
{
func
(
p
*
b
ufferPoolImpl
)
addBuffer
(
slice
[]
byte
,
pages
int
)
{
for
len
(
p
.
buffersBySize
)
<=
int
(
pages
)
{
for
len
(
p
.
buffersBySize
)
<=
int
(
pages
)
{
p
.
buffersBySize
=
append
(
p
.
buffersBySize
,
make
([][]
byte
,
0
))
p
.
buffersBySize
=
append
(
p
.
buffersBySize
,
make
([][]
byte
,
0
))
}
}
...
@@ -92,7 +96,7 @@ func (p *BufferPoolImpl) addBuffer(slice []byte, pages int) {
...
@@ -92,7 +96,7 @@ func (p *BufferPoolImpl) addBuffer(slice []byte, pages int) {
// AllocBuffer creates a buffer of at least the given size. After use,
// AllocBuffer creates a buffer of at least the given size. After use,
// it should be deallocated with FreeBuffer().
// it should be deallocated with FreeBuffer().
func
(
p
*
B
ufferPoolImpl
)
AllocBuffer
(
size
uint32
)
[]
byte
{
func
(
p
*
b
ufferPoolImpl
)
AllocBuffer
(
size
uint32
)
[]
byte
{
sz
:=
int
(
size
)
sz
:=
int
(
size
)
if
sz
<
PAGESIZE
{
if
sz
<
PAGESIZE
{
sz
=
PAGESIZE
sz
=
PAGESIZE
...
@@ -128,7 +132,7 @@ func (p *BufferPoolImpl) AllocBuffer(size uint32) []byte {
...
@@ -128,7 +132,7 @@ func (p *BufferPoolImpl) AllocBuffer(size uint32) []byte {
// FreeBuffer takes back a buffer if it was allocated through
// FreeBuffer takes back a buffer if it was allocated through
// AllocBuffer. It is not an error to call FreeBuffer() on a slice
// AllocBuffer. It is not an error to call FreeBuffer() on a slice
// obtained elsewhere.
// obtained elsewhere.
func
(
p
*
B
ufferPoolImpl
)
FreeBuffer
(
slice
[]
byte
)
{
func
(
p
*
b
ufferPoolImpl
)
FreeBuffer
(
slice
[]
byte
)
{
if
slice
==
nil
{
if
slice
==
nil
{
return
return
}
}
...
...
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