Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
folly
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
folly
Commits
2c73945c
Commit
2c73945c
authored
Apr 22, 2014
by
Tom Jackson
Committed by
Dave Watson
May 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
std::move-able MemoryMapping
Test Plan: unit tests Reviewed By: lucian@fb.com FB internal diff: D1290632
parent
9c428ab9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
1 deletion
+54
-1
folly/MemoryMapping.cpp
folly/MemoryMapping.cpp
+25
-0
folly/MemoryMapping.h
folly/MemoryMapping.h
+9
-1
folly/test/MemoryMappingTest.cpp
folly/test/MemoryMappingTest.cpp
+20
-0
No files found.
folly/MemoryMapping.cpp
View file @
2c73945c
...
...
@@ -37,6 +37,14 @@ MemoryMapping::MemoryMapping()
,
locked_
(
false
)
{
}
MemoryMapping
::
MemoryMapping
(
MemoryMapping
&&
other
)
:
mapStart_
(
nullptr
)
,
mapLength_
(
0
)
,
pageSize_
(
0
)
,
locked_
(
false
)
{
swap
(
other
);
}
MemoryMapping
::
MemoryMapping
(
File
file
,
off_t
offset
,
off_t
length
,
off_t
pageSize
)
:
mapStart_
(
nullptr
)
...
...
@@ -229,9 +237,26 @@ void MemoryMapping::advise(int advice) const {
}
}
MemoryMapping
&
MemoryMapping
::
operator
=
(
MemoryMapping
other
)
{
swap
(
other
);
return
*
this
;
}
void
MemoryMapping
::
swap
(
MemoryMapping
&
other
)
{
using
std
::
swap
;
swap
(
this
->
file_
,
other
.
file_
);
swap
(
this
->
mapStart_
,
other
.
mapStart_
);
swap
(
this
->
mapLength_
,
other
.
mapLength_
);
swap
(
this
->
pageSize_
,
other
.
pageSize_
);
swap
(
this
->
locked_
,
other
.
locked_
);
swap
(
this
->
data_
,
other
.
data_
);
}
WritableMemoryMapping
::
WritableMemoryMapping
(
File
file
,
off_t
offset
,
off_t
length
,
off_t
pageSize
)
{
init
(
std
::
move
(
file
),
offset
,
length
,
pageSize
,
PROT_READ
|
PROT_WRITE
,
true
);
}
void
swap
(
MemoryMapping
&
a
,
MemoryMapping
&
b
)
{
a
.
swap
(
b
);
}
}
// namespace folly
folly/MemoryMapping.h
View file @
2c73945c
...
...
@@ -67,8 +67,14 @@ class MemoryMapping : boost::noncopyable {
off_t
length
=-
1
,
off_t
pageSize
=
0
);
MemoryMapping
(
MemoryMapping
&&
);
virtual
~
MemoryMapping
();
MemoryMapping
&
operator
=
(
MemoryMapping
);
void
swap
(
MemoryMapping
&
other
);
/**
* Lock the pages in memory
*/
...
...
@@ -79,7 +85,7 @@ class MemoryMapping : boost::noncopyable {
* If dontneed is true, the kernel is instructed to release these pages
* (per madvise(MADV_DONTNEED)).
*/
void
munlock
(
bool
dontneed
=
false
);
void
munlock
(
bool
dontneed
=
false
);
/**
* Hint that these pages will be scanned linearly.
...
...
@@ -172,6 +178,8 @@ class WritableMemoryMapping : public MemoryMapping {
}
};
void
swap
(
MemoryMapping
&
,
MemoryMapping
&
);
}
// namespace folly
#endif
/* FOLLY_MEMORYMAPPING_H_ */
folly/test/MemoryMappingTest.cpp
View file @
2c73945c
...
...
@@ -38,6 +38,26 @@ TEST(MemoryMapping, Basic) {
}
}
TEST
(
MemoryMapping
,
Move
)
{
File
f
=
File
::
temporary
();
{
WritableMemoryMapping
m
(
File
(
f
.
fd
()),
0
,
sizeof
(
double
)
*
2
);
double
volatile
*
d
=
m
.
asWritableRange
<
double
>
().
data
();
d
[
0
]
=
37
*
M_PI
;
WritableMemoryMapping
m2
(
std
::
move
(
m
));
double
volatile
*
d2
=
m2
.
asWritableRange
<
double
>
().
data
();
d2
[
1
]
=
39
*
M_PI
;
}
{
MemoryMapping
m
(
File
(
f
.
fd
()),
0
,
sizeof
(
double
));
const
double
volatile
*
d
=
m
.
asRange
<
double
>
().
data
();
EXPECT_EQ
(
d
[
0
],
37
*
M_PI
);
MemoryMapping
m2
(
std
::
move
(
m
));
const
double
volatile
*
d2
=
m2
.
asRange
<
double
>
().
data
();
EXPECT_EQ
(
d2
[
1
],
39
*
M_PI
);
}
}
TEST
(
MemoryMapping
,
DoublyMapped
)
{
File
f
=
File
::
temporary
();
// two mappings of the same memory, different addresses.
...
...
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