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
463ebbfe
Unverified
Commit
463ebbfe
authored
Dec 25, 2017
by
Dominik Charousset
Committed by
GitHub
Dec 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #637
Add templated put/get registry methods
parents
f2473e03
ef80cb74
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 @
463ebbfe
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/actor.hpp"
#include "caf/actor.hpp"
#include "caf/actor_cast.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/actor_control_block.hpp"
...
@@ -49,10 +50,16 @@ public:
...
@@ -49,10 +50,16 @@ public:
~
actor_registry
();
~
actor_registry
();
/// Returns the local actor associated to `key`.
/// 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.
/// 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,
/// Removes an actor from this registry,
/// leaving `reason` for future reference.
/// leaving `reason` for future reference.
...
@@ -72,10 +79,17 @@ public:
...
@@ -72,10 +79,17 @@ public:
void
await_running_count_equal
(
size_t
expected
)
const
;
void
await_running_count_equal
(
size_t
expected
)
const
;
/// Returns the actor associated with `key` or `invalid_actor`.
/// 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`.
/// 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.
/// Removes a name mapping.
void
erase
(
atom_value
key
);
void
erase
(
atom_value
key
);
...
@@ -91,6 +105,18 @@ private:
...
@@ -91,6 +105,18 @@ private:
// Stops this component.
// Stops this component.
void
stop
();
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
>
;
using
entries
=
std
::
unordered_map
<
actor_id
,
strong_actor_ptr
>
;
actor_registry
(
actor_system
&
sys
);
actor_registry
(
actor_system
&
sys
);
...
...
libcaf_core/src/actor_registry.cpp
View file @
463ebbfe
...
@@ -28,7 +28,6 @@
...
@@ -28,7 +28,6 @@
#include "caf/sec.hpp"
#include "caf/sec.hpp"
#include "caf/locks.hpp"
#include "caf/locks.hpp"
#include "caf/logger.hpp"
#include "caf/logger.hpp"
#include "caf/actor_cast.hpp"
#include "caf/attachable.hpp"
#include "caf/attachable.hpp"
#include "caf/exit_reason.hpp"
#include "caf/exit_reason.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
...
@@ -56,7 +55,7 @@ actor_registry::actor_registry(actor_system& sys) : running_(0), system_(sys) {
...
@@ -56,7 +55,7 @@ actor_registry::actor_registry(actor_system& sys) : running_(0), system_(sys) {
// nop
// 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_
);
shared_guard
guard
(
instances_mtx_
);
auto
i
=
entries_
.
find
(
key
);
auto
i
=
entries_
.
find
(
key
);
if
(
i
!=
entries_
.
end
())
if
(
i
!=
entries_
.
end
())
...
@@ -65,7 +64,7 @@ strong_actor_ptr actor_registry::get(actor_id key) const {
...
@@ -65,7 +64,7 @@ strong_actor_ptr actor_registry::get(actor_id key) const {
return
nullptr
;
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
));
CAF_LOG_TRACE
(
CAF_ARG
(
key
));
if
(
!
val
)
if
(
!
val
)
return
;
return
;
...
@@ -119,7 +118,7 @@ void actor_registry::await_running_count_equal(size_t expected) const {
...
@@ -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_
};
shared_guard
guard
{
named_entries_mtx_
};
auto
i
=
named_entries_
.
find
(
key
);
auto
i
=
named_entries_
.
find
(
key
);
if
(
i
==
named_entries_
.
end
())
if
(
i
==
named_entries_
.
end
())
...
@@ -127,10 +126,10 @@ strong_actor_ptr actor_registry::get(atom_value key) const {
...
@@ -127,10 +126,10 @@ strong_actor_ptr actor_registry::get(atom_value key) const {
return
i
->
second
;
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
)
if
(
value
)
value
->
get
()
->
attach_functor
([
=
]
{
value
->
get
()
->
attach_functor
([
=
]
{
system_
.
registry
().
put
(
key
,
nullptr
);
system_
.
registry
().
put
_impl
(
key
,
nullptr
);
});
});
exclusive_guard
guard
{
named_entries_mtx_
};
exclusive_guard
guard
{
named_entries_mtx_
};
named_entries_
.
emplace
(
key
,
std
::
move
(
value
));
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