Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
7f17b7bd
Commit
7f17b7bd
authored
Aug 28, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure reading far pointers is thread-safe.
parent
3c7505d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
8 deletions
+6
-8
arena.c++
c++/src/capnp/arena.c++
+4
-6
arena.h
c++/src/capnp/arena.h
+1
-1
message.h
c++/src/capnp/message.h
+1
-1
No files found.
c++/src/capnp/arena.c++
View file @
7f17b7bd
...
...
@@ -63,12 +63,10 @@ SegmentReader* ReaderArena::tryGetSegment(SegmentId id) {
}
}
// TODO(someday): Lock a mutex so that reading is thread-safe. Take a reader lock during the
// first lookup, unlock it before calling getSegment(), then take a writer lock to update the
// map. Bleh, lazy initialization is sad.
auto
lock
=
moreSegments
.
lockExclusive
();
SegmentMap
*
segments
=
nullptr
;
KJ_IF_MAYBE
(
s
,
moreSegments
)
{
KJ_IF_MAYBE
(
s
,
*
lock
)
{
auto
iter
=
s
->
find
(
id
.
value
);
if
(
iter
!=
s
->
end
())
{
return
iter
->
second
.
get
();
...
...
@@ -81,11 +79,11 @@ SegmentReader* ReaderArena::tryGetSegment(SegmentId id) {
return
nullptr
;
}
if
(
moreSegments
==
nullptr
)
{
if
(
*
lock
==
nullptr
)
{
// OK, the segment exists, so allocate the map.
auto
s
=
kj
::
heap
<
SegmentMap
>
();
segments
=
s
;
moreSegments
=
mv
(
s
);
*
lock
=
mv
(
s
);
}
auto
segment
=
kj
::
heap
<
SegmentReader
>
(
this
,
id
,
newSegment
,
&
readLimiter
);
...
...
c++/src/capnp/arena.h
View file @
7f17b7bd
...
...
@@ -171,7 +171,7 @@ private:
SegmentReader
segment0
;
typedef
std
::
unordered_map
<
uint
,
kj
::
Own
<
SegmentReader
>>
SegmentMap
;
kj
::
M
aybe
<
kj
::
Own
<
SegmentMap
>>
moreSegments
;
kj
::
M
utexGuarded
<
kj
::
Maybe
<
kj
::
Own
<
SegmentMap
>
>>
moreSegments
;
};
class
BuilderArena
final
:
public
Arena
{
...
...
c++/src/capnp/message.h
View file @
7f17b7bd
...
...
@@ -124,7 +124,7 @@ private:
// because we don't want clients to have to #include arena.h, which itself includes a bunch of
// big STL headers. We don't use a pointer to a ReaderArena because that would require an
// extra malloc on every message which could be expensive when processing small messages.
void
*
arenaSpace
[
15
];
void
*
arenaSpace
[
15
+
sizeof
(
kj
::
MutexGuarded
<
void
*>
)
/
sizeof
(
void
*
)
];
bool
allocatedArena
;
_
::
ReaderArena
*
arena
()
{
return
reinterpret_cast
<
_
::
ReaderArena
*>
(
arenaSpace
);
}
...
...
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