Commit 66d9e98c authored by Dominik Charousset's avatar Dominik Charousset

Deprecate .unsafe functions, close #507

parent 98e3e2b3
...@@ -115,6 +115,11 @@ public: ...@@ -115,6 +115,11 @@ public:
return static_cast<bool>(ptr_); return static_cast<bool>(ptr_);
} }
/// Queries whether this actor handle is invalid.
inline bool operator!() const {
return !ptr_;
}
/// Returns the address of the stored actor. /// Returns the address of the stored actor.
actor_addr address() const noexcept; actor_addr address() const noexcept;
...@@ -138,7 +143,7 @@ public: ...@@ -138,7 +143,7 @@ public:
/// Queries whether this object was constructed using /// Queries whether this object was constructed using
/// `unsafe_actor_handle_init` or is in moved-from state. /// `unsafe_actor_handle_init` or is in moved-from state.
bool unsafe() const { bool unsafe() const CAF_DEPRECATED {
return !ptr_; return !ptr_;
} }
......
...@@ -148,14 +148,14 @@ public: ...@@ -148,14 +148,14 @@ public:
} }
~function_view() { ~function_view() {
if (!impl_.unsafe()) if (impl_)
self_.~scoped_actor(); self_.~scoped_actor();
} }
function_view(function_view&& x) function_view(function_view&& x)
: timeout(x.timeout), : timeout(x.timeout),
impl_(std::move(x.impl_)) { impl_(std::move(x.impl_)) {
if (!impl_.unsafe()) { if (impl_) {
new (&self_) scoped_actor(impl_.home_system()); //(std::move(x.self_)); new (&self_) scoped_actor(impl_.home_system()); //(std::move(x.self_));
x.self_.~scoped_actor(); x.self_.~scoped_actor();
} }
...@@ -179,7 +179,7 @@ public: ...@@ -179,7 +179,7 @@ public:
>... >...
>::tuple_type>> >::tuple_type>>
expected<R> operator()(Ts&&... xs) { expected<R> operator()(Ts&&... xs) {
if (impl_.unsafe()) if (!impl_)
return sec::bad_function_call; return sec::bad_function_call;
error err; error err;
function_view_result<R> result; function_view_result<R> result;
...@@ -221,7 +221,7 @@ private: ...@@ -221,7 +221,7 @@ private:
} }
void new_self(const Actor& x) { void new_self(const Actor& x) {
if (!x.unsafe()) if (x)
new (&self_) scoped_actor(x->home_system()); new (&self_) scoped_actor(x->home_system());
} }
......
...@@ -58,8 +58,7 @@ public: ...@@ -58,8 +58,7 @@ public:
/// Links this actor to `x`. /// Links this actor to `x`.
void link_to(const actor_addr& x) { void link_to(const actor_addr& x) {
auto ptr = actor_cast<strong_actor_ptr>(x); auto ptr = actor_cast<strong_actor_ptr>(x);
if (!ptr || ptr->get() == this) if (ptr && ptr->get() != this)
return;
link_impl(establish_link_op, ptr->get()); link_impl(establish_link_op, ptr->get());
} }
...@@ -67,16 +66,14 @@ public: ...@@ -67,16 +66,14 @@ public:
template <class ActorHandle> template <class ActorHandle>
void link_to(const ActorHandle& x) { void link_to(const ActorHandle& x) {
auto ptr = actor_cast<abstract_actor*>(x); auto ptr = actor_cast<abstract_actor*>(x);
if (!ptr || ptr == this) if (ptr && ptr != this)
return;
link_impl(establish_link_op, ptr); link_impl(establish_link_op, ptr);
} }
/// Unlinks this actor from `x`. /// Unlinks this actor from `x`.
void unlink_from(const actor_addr& x) { void unlink_from(const actor_addr& x) {
auto ptr = actor_cast<strong_actor_ptr>(x); auto ptr = actor_cast<strong_actor_ptr>(x);
if (!ptr || ptr->get() == this) if (ptr && ptr->get() != this)
return;
link_impl(remove_link_op, ptr->get()); link_impl(remove_link_op, ptr->get());
} }
...@@ -84,8 +81,7 @@ public: ...@@ -84,8 +81,7 @@ public:
template <class ActorHandle> template <class ActorHandle>
void unlink_from(const ActorHandle& x) { void unlink_from(const ActorHandle& x) {
auto ptr = actor_cast<abstract_actor*>(x); auto ptr = actor_cast<abstract_actor*>(x);
if (!ptr || ptr == this) if (ptr && ptr != this)
return;
link_impl(remove_link_op, ptr); link_impl(remove_link_op, ptr);
} }
......
...@@ -174,6 +174,11 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -174,6 +174,11 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
return static_cast<bool>(ptr_); return static_cast<bool>(ptr_);
} }
/// Queries whether this actor handle is invalid.
inline bool operator!() const {
return !ptr_;
}
/// Queries the address of the stored actor. /// Queries the address of the stored actor.
actor_addr address() const noexcept { actor_addr address() const noexcept {
return {ptr_.get(), true}; return {ptr_.get(), true};
......
...@@ -33,7 +33,7 @@ forwarding_actor_proxy::forwarding_actor_proxy(actor_config& cfg, actor mgr) ...@@ -33,7 +33,7 @@ forwarding_actor_proxy::forwarding_actor_proxy(actor_config& cfg, actor mgr)
} }
forwarding_actor_proxy::~forwarding_actor_proxy() { forwarding_actor_proxy::~forwarding_actor_proxy() {
if (!manager_.unsafe()) if (manager_)
anon_send(manager_, make_message(delete_atom::value, node(), id())); anon_send(manager_, make_message(delete_atom::value, node(), id()));
} }
...@@ -54,7 +54,7 @@ void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender, ...@@ -54,7 +54,7 @@ void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender,
<< CAF_ARG(mid) << CAF_ARG(msg)); << CAF_ARG(mid) << CAF_ARG(msg));
forwarding_stack tmp; forwarding_stack tmp;
shared_lock<detail::shared_spinlock> guard_(manager_mtx_); shared_lock<detail::shared_spinlock> guard_(manager_mtx_);
if (!manager_.unsafe()) if (manager_)
manager_->enqueue(nullptr, invalid_message_id, manager_->enqueue(nullptr, invalid_message_id,
make_message(forward_atom::value, std::move(sender), make_message(forward_atom::value, std::move(sender),
fwd ? *fwd : tmp, fwd ? *fwd : tmp,
......
...@@ -75,18 +75,17 @@ void local_actor::request_response_timeout(const duration& d, message_id mid) { ...@@ -75,18 +75,17 @@ void local_actor::request_response_timeout(const duration& d, message_id mid) {
} }
void local_actor::monitor(abstract_actor* ptr) { void local_actor::monitor(abstract_actor* ptr) {
if (!ptr) if (ptr)
return;
ptr->attach(default_attachable::make_monitor(ptr->address(), address())); ptr->attach(default_attachable::make_monitor(ptr->address(), address()));
} }
void local_actor::demonitor(const actor_addr& whom) { void local_actor::demonitor(const actor_addr& whom) {
CAF_LOG_TRACE(CAF_ARG(whom)); CAF_LOG_TRACE(CAF_ARG(whom));
auto ptr = actor_cast<strong_actor_ptr>(whom); auto ptr = actor_cast<strong_actor_ptr>(whom);
if (!ptr) if (ptr) {
return;
default_attachable::observe_token tk{address(), default_attachable::monitor}; default_attachable::observe_token tk{address(), default_attachable::monitor};
ptr->get()->detach(tk); ptr->get()->detach(tk);
}
} }
void local_actor::on_exit() { void local_actor::on_exit() {
......
...@@ -174,7 +174,7 @@ struct fixture { ...@@ -174,7 +174,7 @@ struct fixture {
template <class T> template <class T>
bool value_is(const char* key, const T& what) { bool value_is(const char* key, const T& what) {
if (!config_server.unsafe()) if (config_server)
return config_server_has(key, what); return config_server_has(key, what);
auto& cv = values[key]; auto& cv = values[key];
using type = using type =
...@@ -192,7 +192,7 @@ struct fixture { ...@@ -192,7 +192,7 @@ struct fixture {
} }
size_t num_values() { size_t num_values() {
if (!config_server.unsafe()) { if (config_server) {
size_t result = 0; size_t result = 0;
scoped_actor self{system}; scoped_actor self{system};
self->request(config_server, infinite, get_atom::value, "*").receive( self->request(config_server, infinite, get_atom::value, "*").receive(
......
...@@ -47,7 +47,7 @@ second_stage::behavior_type typed_second_stage() { ...@@ -47,7 +47,7 @@ second_stage::behavior_type typed_second_stage() {
return x * y; return x * y;
}, },
[](double x) { [](double x) {
return 23.0f * x; return 23.0 * x;
} }
}; };
} }
......
...@@ -85,9 +85,9 @@ struct fixture { ...@@ -85,9 +85,9 @@ struct fixture {
} }
); );
if (expect_fail) if (expect_fail)
CAF_REQUIRE(result.unsafe()); CAF_REQUIRE(!result);
else else
CAF_REQUIRE(!result.unsafe()); CAF_REQUIRE(result);
return result; return result;
} }
...@@ -121,7 +121,7 @@ CAF_TEST(unpublishing) { ...@@ -121,7 +121,7 @@ CAF_TEST(unpublishing) {
down_msg{testee.address(), exit_reason::normal}); down_msg{testee.address(), exit_reason::normal});
// must fail now // must fail now
auto x2 = remote_actor("127.0.0.1", port, true); auto x2 = remote_actor("127.0.0.1", port, true);
CAF_CHECK(x2.unsafe()); CAF_CHECK(!x2);
} }
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment