Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
7fe66f90
Commit
7fe66f90
authored
Aug 20, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
take some load off select() by reading chunks from pipe
parent
81634aa2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
61 deletions
+79
-61
src/middleman.cpp
src/middleman.cpp
+70
-60
src/network_manager.cpp
src/network_manager.cpp
+9
-1
No files found.
src/middleman.cpp
View file @
7fe66f90
...
@@ -555,11 +555,20 @@ class middleman_overseer : public network_channel {
...
@@ -555,11 +555,20 @@ class middleman_overseer : public network_channel {
bool
continue_reading
()
{
bool
continue_reading
()
{
DEBUG
(
"middleman_overseer::continue_reading"
);
DEBUG
(
"middleman_overseer::continue_reading"
);
uint32_t
dummy
;
static
constexpr
size_t
num_dummies
=
256
;
if
(
::
read
(
read_handle
(),
&
dummy
,
sizeof
(
dummy
))
!=
sizeof
(
dummy
))
{
uint8_t
dummies
[
num_dummies
];
auto
read_result
=
::
read
(
read_handle
(),
dummies
,
num_dummies
);
if
(
read_result
<
0
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
// try again later
return
true
;
}
else
{
CPPA_CRITICAL
(
"cannot read from pipe"
);
CPPA_CRITICAL
(
"cannot read from pipe"
);
}
}
}
atomic_thread_fence
(
memory_order_seq_cst
);
atomic_thread_fence
(
memory_order_seq_cst
);
for
(
int
i
=
0
;
i
<
read_result
;
++
i
)
{
unique_ptr
<
middleman_message
>
msg
(
m_queue
.
try_pop
());
unique_ptr
<
middleman_message
>
msg
(
m_queue
.
try_pop
());
if
(
!
msg
)
{
CPPA_CRITICAL
(
"nullptr dequeued"
);
}
if
(
!
msg
)
{
CPPA_CRITICAL
(
"nullptr dequeued"
);
}
switch
(
msg
->
type
)
{
switch
(
msg
->
type
)
{
...
@@ -625,6 +634,7 @@ class middleman_overseer : public network_channel {
...
@@ -625,6 +634,7 @@ class middleman_overseer : public network_channel {
break
;
break
;
}
}
}
}
}
return
true
;
return
true
;
}
}
...
...
src/network_manager.cpp
View file @
7fe66f90
...
@@ -65,6 +65,14 @@ struct network_manager_impl : network_manager {
...
@@ -65,6 +65,14 @@ struct network_manager_impl : network_manager {
}
}
// store pipe read handle in local variables for lambda expression
// store pipe read handle in local variables for lambda expression
int
pipe_fd0
=
pipe_fd
[
0
];
int
pipe_fd0
=
pipe_fd
[
0
];
// set read handle to nonblocking
auto
flags
=
fcntl
(
pipe_fd0
,
F_GETFL
,
0
);
if
(
flags
==
-
1
)
{
throw
network_error
(
"unable to read socket flags"
);
}
if
(
fcntl
(
pipe_fd0
,
F_SETFL
,
flags
|
O_NONBLOCK
)
<
0
)
{
CPPA_CRITICAL
(
"unable to set pipe read handle to nonblock"
);
}
// start threads
// start threads
m_middleman_thread
=
std
::
thread
([
this
,
pipe_fd0
]
{
m_middleman_thread
=
std
::
thread
([
this
,
pipe_fd0
]
{
middleman_loop
(
pipe_fd0
,
this
->
m_middleman_queue
);
middleman_loop
(
pipe_fd0
,
this
->
m_middleman_queue
);
...
@@ -82,7 +90,7 @@ struct network_manager_impl : network_manager {
...
@@ -82,7 +90,7 @@ struct network_manager_impl : network_manager {
void
send_to_middleman
(
std
::
unique_ptr
<
middleman_message
>
msg
)
{
void
send_to_middleman
(
std
::
unique_ptr
<
middleman_message
>
msg
)
{
m_middleman_queue
.
_push_back
(
msg
.
release
());
m_middleman_queue
.
_push_back
(
msg
.
release
());
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
std
::
uint
32
_t
dummy
=
0
;
std
::
uint
8
_t
dummy
=
0
;
if
(
write
(
pipe_fd
[
1
],
&
dummy
,
sizeof
(
dummy
))
!=
sizeof
(
dummy
))
{
if
(
write
(
pipe_fd
[
1
],
&
dummy
,
sizeof
(
dummy
))
!=
sizeof
(
dummy
))
{
CPPA_CRITICAL
(
"cannot write to pipe"
);
CPPA_CRITICAL
(
"cannot write to pipe"
);
}
}
...
...
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