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
993ad2c2
Commit
993ad2c2
authored
Aug 15, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced post_office & mailman by a single middleman that handles all asynchronous IO
parent
808b96c7
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
695 additions
and
98 deletions
+695
-98
CMakeLists.txt
CMakeLists.txt
+0
-2
cppa.files
cppa.files
+0
-4
cppa/detail/middleman.hpp
cppa/detail/middleman.hpp
+73
-4
cppa/detail/network_manager.hpp
cppa/detail/network_manager.hpp
+2
-5
src/actor_proxy.cpp
src/actor_proxy.cpp
+5
-3
src/middleman.cpp
src/middleman.cpp
+601
-48
src/network_manager.cpp
src/network_manager.cpp
+11
-27
src/unicast_network.cpp
src/unicast_network.cpp
+3
-5
No files found.
CMakeLists.txt
View file @
993ad2c2
...
@@ -99,14 +99,12 @@ set(LIBCPPA_SRC
...
@@ -99,14 +99,12 @@ set(LIBCPPA_SRC
src/ipv4_acceptor.cpp
src/ipv4_acceptor.cpp
src/ipv4_io_stream.cpp
src/ipv4_io_stream.cpp
src/local_actor.cpp
src/local_actor.cpp
src/mailman.cpp
src/middleman.cpp
src/middleman.cpp
src/network_manager.cpp
src/network_manager.cpp
src/object.cpp
src/object.cpp
src/object_array.cpp
src/object_array.cpp
src/partial_function.cpp
src/partial_function.cpp
src/pattern.cpp
src/pattern.cpp
src/post_office.cpp
src/primitive_variant.cpp
src/primitive_variant.cpp
src/process_information.cpp
src/process_information.cpp
src/receive.cpp
src/receive.cpp
...
...
cppa.files
View file @
993ad2c2
...
@@ -55,14 +55,12 @@ cppa/detail/get_behavior.hpp
...
@@ -55,14 +55,12 @@ cppa/detail/get_behavior.hpp
cppa/detail/group_manager.hpp
cppa/detail/group_manager.hpp
cppa/detail/implicit_conversions.hpp
cppa/detail/implicit_conversions.hpp
cppa/detail/list_member.hpp
cppa/detail/list_member.hpp
cppa/detail/mailman.hpp
cppa/detail/map_member.hpp
cppa/detail/map_member.hpp
cppa/detail/matches.hpp
cppa/detail/matches.hpp
cppa/detail/network_manager.hpp
cppa/detail/network_manager.hpp
cppa/detail/object_array.hpp
cppa/detail/object_array.hpp
cppa/detail/object_impl.hpp
cppa/detail/object_impl.hpp
cppa/detail/pair_member.hpp
cppa/detail/pair_member.hpp
cppa/detail/post_office.hpp
cppa/detail/primitive_member.hpp
cppa/detail/primitive_member.hpp
cppa/detail/projection.hpp
cppa/detail/projection.hpp
cppa/detail/pseudo_tuple.hpp
cppa/detail/pseudo_tuple.hpp
...
@@ -199,13 +197,11 @@ src/fiber.cpp
...
@@ -199,13 +197,11 @@ src/fiber.cpp
src/group.cpp
src/group.cpp
src/group_manager.cpp
src/group_manager.cpp
src/local_actor.cpp
src/local_actor.cpp
src/mailman.cpp
src/network_manager.cpp
src/network_manager.cpp
src/object.cpp
src/object.cpp
src/object_array.cpp
src/object_array.cpp
src/partial_function.cpp
src/partial_function.cpp
src/pattern.cpp
src/pattern.cpp
src/post_office.cpp
src/primitive_variant.cpp
src/primitive_variant.cpp
src/process_information.cpp
src/process_information.cpp
src/receive.cpp
src/receive.cpp
...
...
cppa/detail/middleman.hpp
View file @
993ad2c2
...
@@ -31,10 +31,79 @@
...
@@ -31,10 +31,79 @@
#ifndef MIDDLEMAN_HPP
#ifndef MIDDLEMAN_HPP
#define MIDDLEMAN_HPP
#define MIDDLEMAN_HPP
class
middleman
#include <memory>
{
public:
#include "cppa/actor.hpp"
middleman
();
#include "cppa/process_information.hpp"
#include "cppa/util/acceptor.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/detail/network_manager.hpp"
#include "cppa/detail/addressed_message.hpp"
#include "cppa/detail/singleton_manager.hpp"
namespace
cppa
{
namespace
detail
{
enum
class
middleman_message_type
{
add_peer
,
publish
,
unpublish
,
outgoing_message
,
shutdown
};
struct
middleman_message
{
middleman_message
*
next
;
const
middleman_message_type
type
;
union
{
std
::
pair
<
util
::
io_stream_ptr_pair
,
process_information_ptr
>
new_peer
;
std
::
pair
<
std
::
unique_ptr
<
util
::
acceptor
>
,
actor_ptr
>
new_published_actor
;
actor_ptr
published_actor
;
std
::
pair
<
process_information_ptr
,
addressed_message
>
out_msg
;
};
middleman_message
();
middleman_message
(
util
::
io_stream_ptr_pair
,
process_information_ptr
);
middleman_message
(
std
::
unique_ptr
<
util
::
acceptor
>
,
actor_ptr
);
middleman_message
(
process_information_ptr
,
addressed_message
);
middleman_message
(
actor_ptr
);
~
middleman_message
();
template
<
typename
...
Args
>
static
inline
std
::
unique_ptr
<
middleman_message
>
create
(
Args
&&
...
args
)
{
return
std
::
unique_ptr
<
middleman_message
>
(
new
middleman_message
(
std
::
forward
<
Args
>
(
args
)...));
}
};
};
typedef
intrusive
::
single_reader_queue
<
middleman_message
>
middleman_queue
;
void
middleman_loop
(
int
pipe_rd
,
middleman_queue
&
queue
);
template
<
typename
...
Args
>
inline
void
send2mm
(
Args
&&
...
args
)
{
auto
nm
=
singleton_manager
::
get_network_manager
();
nm
->
send_to_middleman
(
middleman_message
::
create
(
std
::
forward
<
Args
>
(
args
)...));
}
inline
void
middleman_add_peer
(
util
::
io_stream_ptr_pair
peer_streams
,
process_information_ptr
peer_ptr
)
{
send2mm
(
std
::
move
(
peer_streams
),
std
::
move
(
peer_ptr
));
}
inline
void
middleman_publish
(
std
::
unique_ptr
<
util
::
acceptor
>
server
,
actor_ptr
published_actor
)
{
send2mm
(
std
::
move
(
server
),
std
::
move
(
published_actor
));
}
inline
void
middleman_unpublish
(
actor_ptr
whom
)
{
send2mm
(
std
::
move
(
whom
));
}
inline
void
middleman_enqueue
(
process_information_ptr
peer
,
addressed_message
outgoing_message
)
{
send2mm
(
std
::
move
(
peer
),
std
::
move
(
outgoing_message
));
}
}
}
// namespace cppa::detail
#endif // MIDDLEMAN_HPP
#endif // MIDDLEMAN_HPP
cppa/detail/network_manager.hpp
View file @
993ad2c2
...
@@ -37,8 +37,7 @@
...
@@ -37,8 +37,7 @@
namespace
cppa
{
namespace
detail
{
namespace
cppa
{
namespace
detail
{
struct
po_message
;
struct
middleman_message
;
struct
mm_message
;
class
network_manager
{
class
network_manager
{
...
@@ -50,9 +49,7 @@ class network_manager {
...
@@ -50,9 +49,7 @@ class network_manager {
virtual
void
stop
()
=
0
;
virtual
void
stop
()
=
0
;
virtual
void
send_to_post_office
(
std
::
unique_ptr
<
po_message
>
msg
)
=
0
;
virtual
void
send_to_middleman
(
std
::
unique_ptr
<
middleman_message
>
msg
)
=
0
;
virtual
void
send_to_mailman
(
std
::
unique_ptr
<
mm_message
>
msg
)
=
0
;
static
network_manager
*
create_singleton
();
static
network_manager
*
create_singleton
();
...
...
src/actor_proxy.cpp
View file @
993ad2c2
...
@@ -29,14 +29,17 @@
...
@@ -29,14 +29,17 @@
#include "cppa/atom.hpp"
#include "cppa/atom.hpp"
#include "cppa/to_string.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/actor_proxy.hpp"
#include "cppa/actor_proxy.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/detail/m
ail
man.hpp"
#include "cppa/detail/m
iddle
man.hpp"
#include "cppa/detail/network_manager.hpp"
#include "cppa/detail/network_manager.hpp"
#include "cppa/detail/singleton_manager.hpp"
#include "cppa/detail/singleton_manager.hpp"
#include <iostream>
namespace
cppa
{
namespace
cppa
{
actor_proxy
::
actor_proxy
(
std
::
uint32_t
mid
,
const
process_information_ptr
&
pptr
)
actor_proxy
::
actor_proxy
(
std
::
uint32_t
mid
,
const
process_information_ptr
&
pptr
)
...
@@ -49,8 +52,7 @@ void actor_proxy::forward_message(const process_information_ptr& piptr,
...
@@ -49,8 +52,7 @@ void actor_proxy::forward_message(const process_information_ptr& piptr,
any_tuple
&&
msg
,
any_tuple
&&
msg
,
message_id_t
id
)
{
message_id_t
id
)
{
detail
::
addressed_message
amsg
{
sender
,
this
,
std
::
move
(
msg
),
id
};
detail
::
addressed_message
amsg
{
sender
,
this
,
std
::
move
(
msg
),
id
};
detail
::
singleton_manager
::
get_network_manager
()
detail
::
middleman_enqueue
(
piptr
,
std
::
move
(
amsg
));
->
send_to_mailman
(
detail
::
mm_message
::
create
(
piptr
,
std
::
move
(
amsg
)));
}
}
void
actor_proxy
::
enqueue
(
actor
*
sender
,
any_tuple
msg
)
{
void
actor_proxy
::
enqueue
(
actor
*
sender
,
any_tuple
msg
)
{
...
...
src/middleman.cpp
View file @
993ad2c2
This diff is collapsed.
Click to expand it.
src/network_manager.cpp
View file @
993ad2c2
...
@@ -44,8 +44,7 @@
...
@@ -44,8 +44,7 @@
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/detail/mailman.hpp"
#include "cppa/detail/middleman.hpp"
#include "cppa/detail/post_office.hpp"
#include "cppa/detail/network_manager.hpp"
#include "cppa/detail/network_manager.hpp"
namespace
{
namespace
{
...
@@ -55,11 +54,8 @@ using namespace cppa::detail;
...
@@ -55,11 +54,8 @@ using namespace cppa::detail;
struct
network_manager_impl
:
network_manager
{
struct
network_manager_impl
:
network_manager
{
intrusive
::
single_reader_queue
<
mm_message
>
m_mailman_queue
;
middleman_queue
m_middleman_queue
;
std
::
thread
m_mailman_thread
;
std
::
thread
m_middleman_thread
;
intrusive
::
single_reader_queue
<
po_message
>
m_post_office_queue
;
std
::
thread
m_post_office_thread
;
int
pipe_fd
[
2
];
int
pipe_fd
[
2
];
...
@@ -70,47 +66,35 @@ struct network_manager_impl : network_manager {
...
@@ -70,47 +66,35 @@ 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
];
// start threads
// start threads
m_post_office_thread
=
std
::
thread
([
this
,
pipe_fd0
]
{
m_middleman_thread
=
std
::
thread
([
this
,
pipe_fd0
]
{
post_office_loop
(
pipe_fd0
,
this
->
m_post_office_queue
);
middleman_loop
(
pipe_fd0
,
this
->
m_middleman_queue
);
});
m_mailman_thread
=
std
::
thread
([
this
]
{
mailman_loop
(
this
->
m_mailman_queue
);
});
});
}
}
void
stop
()
{
// override
void
stop
()
{
// override
//m_mailman->enqueue(nullptr, make_any_tuple(atom("DONE")));
//m_mailman->enqueue(nullptr, make_any_tuple(atom("DONE")));
m_mailman_thread
.
join
();
send_to_middleman
(
middleman_message
::
create
());
// wait until mailman is done; post_office closes all sockets
m_middleman_thread
.
join
();
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
m_post_office_queue
.
push_back
(
new
po_message
);
//send_to_post_office(po_message{atom("DONE"), -1, 0});
m_post_office_thread
.
join
();
close
(
pipe_fd
[
0
]);
close
(
pipe_fd
[
0
]);
close
(
pipe_fd
[
1
]);
close
(
pipe_fd
[
1
]);
}
}
void
send_to_post_office
(
std
::
unique_ptr
<
po_message
>
msg
)
{
void
send_to_middleman
(
std
::
unique_ptr
<
middleman_message
>
msg
)
{
m_post_office_queue
.
push_back
(
msg
.
release
());
m_middleman_queue
.
_push_back
(
msg
.
release
());
std
::
atomic_thread_fence
(
std
::
memory_order_seq_cst
);
std
::
uint32_t
dummy
=
0
;
std
::
uint32_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"
);
}
}
}
}
void
send_to_mailman
(
std
::
unique_ptr
<
mm_message
>
msg
)
{
m_mailman_queue
.
push_back
(
msg
.
release
());
//m_mailman->enqueue(nullptr, std::move(msg));
}
};
};
}
// namespace <anonymous>
}
// namespace <anonymous>
namespace
cppa
{
namespace
detail
{
namespace
cppa
{
namespace
detail
{
network_manager
::~
network_manager
()
{
network_manager
::~
network_manager
()
{
}
}
network_manager
*
network_manager
::
create_singleton
()
{
network_manager
*
network_manager
::
create_singleton
()
{
return
new
network_manager_impl
;
return
new
network_manager_impl
;
...
...
src/unicast_network.cpp
View file @
993ad2c2
...
@@ -50,8 +50,7 @@
...
@@ -50,8 +50,7 @@
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
#include "cppa/detail/mailman.hpp"
#include "cppa/detail/middleman.hpp"
#include "cppa/detail/post_office.hpp"
#include "cppa/detail/ipv4_acceptor.hpp"
#include "cppa/detail/ipv4_acceptor.hpp"
#include "cppa/detail/ipv4_io_stream.hpp"
#include "cppa/detail/ipv4_io_stream.hpp"
#include "cppa/detail/actor_registry.hpp"
#include "cppa/detail/actor_registry.hpp"
...
@@ -68,7 +67,7 @@ namespace cppa {
...
@@ -68,7 +67,7 @@ namespace cppa {
void
publish
(
actor_ptr
whom
,
std
::
unique_ptr
<
util
::
acceptor
>
acceptor
)
{
void
publish
(
actor_ptr
whom
,
std
::
unique_ptr
<
util
::
acceptor
>
acceptor
)
{
if
(
!
whom
&&
!
acceptor
)
return
;
if
(
!
whom
&&
!
acceptor
)
return
;
detail
::
singleton_manager
::
get_actor_registry
()
->
put
(
whom
->
id
(),
whom
);
detail
::
singleton_manager
::
get_actor_registry
()
->
put
(
whom
->
id
(),
whom
);
detail
::
post_office
_publish
(
std
::
move
(
acceptor
),
whom
);
detail
::
middleman
_publish
(
std
::
move
(
acceptor
),
whom
);
}
}
actor_ptr
remote_actor
(
util
::
io_stream_ptr_pair
peer
)
{
actor_ptr
remote_actor
(
util
::
io_stream_ptr_pair
peer
)
{
...
@@ -85,8 +84,7 @@ actor_ptr remote_actor(util::io_stream_ptr_pair peer) {
...
@@ -85,8 +84,7 @@ actor_ptr remote_actor(util::io_stream_ptr_pair peer) {
peer
.
first
->
read
(
peer_node_id
.
data
(),
peer_node_id
.
size
());
peer
.
first
->
read
(
peer_node_id
.
data
(),
peer_node_id
.
size
());
process_information_ptr
pinfptr
(
new
process_information
(
peer_pid
,
peer_node_id
));
process_information_ptr
pinfptr
(
new
process_information
(
peer_pid
,
peer_node_id
));
//auto key = std::make_tuple(remote_actor_id, pinfptr->process_id(), pinfptr->node_id());
//auto key = std::make_tuple(remote_actor_id, pinfptr->process_id(), pinfptr->node_id());
detail
::
mailman_add_peer
(
peer
,
pinfptr
);
detail
::
middleman_add_peer
(
peer
,
pinfptr
);
detail
::
post_office_add_peer
(
peer
,
pinfptr
);
return
detail
::
get_actor_proxy_cache
().
get
(
remote_actor_id
,
return
detail
::
get_actor_proxy_cache
().
get
(
remote_actor_id
,
pinfptr
->
process_id
(),
pinfptr
->
process_id
(),
pinfptr
->
node_id
());
pinfptr
->
node_id
());
...
...
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