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
ef80cb74
Commit
ef80cb74
authored
Dec 23, 2017
by
rkfg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add templated put/get registry methods
parent
bec8b3fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
10 deletions
+35
-10
libcaf_core/caf/actor_registry.hpp
libcaf_core/caf/actor_registry.hpp
+30
-4
libcaf_core/src/actor_registry.cpp
libcaf_core/src/actor_registry.cpp
+5
-6
No files found.
libcaf_core/caf/actor_registry.hpp
View file @
ef80cb74
...
...
@@ -29,6 +29,7 @@
#include "caf/fwd.hpp"
#include "caf/actor.hpp"
#include "caf/actor_cast.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/actor_control_block.hpp"
...
...
@@ -49,10 +50,16 @@ public:
~
actor_registry
();
/// Returns the local actor associated to `key`.
strong_actor_ptr
get
(
actor_id
key
)
const
;
template
<
class
T
=
strong_actor_ptr
>
T
get
(
actor_id
key
)
const
{
return
actor_cast
<
T
>
(
get_impl
(
key
));
}
/// Associates a local actor with its ID.
void
put
(
actor_id
key
,
strong_actor_ptr
val
);
template
<
class
T
>
void
put
(
actor_id
key
,
const
T
&
val
)
{
put_impl
(
key
,
actor_cast
<
strong_actor_ptr
>
(
val
));
}
/// Removes an actor from this registry,
/// leaving `reason` for future reference.
...
...
@@ -72,10 +79,17 @@ public:
void
await_running_count_equal
(
size_t
expected
)
const
;
/// Returns the actor associated with `key` or `invalid_actor`.
strong_actor_ptr
get
(
atom_value
key
)
const
;
template
<
class
T
=
strong_actor_ptr
>
T
get
(
atom_value
key
)
const
{
return
actor_cast
<
T
>
(
get_impl
(
key
));
}
/// Associates given actor to `key`.
void
put
(
atom_value
key
,
strong_actor_ptr
value
);
template
<
class
T
>
void
put
(
atom_value
key
,
const
T
&
value
)
{
// using reference here and before to allow putting a scoped_actor without calling .ptr()
put_impl
(
key
,
actor_cast
<
strong_actor_ptr
>
(
value
));
}
/// Removes a name mapping.
void
erase
(
atom_value
key
);
...
...
@@ -91,6 +105,18 @@ private:
// Stops this component.
void
stop
();
/// Returns the local actor associated to `key`.
strong_actor_ptr
get_impl
(
actor_id
key
)
const
;
/// Associates a local actor with its ID.
void
put_impl
(
actor_id
key
,
strong_actor_ptr
val
);
/// Returns the actor associated with `key` or `invalid_actor`.
strong_actor_ptr
get_impl
(
atom_value
key
)
const
;
/// Associates given actor to `key`.
void
put_impl
(
atom_value
key
,
strong_actor_ptr
value
);
using
entries
=
std
::
unordered_map
<
actor_id
,
strong_actor_ptr
>
;
actor_registry
(
actor_system
&
sys
);
...
...
libcaf_core/src/actor_registry.cpp
View file @
ef80cb74
...
...
@@ -28,7 +28,6 @@
#include "caf/sec.hpp"
#include "caf/locks.hpp"
#include "caf/logger.hpp"
#include "caf/actor_cast.hpp"
#include "caf/attachable.hpp"
#include "caf/exit_reason.hpp"
#include "caf/actor_system.hpp"
...
...
@@ -56,7 +55,7 @@ actor_registry::actor_registry(actor_system& sys) : running_(0), system_(sys) {
// nop
}
strong_actor_ptr
actor_registry
::
get
(
actor_id
key
)
const
{
strong_actor_ptr
actor_registry
::
get
_impl
(
actor_id
key
)
const
{
shared_guard
guard
(
instances_mtx_
);
auto
i
=
entries_
.
find
(
key
);
if
(
i
!=
entries_
.
end
())
...
...
@@ -65,7 +64,7 @@ strong_actor_ptr actor_registry::get(actor_id key) const {
return
nullptr
;
}
void
actor_registry
::
put
(
actor_id
key
,
strong_actor_ptr
val
)
{
void
actor_registry
::
put
_impl
(
actor_id
key
,
strong_actor_ptr
val
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
key
));
if
(
!
val
)
return
;
...
...
@@ -119,7 +118,7 @@ void actor_registry::await_running_count_equal(size_t expected) const {
}
}
strong_actor_ptr
actor_registry
::
get
(
atom_value
key
)
const
{
strong_actor_ptr
actor_registry
::
get
_impl
(
atom_value
key
)
const
{
shared_guard
guard
{
named_entries_mtx_
};
auto
i
=
named_entries_
.
find
(
key
);
if
(
i
==
named_entries_
.
end
())
...
...
@@ -127,10 +126,10 @@ strong_actor_ptr actor_registry::get(atom_value key) const {
return
i
->
second
;
}
void
actor_registry
::
put
(
atom_value
key
,
strong_actor_ptr
value
)
{
void
actor_registry
::
put
_impl
(
atom_value
key
,
strong_actor_ptr
value
)
{
if
(
value
)
value
->
get
()
->
attach_functor
([
=
]
{
system_
.
registry
().
put
(
key
,
nullptr
);
system_
.
registry
().
put
_impl
(
key
,
nullptr
);
});
exclusive_guard
guard
{
named_entries_mtx_
};
named_entries_
.
emplace
(
key
,
std
::
move
(
value
));
...
...
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