Commit b1381c27 authored by Dominik Charousset's avatar Dominik Charousset

Fix several warnings

parent c516ce0b
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
* - ./build/bin/broker -c localhost 4242 * * - ./build/bin/broker -c localhost 4242 *
\ ******************************************************************************/ \ ******************************************************************************/
// This file is partially included in the manual, do not modify // Manual refs: 46-50 (Actors.tex)
// without updating the references in the *.tex files!
// Manual references: lines 46-50 (Actors.tex)
#include "caf/config.hpp" #include "caf/config.hpp"
...@@ -38,6 +36,8 @@ using std::endl; ...@@ -38,6 +36,8 @@ using std::endl;
using namespace caf; using namespace caf;
using namespace caf::io; using namespace caf::io;
namespace {
using ping_atom = atom_constant<atom("ping")>; using ping_atom = atom_constant<atom("ping")>;
using pong_atom = atom_constant<atom("pong")>; using pong_atom = atom_constant<atom("pong")>;
using kickoff_atom = atom_constant<atom("kickoff")>; using kickoff_atom = atom_constant<atom("kickoff")>;
...@@ -175,10 +175,6 @@ behavior server(broker* self, const actor& buddy) { ...@@ -175,10 +175,6 @@ behavior server(broker* self, const actor& buddy) {
}; };
} }
optional<uint16_t> as_u16(const std::string& str) {
return static_cast<uint16_t>(stoul(str));
}
class config : public actor_system_config { class config : public actor_system_config {
public: public:
uint16_t port = 0; uint16_t port = 0;
...@@ -211,4 +207,6 @@ void caf_main(actor_system& system, const config& cfg) { ...@@ -211,4 +207,6 @@ void caf_main(actor_system& system, const config& cfg) {
send_as(io_actor, ping_actor, kickoff_atom::value, io_actor); send_as(io_actor, ping_actor, kickoff_atom::value, io_actor);
} }
} // namespace <anonymous>
CAF_MAIN(io::middleman) CAF_MAIN(io::middleman)
...@@ -11,6 +11,8 @@ using std::endl; ...@@ -11,6 +11,8 @@ using std::endl;
using namespace caf; using namespace caf;
using namespace caf::io; using namespace caf::io;
namespace {
using tick_atom = atom_constant<atom("tick")>; using tick_atom = atom_constant<atom("tick")>;
constexpr const char http_ok[] = R"__(HTTP/1.1 200 OK constexpr const char http_ok[] = R"__(HTTP/1.1 200 OK
...@@ -85,4 +87,6 @@ void caf_main(actor_system& system, const config& cfg) { ...@@ -85,4 +87,6 @@ void caf_main(actor_system& system, const config& cfg) {
anon_send_exit(server_actor, exit_reason::user_shutdown); anon_send_exit(server_actor, exit_reason::user_shutdown);
} }
} // namespace <anonymous>
CAF_MAIN(io::middleman) CAF_MAIN(io::middleman)
// Showcases how to add custom POD message types. // Showcases how to add custom POD message types.
// This file is referenced in the manual, do not modify without updating refs! // Manual refs: 23-26, 29-33, 87-90, 93-96 (ConfiguringActorApplications)
// ConfiguringActorApplications: 23-26, 29-33, 87-90, 93-96
#include <tuple>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cassert> #include <cassert>
...@@ -19,6 +17,8 @@ using std::vector; ...@@ -19,6 +17,8 @@ using std::vector;
using namespace caf; using namespace caf;
namespace {
// POD struct foo // POD struct foo
struct foo { struct foo {
std::vector<int> a; std::vector<int> a;
...@@ -112,7 +112,7 @@ void caf_main(actor_system& system, const config&) { ...@@ -112,7 +112,7 @@ void caf_main(actor_system& system, const config&) {
// must be equal // must be equal
assert(to_string(f1) == to_string(f2)); assert(to_string(f1) == to_string(f2));
// spawn a testee that receives two messages of user-defined type // spawn a testee that receives two messages of user-defined type
auto t = system.spawn(testee, 2); auto t = system.spawn(testee, 2u);
scoped_actor self{system}; scoped_actor self{system};
// send t a foo // send t a foo
self->send(t, foo{std::vector<int>{1, 2, 3, 4}, 5}); self->send(t, foo{std::vector<int>{1, 2, 3, 4}, 5});
...@@ -121,4 +121,6 @@ void caf_main(actor_system& system, const config&) { ...@@ -121,4 +121,6 @@ void caf_main(actor_system& system, const config&) {
self->await_all_other_actors_done(); self->await_all_other_actors_done();
} }
} // namespace <anonymous>
CAF_MAIN() CAF_MAIN()
...@@ -12,6 +12,8 @@ using std::make_pair; ...@@ -12,6 +12,8 @@ using std::make_pair;
using namespace caf; using namespace caf;
namespace {
// a simple class using getter and setter member functions // a simple class using getter and setter member functions
class foo { class foo {
public: public:
...@@ -72,4 +74,6 @@ void caf_main(actor_system& system, const config&) { ...@@ -72,4 +74,6 @@ void caf_main(actor_system& system, const config&) {
anon_send(system.spawn(testee), foo{1, 2}); anon_send(system.spawn(testee), foo{1, 2});
} }
} // namespace <anonymous>
CAF_MAIN() CAF_MAIN()
// Showcases how to add custom message types to CAF // Showcases custom message types that cannot provide
// if no friend access for serialization is possible. // friend access to the serialize() function.
// This file is referenced in the manual, do not modify without updating refs!
// ConfiguringActorApplications: 57-59, 64-66
// Manual refs: 57-59, 64-66 (ConfiguringActorApplications)
#include <utility> #include <utility>
#include <iostream> #include <iostream>
...@@ -16,6 +14,8 @@ using std::make_pair; ...@@ -16,6 +14,8 @@ using std::make_pair;
using namespace caf; using namespace caf;
namespace {
// identical to our second custom type example, // identical to our second custom type example,
// but without friend declarations // but without friend declarations
class foo { class foo {
...@@ -90,4 +90,6 @@ void caf_main(actor_system& system, const config&) { ...@@ -90,4 +90,6 @@ void caf_main(actor_system& system, const config&) {
anon_send(system.spawn(testee), foo{1, 2}); anon_send(system.spawn(testee), foo{1, 2});
} }
} // namespace <anonymous>
CAF_MAIN() CAF_MAIN()
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
* for both the blocking and the event-based API. * * for both the blocking and the event-based API. *
\******************************************************************************/ \******************************************************************************/
// This file is partially included in the manual, do not modify // Manual refs: lines 19-21, 31-65, 67-101, 134-139 (Actor)
// without updating the references in the *.tex files!
// Manual references: lines 17-21, 31-65, 67-101, and 134-139 (Actor.tex)
#include <iostream> #include <iostream>
...@@ -14,6 +12,8 @@ ...@@ -14,6 +12,8 @@
using std::endl; using std::endl;
using namespace caf; using namespace caf;
namespace {
using add_atom = atom_constant<atom("add")>; using add_atom = atom_constant<atom("add")>;
using sub_atom = atom_constant<atom("sub")>; using sub_atom = atom_constant<atom("sub")>;
...@@ -138,4 +138,6 @@ void caf_main(actor_system& system) { ...@@ -138,4 +138,6 @@ void caf_main(actor_system& system) {
tester(self, a1, 1, 2, a2, 3, 4, a3, 5, 6, a4, 7, 8, a5, 9, 10, a6, 11, 12); tester(self, a1, 1, 2, a2, 3, 4, a3, 5, 6, a4, 7, 8, a5, 9, 10, a6, 11, 12);
} }
} // namespace <anonymous>
CAF_MAIN() CAF_MAIN()
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
* A very basic, interactive divider. * * A very basic, interactive divider. *
\******************************************************************************/ \******************************************************************************/
// This file is partially included in the manual, do not modify // Manual refs: 19-25, 35-48, 63-73 (MessagePassing);
// without updating the references in the *.tex files! // 19-34, 51-56 (Error)
// Manual references: lines 19-25, 35-48, and 63-73 (MessagePassing.tex);
// lines 19-34, and 51-56 (Error.tex)
#include <iostream> #include <iostream>
...@@ -16,6 +14,8 @@ using std::endl; ...@@ -16,6 +14,8 @@ using std::endl;
using std::flush; using std::flush;
using namespace caf; using namespace caf;
namespace {
enum class math_error : uint8_t { enum class math_error : uint8_t {
division_by_zero = 1 division_by_zero = 1
}; };
...@@ -77,4 +77,6 @@ void caf_main(actor_system& system, const config&) { ...@@ -77,4 +77,6 @@ void caf_main(actor_system& system, const config&) {
); );
} }
} // namespace <anonymous>
CAF_MAIN() CAF_MAIN()
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
using std::endl; using std::endl;
using namespace caf; using namespace caf;
namespace {
using pop_atom = atom_constant<atom("pop")>; using pop_atom = atom_constant<atom("pop")>;
using push_atom = atom_constant<atom("push")>; using push_atom = atom_constant<atom("push")>;
...@@ -71,7 +73,7 @@ private: ...@@ -71,7 +73,7 @@ private:
void caf_main(actor_system& system) { void caf_main(actor_system& system) {
scoped_actor self{system}; scoped_actor self{system};
auto st = self->spawn<fixed_stack>(5); auto st = self->spawn<fixed_stack>(5u);
// fill stack // fill stack
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
self->send(st, push_atom::value, i); self->send(st, push_atom::value, i);
...@@ -92,4 +94,6 @@ void caf_main(actor_system& system) { ...@@ -92,4 +94,6 @@ void caf_main(actor_system& system) {
self->send_exit(st, exit_reason::user_shutdown); self->send_exit(st, exit_reason::user_shutdown);
} }
} // namespace <anonymous>
CAF_MAIN() CAF_MAIN()
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
// Run client at the same host: // Run client at the same host:
// - ./build/bin/distributed_math_actor -c -p 4242 // - ./build/bin/distributed_math_actor -c -p 4242
// This file is partially included in the manual, do not modify // Manual refs: 250-262 (ConfiguringActorSystems)
// without updating the references in the *.tex files!
// Manual references: lines 254-266 (ConfiguringActorSystems.tex)
#include <array> #include <array>
#include <vector> #include <vector>
...@@ -249,8 +247,6 @@ void client_repl(actor_system& system, string host, uint16_t port) { ...@@ -249,8 +247,6 @@ void client_repl(actor_system& system, string host, uint16_t port) {
} }
} }
} // namespace <anonymous>
class config : public actor_system_config { class config : public actor_system_config {
public: public:
uint16_t port = 0; uint16_t port = 0;
...@@ -286,4 +282,6 @@ void caf_main(actor_system& system, const config& cfg) { ...@@ -286,4 +282,6 @@ void caf_main(actor_system& system, const config& cfg) {
client_repl(system, cfg.host, cfg.port); client_repl(system, cfg.host, cfg.port);
} }
} // namespace <anonymous>
CAF_MAIN(io::middleman) CAF_MAIN(io::middleman)
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
using namespace std; using namespace std;
using namespace caf; using namespace caf;
namespace {
using broadcast_atom = atom_constant<atom("broadcast")>; using broadcast_atom = atom_constant<atom("broadcast")>;
struct line { string str; }; struct line { string str; };
...@@ -153,4 +155,6 @@ void caf_main(actor_system& system, const config& cfg) { ...@@ -153,4 +155,6 @@ void caf_main(actor_system& system, const config& cfg) {
anon_send_exit(client_actor, exit_reason::user_shutdown); anon_send_exit(client_actor, exit_reason::user_shutdown);
} }
} // namespace <anonymous>
CAF_MAIN(io::middleman) CAF_MAIN(io::middleman)
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
using namespace std; using namespace std;
using namespace caf; using namespace caf;
namespace {
class config : public actor_system_config { class config : public actor_system_config {
public: public:
uint16_t port = 0; uint16_t port = 0;
...@@ -39,4 +41,6 @@ void caf_main(actor_system& system, const config& cfg) { ...@@ -39,4 +41,6 @@ void caf_main(actor_system& system, const config& cfg) {
cerr << "illegal command" << endl; cerr << "illegal command" << endl;
} }
} // namespace <anonymous>
CAF_MAIN(io::middleman) CAF_MAIN(io::middleman)
...@@ -88,7 +88,10 @@ set (LIBCAF_CORE_SRCS ...@@ -88,7 +88,10 @@ set (LIBCAF_CORE_SRCS
src/try_match.cpp src/try_match.cpp
src/type_erased_value.cpp src/type_erased_value.cpp
src/type_erased_tuple.cpp src/type_erased_tuple.cpp
src/uniform_type_info_map.cpp) src/uniform_type_info_map.cpp
src/unprofiled.cpp
src/work_stealing.cpp
src/work_sharing.cpp)
add_custom_target(libcaf_core) add_custom_target(libcaf_core)
......
...@@ -117,14 +117,19 @@ public: ...@@ -117,14 +117,19 @@ public:
/// Returns the address of the stored actor. /// Returns the address of the stored actor.
actor_addr address() const noexcept; actor_addr address() const noexcept;
/// Returns the ID of this actor.
inline actor_id id() const noexcept {
return ptr_->id();
}
/// Returns the origin node of this actor. /// Returns the origin node of this actor.
inline node_id node() const noexcept { inline node_id node() const noexcept {
return ptr_->node(); return ptr_->node();
} }
/// Returns the ID of this actor. /// Returns the hosting actor system.
inline actor_id id() const noexcept { inline actor_system& home_system() const noexcept {
return ptr_->id(); return *ptr_->home_system;
} }
/// Exchange content of `*this` and `other`. /// Exchange content of `*this` and `other`.
......
...@@ -73,13 +73,19 @@ public: ...@@ -73,13 +73,19 @@ public:
actor_addr(const unsafe_actor_handle_init_t&); actor_addr(const unsafe_actor_handle_init_t&);
/// Returns the ID of this actor. /// Returns the ID of this actor.
actor_id id() const noexcept; inline actor_id id() const noexcept {
return ptr_->id();
}
/// Returns the origin node of this actor. /// Returns the origin node of this actor.
node_id node() const noexcept; inline node_id node() const noexcept {
return ptr_->node();
}
/// Returns the hosting actor system. /// Returns the hosting actor system.
actor_system* home_system() const noexcept; inline actor_system& home_system() const noexcept {
return *ptr_->home_system;
}
/// Exchange content of `*this` and `other`. /// Exchange content of `*this` and `other`.
void swap(actor_addr& other) noexcept; void swap(actor_addr& other) noexcept;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "caf/config_value.hpp" #include "caf/config_value.hpp"
#include "caf/config_option.hpp" #include "caf/config_option.hpp"
#include "caf/actor_factory.hpp" #include "caf/actor_factory.hpp"
#include "caf/is_typed_actor.hpp"
#include "caf/type_erased_value.hpp" #include "caf/type_erased_value.hpp"
#include "caf/detail/safe_equal.hpp" #include "caf/detail/safe_equal.hpp"
...@@ -116,6 +117,7 @@ public: ...@@ -116,6 +117,7 @@ public:
template <class T> template <class T>
actor_system_config& add_message_type(std::string name) { actor_system_config& add_message_type(std::string name) {
static_assert(std::is_empty<T>::value static_assert(std::is_empty<T>::value
|| is_typed_actor<T>::value
|| (std::is_default_constructible<T>::value || (std::is_default_constructible<T>::value
&& std::is_copy_constructible<T>::value), && std::is_copy_constructible<T>::value),
"T must provide default and copy constructors"); "T must provide default and copy constructors");
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
_Pragma("clang diagnostic ignored \"-Wdisabled-macro-expansion\"") \ _Pragma("clang diagnostic ignored \"-Wdisabled-macro-expansion\"") \
_Pragma("clang diagnostic ignored \"-Wunreachable-code\"") \ _Pragma("clang diagnostic ignored \"-Wunreachable-code\"") \
_Pragma("clang diagnostic ignored \"-Wreserved-id-macro\"") \ _Pragma("clang diagnostic ignored \"-Wreserved-id-macro\"") \
_Pragma("clang diagnostic ignored \"-Wdouble-promotion\"") \
_Pragma("clang diagnostic ignored \"-Wsign-conversion\"") _Pragma("clang diagnostic ignored \"-Wsign-conversion\"")
# define CAF_PUSH_NON_VIRTUAL_DTOR_WARNING \ # define CAF_PUSH_NON_VIRTUAL_DTOR_WARNING \
_Pragma("clang diagnostic push") \ _Pragma("clang diagnostic push") \
......
...@@ -151,11 +151,11 @@ public: ...@@ -151,11 +151,11 @@ public:
apply(T& x) { apply(T& x) {
using underlying = typename std::underlying_type<T>::type; using underlying = typename std::underlying_type<T>::type;
struct { struct {
void operator()(T& x, underlying& y) const { void operator()(T& lhs, underlying& rhs) const {
x = static_cast<T>(y); lhs = static_cast<T>(rhs);
} }
void operator()(underlying& x, T& y) const { void operator()(underlying& lhs, T& rhs) const {
x = static_cast<underlying>(y); lhs = static_cast<underlying>(rhs);
} }
} assign; } assign;
underlying tmp; underlying tmp;
...@@ -171,11 +171,11 @@ public: ...@@ -171,11 +171,11 @@ public:
void apply(bool& x) { void apply(bool& x) {
struct { struct {
void operator()(bool& x, uint8_t& y) const { void operator()(bool& lhs, uint8_t& rhs) const {
x = y != 0; lhs = rhs != 0;
} }
void operator()(uint8_t& x, bool& y) const { void operator()(uint8_t& lhs, bool& rhs) const {
x = y ? 1 : 0; lhs = rhs ? 1 : 0;
} }
} assign; } assign;
uint8_t tmp; uint8_t tmp;
...@@ -324,12 +324,12 @@ public: ...@@ -324,12 +324,12 @@ public:
// always save/store durations as int64_t to work around possibly // always save/store durations as int64_t to work around possibly
// different integer types on different plattforms for standard typedefs // different integer types on different plattforms for standard typedefs
struct { struct {
void operator()(duration_type& x, int64_t& y) const { void operator()(duration_type& lhs, int64_t& rhs) const {
duration_type tmp{y}; duration_type tmp{rhs};
x = tmp; lhs = tmp;
} }
void operator()(int64_t& x, duration_type& y) const { void operator()(int64_t& lhs, duration_type& rhs) const {
x = y.count(); lhs = rhs.count();
} }
} assign; } assign;
int64_t tmp; int64_t tmp;
...@@ -345,12 +345,12 @@ public: ...@@ -345,12 +345,12 @@ public:
// always save/store floating point durations // always save/store floating point durations
// as doubles for the same reason as above // as doubles for the same reason as above
struct { struct {
void operator()(duration_type& x, double& y) const { void operator()(duration_type& lhs, double& rhs) const {
duration_type tmp{y}; duration_type tmp{rhs};
x = tmp; lhs = tmp;
} }
void operator()(double& x, duration_type& y) const { void operator()(double& lhs, duration_type& rhs) const {
x = y.count(); lhs = rhs.count();
} }
} assign; } assign;
double tmp; double tmp;
......
...@@ -34,6 +34,8 @@ namespace caf { ...@@ -34,6 +34,8 @@ namespace caf {
/// Technology-independent deserialization interface. /// Technology-independent deserialization interface.
class deserializer : public data_processor<deserializer> { class deserializer : public data_processor<deserializer> {
public: public:
~deserializer();
using super = data_processor<deserializer>; using super = data_processor<deserializer>;
using is_saving = std::false_type; using is_saving = std::false_type;
......
...@@ -49,8 +49,8 @@ public: ...@@ -49,8 +49,8 @@ public:
} }
behavior make_behavior() override { behavior make_behavior() override {
auto f = [=](local_actor*, const type_erased_tuple* x) -> result<message> { auto f = [=](local_actor*, const type_erased_tuple* tup) -> result<message> {
auto msg = message::from(x); auto msg = message::from(tup);
auto rp = this->make_response_promise(); auto rp = this->make_response_promise();
split_(workset_, msg); split_(workset_, msg);
for (auto& x : workset_) for (auto& x : workset_)
......
...@@ -32,6 +32,9 @@ class execution_unit { ...@@ -32,6 +32,9 @@ class execution_unit {
public: public:
explicit execution_unit(actor_system* sys); explicit execution_unit(actor_system* sys);
execution_unit(execution_unit&&) = delete;
execution_unit(const execution_unit&) = delete;
virtual ~execution_unit(); virtual ~execution_unit();
/// Enqueues `ptr` to the job list of the execution unit. /// Enqueues `ptr` to the job list of the execution unit.
......
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
function_view(function_view&& x) : impl_(std::move(x.impl_)) { function_view(function_view&& x) : impl_(std::move(x.impl_)) {
if (! impl_.unsafe()) { if (! impl_.unsafe()) {
new (&self_) scoped_actor(std::move(x.self_)); new (&self_) scoped_actor(impl_.home_system()); //(std::move(x.self_));
x.self_.~scoped_actor(); x.self_.~scoped_actor();
} }
} }
......
...@@ -29,6 +29,14 @@ namespace caf { ...@@ -29,6 +29,14 @@ namespace caf {
template <class T> template <class T>
class input_range { class input_range {
public: public:
virtual ~input_range() {
// nop
}
input_range() = default;
input_range(const input_range&) = default;
input_range& operator=(const input_range&) = default;
class iterator : public std::iterator<std::input_iterator_tag, T> { class iterator : public std::iterator<std::input_iterator_tag, T> {
public: public:
iterator(input_range* range) : xs_(range) { iterator(input_range* range) : xs_(range) {
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_IS_TYPED_ACTOR_HPP
#define CAF_IS_TYPED_ACTOR_HPP
#include "caf/fwd.hpp"
namespace caf {
/**
* Evaluates to true if `T` is a `typed_actor<...>`.
*/
template <class T>
struct is_typed_actor : std::false_type { };
template <class... Ts>
struct is_typed_actor<typed_actor<Ts...>> : std::true_type { };
} // namespace caf
#endif //CAF_IS_TYPED_ACTOR_HPP
...@@ -44,7 +44,6 @@ public: ...@@ -44,7 +44,6 @@ public:
} }
/// Sends `{xs...}` as a synchronous message to `dest` with priority `mp`. /// Sends `{xs...}` as a synchronous message to `dest` with priority `mp`.
/// @returns A handle identifying a future-like handle to the response.
/// @warning The returned handle is actor specific and the response to the /// @warning The returned handle is actor specific and the response to the
/// sent message cannot be received by another actor. /// sent message cannot be received by another actor.
/// @throws std::invalid_argument if `dest == invalid_actor` /// @throws std::invalid_argument if `dest == invalid_actor`
...@@ -74,6 +73,21 @@ public: ...@@ -74,6 +73,21 @@ public:
this->context(), std::forward<Ts>(xs)...); this->context(), std::forward<Ts>(xs)...);
} }
template <message_priority P = message_priority::normal,
class Source = actor, class Dest = actor, class... Ts>
void anon_send(const Dest& dest, Ts&&... xs) {
static_assert(sizeof...(Ts) > 0, "no message to send");
using token =
detail::type_list<
typename detail::implicit_conversions<
typename std::decay<Ts>::type
>::type...>;
static_assert(actor_accepts_message(signatures_of<Dest>(), token{}),
"receiver does not accept given message");
dest->eq_impl(message_id::make(P), nullptr,
this->context(), std::forward<Ts>(xs)...);
}
template <message_priority P = message_priority::normal, template <message_priority P = message_priority::normal,
class Dest = actor, class... Ts> class Dest = actor, class... Ts>
void delayed_send(const Dest& dest, const duration& rtime, Ts&&... xs) { void delayed_send(const Dest& dest, const duration& rtime, Ts&&... xs) {
......
...@@ -32,21 +32,7 @@ namespace policy { ...@@ -32,21 +32,7 @@ namespace policy {
/// factor common utilities for implementing actual policies. /// factor common utilities for implementing actual policies.
class unprofiled { class unprofiled {
public: public:
virtual ~unprofiled() = default; virtual ~unprofiled();
/// Policy-specific data fields for the coordinator.
struct coordinator_data {
inline explicit coordinator_data(scheduler::abstract_coordinator*) {
// nop
}
};
/// Policy-specific data fields for the worker.
struct worker_data {
inline explicit worker_data(scheduler::abstract_coordinator*) {
// nop
}
};
/// Performs cleanup action before a shutdown takes place. /// Performs cleanup action before a shutdown takes place.
template <class Worker> template <class Worker>
......
...@@ -31,12 +31,15 @@ ...@@ -31,12 +31,15 @@
namespace caf { namespace caf {
namespace policy { namespace policy {
/// Implements scheduling of actors via work sharing (central job queue).
/// @extends scheduler_policy /// @extends scheduler_policy
class work_sharing : public unprofiled { class work_sharing : public unprofiled {
public: public:
// A thread-safe queue implementation. // A thread-safe queue implementation.
using queue_type = std::list<resumable*>; using queue_type = std::list<resumable*>;
~work_sharing();
struct coordinator_data { struct coordinator_data {
inline explicit coordinator_data(scheduler::abstract_coordinator*) { inline explicit coordinator_data(scheduler::abstract_coordinator*) {
// nop // nop
...@@ -47,6 +50,12 @@ public: ...@@ -47,6 +50,12 @@ public:
std::condition_variable cv; std::condition_variable cv;
}; };
struct worker_data {
inline explicit worker_data(scheduler::abstract_coordinator*) {
// nop
}
};
template <class Coordinator> template <class Coordinator>
void enqueue(Coordinator* self, resumable* job) { void enqueue(Coordinator* self, resumable* job) {
queue_type l; queue_type l;
......
...@@ -34,24 +34,12 @@ ...@@ -34,24 +34,12 @@
namespace caf { namespace caf {
namespace policy { namespace policy {
/// Implements scheduling of actors via work stealing. This implementation uses /// Implements scheduling of actors via work stealing.
/// two queues: a synchronized queue accessible by other threads and an internal
/// queue. Access to the synchronized queue is minimized.
/// The reasoning behind this design decision is that it
/// has been shown that stealing actually is very rare for most workloads [1].
/// Hence, implementations should focus on the performance in
/// the non-stealing case. For this reason, each worker has an exposed
/// job queue that can be accessed by the central scheduler instance as
/// well as other workers, but it also has a private job list it is
/// currently working on. To account for the load balancing aspect, each
/// worker makes sure that at least one job is left in its exposed queue
/// to allow other workers to steal it.
///
/// [1] http://dl.acm.org/citation.cfm?doid=2398857.2384639
///
/// @extends scheduler_policy /// @extends scheduler_policy
class work_stealing : public unprofiled { class work_stealing : public unprofiled {
public: public:
~work_stealing();
// A thread-safe queue implementation. // A thread-safe queue implementation.
using queue_type = detail::double_ended_queue<resumable>; using queue_type = detail::double_ended_queue<resumable>;
......
...@@ -45,15 +45,20 @@ public: ...@@ -45,15 +45,20 @@ public:
// tell actor_cast this is a non-null handle type // tell actor_cast this is a non-null handle type
static constexpr bool has_non_null_guarantee = true; static constexpr bool has_non_null_guarantee = true;
scoped_actor(const scoped_actor&) = delete;
scoped_actor(actor_system& sys, bool hide_actor = false); scoped_actor(actor_system& sys, bool hide_actor = false);
scoped_actor(const scoped_actor&) = delete;
scoped_actor& operator=(const scoped_actor&) = delete;
scoped_actor(scoped_actor&&) = default; scoped_actor(scoped_actor&&) = default;
scoped_actor& operator=(scoped_actor&&) = default; scoped_actor& operator=(scoped_actor&&) = default;
~scoped_actor(); ~scoped_actor();
inline actor_system& home_system() const {
return *self_->home_system;
}
inline blocking_actor* operator->() const { inline blocking_actor* operator->() const {
return ptr(); return ptr();
} }
......
...@@ -94,8 +94,10 @@ public: ...@@ -94,8 +94,10 @@ public:
} }
void apply_raw(size_t num_bytes, void* data) override { void apply_raw(size_t num_bytes, void* data) override {
auto n = streambuf_.sgetn(reinterpret_cast<char_type*>(data), num_bytes); auto n = streambuf_.sgetn(reinterpret_cast<char_type*>(data),
range_check(n, num_bytes); static_cast<std::streamsize>(num_bytes));
CAF_ASSERT(n >= 0);
range_check(static_cast<size_t>(n), num_bytes);
} }
protected: protected:
...@@ -112,7 +114,7 @@ protected: ...@@ -112,7 +114,7 @@ protected:
if (traits::eq_int_type(c, traits::eof())) if (traits::eq_int_type(c, traits::eof()))
throw std::out_of_range{"stream_deserializer<T>::begin_sequence"}; throw std::out_of_range{"stream_deserializer<T>::begin_sequence"};
low7 = static_cast<uint8_t>(traits::to_char_type(c)); low7 = static_cast<uint8_t>(traits::to_char_type(c));
x |= (low7 & 0x7F) << (7 * n); x |= static_cast<T>((low7 & 0x7F) << (7 * n));
++n; ++n;
} while (low7 & 0x80); } while (low7 & 0x80);
return n; return n;
...@@ -160,8 +162,9 @@ protected: ...@@ -160,8 +162,9 @@ protected:
// TODO: When using C++14, switch to str.data(), which then has a // TODO: When using C++14, switch to str.data(), which then has a
// non-const overload. // non-const overload.
auto data = reinterpret_cast<char_type*>(&str[0]); auto data = reinterpret_cast<char_type*>(&str[0]);
size_t n = streambuf_.sgetn(data, str_size); auto n = streambuf_.sgetn(data, static_cast<std::streamsize>(str_size));
range_check(n, str_size); CAF_ASSERT(n >= 0);
range_check(static_cast<size_t>(n), str_size);
end_sequence(); end_sequence();
break; break;
} }
...@@ -174,8 +177,9 @@ protected: ...@@ -174,8 +177,9 @@ protected:
// TODO: When using C++14, switch to str.data(), which then has a // TODO: When using C++14, switch to str.data(), which then has a
// non-const overload. // non-const overload.
auto data = reinterpret_cast<char_type*>(&str[0]); auto data = reinterpret_cast<char_type*>(&str[0]);
size_t n = streambuf_.sgetn(data, bytes); auto n = streambuf_.sgetn(data, static_cast<std::streamsize>(bytes));
range_check(n, bytes); CAF_ASSERT(n >= 0);
range_check(static_cast<size_t>(n), str_size);
end_sequence(); end_sequence();
break; break;
} }
...@@ -188,8 +192,9 @@ protected: ...@@ -188,8 +192,9 @@ protected:
// TODO: When using C++14, switch to str.data(), which then has a // TODO: When using C++14, switch to str.data(), which then has a
// non-const overload. // non-const overload.
auto data = reinterpret_cast<char_type*>(&str[0]); auto data = reinterpret_cast<char_type*>(&str[0]);
size_t n = streambuf_.sgetn(data, bytes); auto n = streambuf_.sgetn(data, static_cast<std::streamsize>(bytes));
range_check(n, bytes); CAF_ASSERT(n >= 0);
range_check(static_cast<size_t>(n), str_size);
end_sequence(); end_sequence();
break; break;
} }
......
...@@ -92,7 +92,8 @@ public: ...@@ -92,7 +92,8 @@ public:
} }
void apply_raw(size_t num_bytes, void* data) override { void apply_raw(size_t num_bytes, void* data) override {
streambuf_.sputn(reinterpret_cast<char_type*>(data), num_bytes); streambuf_.sputn(reinterpret_cast<char_type*>(data),
static_cast<std::streamsize>(num_bytes));
} }
protected: protected:
...@@ -109,7 +110,10 @@ protected: ...@@ -109,7 +110,10 @@ protected:
x >>= 7; x >>= 7;
} }
*i++ = static_cast<uint8_t>(x) & 0x7f; *i++ = static_cast<uint8_t>(x) & 0x7f;
return streambuf_.sputn(reinterpret_cast<char_type*>(buf), i - buf); auto res = streambuf_.sputn(reinterpret_cast<char_type*>(buf),
static_cast<std::streamsize>(i - buf));
CAF_ASSERT(res >= 0);
return static_cast<size_t>(res);
} }
void apply_builtin(builtin type, void* val) override { void apply_builtin(builtin type, void* val) override {
......
...@@ -99,16 +99,18 @@ protected: ...@@ -99,16 +99,18 @@ protected:
std::streamsize xsputn(const char_type* s, std::streamsize n) override { std::streamsize xsputn(const char_type* s, std::streamsize n) override {
auto available = this->epptr() - this->pptr(); auto available = this->epptr() - this->pptr();
auto actual = std::min(n, available); auto actual = std::min(n, available);
std::memcpy(this->pptr(), s, actual * sizeof(char_type)); std::memcpy(this->pptr(), s,
this->pbump(actual); static_cast<size_t>(actual) * sizeof(char_type));
this->pbump(static_cast<int>(actual));
return actual; return actual;
} }
std::streamsize xsgetn(char_type* s, std::streamsize n) override { std::streamsize xsgetn(char_type* s, std::streamsize n) override {
auto available = this->egptr() - this->gptr(); auto available = this->egptr() - this->gptr();
auto actual = std::min(n, available); auto actual = std::min(n, available);
std::memcpy(s, this->gptr(), actual * sizeof(char_type)); std::memcpy(s, this->gptr(),
this->gbump(actual); static_cast<size_t>(actual) * sizeof(char_type));
this->gbump(static_cast<int>(actual));
return actual; return actual;
} }
}; };
...@@ -180,8 +182,9 @@ protected: ...@@ -180,8 +182,9 @@ protected:
std::streamsize xsgetn(char_type* s, std::streamsize n) override { std::streamsize xsgetn(char_type* s, std::streamsize n) override {
auto available = this->egptr() - this->gptr(); auto available = this->egptr() - this->gptr();
auto actual = std::min(n, available); auto actual = std::min(n, available);
std::memcpy(s, this->gptr(), actual * sizeof(char_type)); std::memcpy(s, this->gptr(),
this->gbump(actual); static_cast<size_t>(actual) * sizeof(char_type));
this->gbump(static_cast<int>(actual));
return actual; return actual;
} }
......
...@@ -40,6 +40,9 @@ public: ...@@ -40,6 +40,9 @@ public:
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
type_erased_tuple() = default;
type_erased_tuple(const type_erased_tuple&) = default;
virtual ~type_erased_tuple(); virtual ~type_erased_tuple();
// -- pure virtual modifiers ------------------------------------------------- // -- pure virtual modifiers -------------------------------------------------
...@@ -141,7 +144,9 @@ public: ...@@ -141,7 +144,9 @@ public:
init(); init();
} }
type_erased_tuple_view(const type_erased_tuple_view& other) : xs_(other.xs_) { type_erased_tuple_view(const type_erased_tuple_view& other)
: type_erased_tuple(),
xs_(other.xs_) {
init(); init();
} }
......
...@@ -62,10 +62,15 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -62,10 +62,15 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
public: public:
static_assert(sizeof...(Sigs) > 0, "Empty typed actor handle"); static_assert(sizeof...(Sigs) > 0, "Empty typed actor handle");
// grant access to private ctor // -- friend types that need access to private ctors
friend class local_actor; friend class local_actor;
// friend with all possible instantiations template <class>
friend class data_processor;
template <class>
friend class type_erased_value_impl;
template <class...> template <class...>
friend class typed_actor; friend class typed_actor;
...@@ -126,8 +131,6 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -126,8 +131,6 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
using stateful_broker_pointer = using stateful_broker_pointer =
stateful_actor<State, broker_base>*; stateful_actor<State, broker_base>*;
typed_actor() = delete;
typed_actor(typed_actor&&) = default; typed_actor(typed_actor&&) = default;
typed_actor(const typed_actor&) = default; typed_actor(const typed_actor&) = default;
typed_actor& operator=(typed_actor&&) = default; typed_actor& operator=(typed_actor&&) = default;
...@@ -184,14 +187,19 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -184,14 +187,19 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
return {ptr_.get(), true}; return {ptr_.get(), true};
} }
/// Returns the ID of this actor.
actor_id id() const noexcept {
return ptr_->id();
}
/// Returns the origin node of this actor. /// Returns the origin node of this actor.
node_id node() const noexcept { node_id node() const noexcept {
return ptr_->node(); return ptr_->node();
} }
/// Returns the ID of this actor. /// Returns the hosting actor system.
actor_id id() const noexcept { inline actor_system& home_system() const noexcept {
return ptr_->id(); return *ptr_->home_system;
} }
/// Exchange content of `*this` and `other`. /// Exchange content of `*this` and `other`.
...@@ -262,6 +270,8 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>, ...@@ -262,6 +270,8 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
/// @endcond /// @endcond
private: private:
typed_actor() = default;
actor_control_block* get() const noexcept { actor_control_block* get() const noexcept {
return ptr_.get(); return ptr_.get();
} }
......
...@@ -71,18 +71,6 @@ intptr_t actor_addr::compare(const actor_control_block* other) const noexcept { ...@@ -71,18 +71,6 @@ intptr_t actor_addr::compare(const actor_control_block* other) const noexcept {
return compare(ptr_.get(), other); return compare(ptr_.get(), other);
} }
actor_id actor_addr::id() const noexcept {
return (ptr_) ? ptr_->id() : 0;
}
node_id actor_addr::node() const noexcept {
return ptr_ ? ptr_->node() : node_id{};
}
actor_system* actor_addr::home_system() const noexcept {
return ptr_ ? ptr_->home_system : nullptr;
}
void actor_addr::swap(actor_addr& other) noexcept { void actor_addr::swap(actor_addr& other) noexcept {
ptr_.swap(other.ptr_); ptr_.swap(other.ptr_);
} }
......
...@@ -48,10 +48,7 @@ public: ...@@ -48,10 +48,7 @@ public:
key += '.'; key += '.';
// name can have format "<long>,<short>"; consider only long name // name can have format "<long>,<short>"; consider only long name
auto name_begin = x->name(); auto name_begin = x->name();
auto name_end = name_begin; const char* name_end = strchr(x->name(), ',');
for (auto c = *name_end; c != ',' && c != 0; ++name_end) {
// nop
}
key.insert(key.end(), name_begin, name_end); key.insert(key.end(), name_begin, name_end);
//key += x->name(); //key += x->name();
sinks_.emplace(std::move(key), x->to_sink()); sinks_.emplace(std::move(key), x->to_sink());
......
...@@ -69,14 +69,14 @@ const char* config_option::type_name_visitor::operator()(atom_value) const { ...@@ -69,14 +69,14 @@ const char* config_option::type_name_visitor::operator()(atom_value) const {
bool config_option::assign_config_value(size_t& x, int64_t& y) { bool config_option::assign_config_value(size_t& x, int64_t& y) {
if (y < 0 || ! unsigned_assign_in_range(x, y)) if (y < 0 || ! unsigned_assign_in_range(x, y))
return false; return false;
x = std::move(y); x = static_cast<size_t>(y);
return true; return true;
} }
bool config_option::assign_config_value(uint16_t& x, int64_t& y) { bool config_option::assign_config_value(uint16_t& x, int64_t& y) {
if (y < 0 || y > std::numeric_limits<uint16_t>::max()) if (y < 0 || y > std::numeric_limits<uint16_t>::max())
return false; return false;
x = std::move(y); x = static_cast<uint16_t>(y);
return true; return true;
} }
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
namespace caf { namespace caf {
deserializer::~deserializer() {
// nop
}
deserializer::deserializer(actor_system& x) : super(x.dummy_execution_unit()) { deserializer::deserializer(actor_system& x) : super(x.dummy_execution_unit()) {
// nop // nop
} }
......
...@@ -361,6 +361,8 @@ local_actor::msg_type local_actor::filter_msg(mailbox_element& node) { ...@@ -361,6 +361,8 @@ local_actor::msg_type local_actor::filter_msg(mailbox_element& node) {
} }
} }
namespace {
class invoke_result_visitor_helper { class invoke_result_visitor_helper {
public: public:
invoke_result_visitor_helper(response_promise x) : rp(x) { invoke_result_visitor_helper(response_promise x) : rp(x) {
...@@ -429,6 +431,8 @@ private: ...@@ -429,6 +431,8 @@ private:
local_actor* self_; local_actor* self_;
}; };
} // namespace <anonymous>
void local_actor::handle_response(mailbox_element_ptr& ptr, void local_actor::handle_response(mailbox_element_ptr& ptr,
local_actor::pending_response& pr) { local_actor::pending_response& pr) {
CAF_ASSERT(ptr != nullptr); CAF_ASSERT(ptr != nullptr);
......
...@@ -246,7 +246,7 @@ void node_id::from_string(const std::string& str) { ...@@ -246,7 +246,7 @@ void node_id::from_string(const std::string& str) {
// nop // nop
} }
uint8_t operator*() const { uint8_t operator*() const {
return (hex_nibble(*i) << 4) | hex_nibble(*(i + 1)); return static_cast<uint8_t>(hex_nibble(*i) << 4) | hex_nibble(*(i + 1));
} }
hex_byte_iter& operator++() { hex_byte_iter& operator++() {
i += 2; i += 2;
......
...@@ -29,13 +29,13 @@ namespace detail { ...@@ -29,13 +29,13 @@ namespace detail {
void parse_ini_t::operator()(std::istream& input, config_consumer consumer_fun, void parse_ini_t::operator()(std::istream& input, config_consumer consumer_fun,
optional<std::ostream&> errors) const { optional<std::ostream&> errors) const {
std::string group;
std::string line;
size_t ln = 0; // line number
// wraps a temporary into an (lvalue) config_value and calls `consumer_fun` // wraps a temporary into an (lvalue) config_value and calls `consumer_fun`
auto consumer = [&](size_t ln, std::string name, value x) { auto consumer = [&](size_t ln, std::string name, value x) {
consumer_fun(ln, std::move(name), x); consumer_fun(ln, std::move(name), x);
}; };
std::string group;
std::string line;
size_t ln = 0; // line number
auto print = [&](const char* category, const char* str) { auto print = [&](const char* category, const char* str) {
if (errors) if (errors)
*errors << category << " INI file line " *errors << category << " INI file line "
......
...@@ -44,14 +44,14 @@ public: ...@@ -44,14 +44,14 @@ public:
} // namespace <anonymous> } // namespace <anonymous>
scoped_actor::scoped_actor(actor_system& sys, bool hidden) : context_{&sys} { scoped_actor::scoped_actor(actor_system& sys, bool hide) : context_(&sys) {
actor_config cfg{&context_}; actor_config cfg{&context_};
self_ = make_actor<impl, strong_actor_ptr>(sys.next_actor_id(), sys.node(), self_ = make_actor<impl, strong_actor_ptr>(sys.next_actor_id(), sys.node(),
&sys, cfg); &sys, cfg);
if (! hidden) if (! hide)
prev_ = CAF_SET_AID(self_->id()); prev_ = CAF_SET_AID(self_->id());
CAF_LOG_TRACE(CAF_ARG(hidden)); CAF_LOG_TRACE(CAF_ARG(hide));
ptr()->is_registered(! hidden); ptr()->is_registered(! hide);
} }
scoped_actor::~scoped_actor() { scoped_actor::~scoped_actor() {
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/policy/unprofiled.hpp"
namespace caf {
namespace policy {
unprofiled::~unprofiled() {
// nop
}
} // namespace policy
} // namespace caf
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/policy/work_sharing.hpp"
namespace caf {
namespace policy {
work_sharing::~work_sharing() {
// nop
}
} // namespace policy
} // namespace caf
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/policy/work_stealing.hpp"
namespace caf {
namespace policy {
work_stealing::~work_stealing() {
// nop
}
} // namespace policy
} // namespace caf
...@@ -31,24 +31,6 @@ using namespace caf; ...@@ -31,24 +31,6 @@ using namespace caf;
using std::string; using std::string;
namespace {
bool msg_equals_rec(const message&, size_t) {
return true;
}
template <class T, class... Ts>
bool msg_equals_rec(const message& msg, size_t pos, const T& x, const Ts&... xs) {
return msg.get_as<T>(pos) == x && msg_equals_rec(msg, pos + 1, xs...);
}
template <class... Ts>
bool msg_equals(const message& msg, const Ts&... xs) {
return msg.match_elements<Ts...>() && msg_equals_rec(msg, 0, xs...);
}
} // namespace <anonymous>
CAF_TEST(type_sequences) { CAF_TEST(type_sequences) {
auto _64 = uint64_t{64}; auto _64 = uint64_t{64};
std::string str = "str"; std::string str = "str";
...@@ -56,9 +38,12 @@ CAF_TEST(type_sequences) { ...@@ -56,9 +38,12 @@ CAF_TEST(type_sequences) {
auto df = [](double, float) { }; auto df = [](double, float) { };
auto fs = [](float, const string&) { }; auto fs = [](float, const string&) { };
auto iu = [](int, uint64_t) { }; auto iu = [](int, uint64_t) { };
CAF_CHECK(msg_equals(msg.extract(df), str, 42, _64)); CAF_CHECK_EQUAL(to_string(msg.extract(df)),
CAF_CHECK(msg_equals(msg.extract(fs), 1.0, 42, _64)); to_string(make_message(str, 42, _64)));
CAF_CHECK(msg_equals(msg.extract(iu), 1.0, 2.f, str)); CAF_CHECK_EQUAL(to_string(msg.extract(fs)),
to_string(make_message(1.0, 42, _64)));
CAF_CHECK_EQUAL(to_string(msg.extract(iu)),
to_string(make_message(1.0, 2.f, str)));
} }
CAF_TEST(cli_args) { CAF_TEST(cli_args) {
......
...@@ -183,11 +183,11 @@ public: ...@@ -183,11 +183,11 @@ public:
behavior make_behavior() override { behavior make_behavior() override {
return { return {
[=](gogo_atom x) -> response_promise { [=](gogo_atom gogo) -> response_promise {
auto rp = make_response_promise(); auto rp = make_response_promise();
request(buddy(), infinite, x).then( request(buddy(), infinite, gogo).then(
[=](ok_atom x) mutable { [=](ok_atom ok) mutable {
rp.deliver(x); rp.deliver(ok);
quit(); quit();
} }
); );
...@@ -429,10 +429,10 @@ CAF_TEST(request_no_then) { ...@@ -429,10 +429,10 @@ CAF_TEST(request_no_then) {
CAF_TEST(async_request) { CAF_TEST(async_request) {
auto foo = system.spawn([](event_based_actor* self) -> behavior { auto foo = system.spawn([](event_based_actor* self) -> behavior {
auto receiver = self->spawn<linked>([](event_based_actor* self) -> behavior{ auto receiver = self->spawn<linked>([](event_based_actor* ptr) -> behavior {
return { return {
[=](int) { [=](int) {
return self->make_response_promise(); return ptr->make_response_promise();
} }
}; };
}); });
......
...@@ -110,22 +110,22 @@ CAF_TEST(untyped_splicing) { ...@@ -110,22 +110,22 @@ CAF_TEST(untyped_splicing) {
CAF_TEST(typed_splicing) { CAF_TEST(typed_splicing) {
using namespace std::placeholders; using namespace std::placeholders;
auto x = system.spawn(typed_first_stage); auto stage0 = system.spawn(typed_first_stage);
auto y = system.spawn(typed_second_stage); auto stage1 = system.spawn(typed_second_stage);
auto x_and_y = splice(x, y.bind(23.0, _1)); auto stages = splice(stage0, stage1.bind(23.0, _1));
using expected_type = typed_actor<replies_to<double> using expected_type = typed_actor<replies_to<double>
::with<double, double, double>>; ::with<double, double, double>>;
static_assert(std::is_same<decltype(x_and_y), expected_type>::value, static_assert(std::is_same<decltype(stages), expected_type>::value,
"splice() did not compute the correct result"); "splice() did not compute the correct result");
self->request(x_and_y, infinite, 42.0).receive( self->request(stages, infinite, 42.0).receive(
[](double x, double y, double z) { [](double x, double y, double z) {
CAF_CHECK_EQUAL(x, (42.0 * 2.0)); CAF_CHECK_EQUAL(x, (42.0 * 2.0));
CAF_CHECK_EQUAL(y, (42.0 * 4.0)); CAF_CHECK_EQUAL(y, (42.0 * 4.0));
CAF_CHECK_EQUAL(z, (23.0 * 42.0)); CAF_CHECK_EQUAL(z, (23.0 * 42.0));
} }
); );
// x and y go out of scope, leaving only the references // stage0 and stage1 go out of scope, leaving only the references
// in x_and_y, which will also go out of scope // in stages, which will also go out of scope
} }
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
...@@ -34,21 +34,21 @@ CAF_TEST(signed_arraybuf) { ...@@ -34,21 +34,21 @@ CAF_TEST(signed_arraybuf) {
CAF_CHECK_EQUAL(ab.sgetc(), 'T'); CAF_CHECK_EQUAL(ab.sgetc(), 'T');
std::string buf; std::string buf;
buf.resize(3); buf.resize(3);
size_t got = ab.sgetn(&buf[0], 3); auto got = ab.sgetn(&buf[0], 3);
CAF_CHECK_EQUAL(got, 3u); CAF_CHECK_EQUAL(got, 3);
CAF_CHECK_EQUAL(buf, "The"); CAF_CHECK_EQUAL(buf, "The");
CAF_CHECK_EQUAL(ab.sgetc(), ' '); CAF_CHECK_EQUAL(ab.sgetc(), ' ');
// Exhaust the stream. // Exhaust the stream.
buf.resize(data.size()); buf.resize(data.size());
got = ab.sgetn(&buf[0] + 3, data.size() - 3); got = ab.sgetn(&buf[0] + 3, static_cast<std::streamsize>(data.size() - 3));
CAF_CHECK_EQUAL(got, data.size() - 3); CAF_CHECK_EQUAL(static_cast<size_t>(got), data.size() - 3);
CAF_CHECK_EQUAL(data, buf); CAF_CHECK_EQUAL(data, buf);
CAF_CHECK_EQUAL(ab.in_avail(), 0); CAF_CHECK_EQUAL(ab.in_avail(), 0);
// No more. // No more.
auto c = ab.sgetc(); auto c = ab.sgetc();
CAF_CHECK_EQUAL(c, charbuf::traits_type::eof()); CAF_CHECK_EQUAL(c, charbuf::traits_type::eof());
// Reset the stream and write into it. // Reset the stream and write into it.
ab.setbuf(&data[0], data.size()); ab.setbuf(&data[0], static_cast<std::streamsize>(data.size()));
CAF_CHECK_EQUAL(static_cast<size_t>(ab.in_avail()), data.size()); CAF_CHECK_EQUAL(static_cast<size_t>(ab.in_avail()), data.size());
auto put = ab.sputn("One", 3); auto put = ab.sputn("One", 3);
CAF_CHECK_EQUAL(put, 3); CAF_CHECK_EQUAL(put, 3);
...@@ -77,7 +77,7 @@ CAF_TEST(containerbuf) { ...@@ -77,7 +77,7 @@ CAF_TEST(containerbuf) {
// Write some data. // Write some data.
std::vector<char> buf; std::vector<char> buf;
vectorbuf vb{buf}; vectorbuf vb{buf};
auto put = vb.sputn(data.data(), data.size()); auto put = vb.sputn(data.data(), static_cast<std::streamsize>(data.size()));
CAF_CHECK_EQUAL(static_cast<size_t>(put), data.size()); CAF_CHECK_EQUAL(static_cast<size_t>(put), data.size());
put = vb.sputn(";", 1); put = vb.sputn(";", 1);
CAF_CHECK_EQUAL(put, 1); CAF_CHECK_EQUAL(put, 1);
...@@ -103,8 +103,8 @@ CAF_TEST(containerbuf) { ...@@ -103,8 +103,8 @@ CAF_TEST(containerbuf) {
buf.clear(); buf.clear();
containerbuf<std::string> sib2{data}; containerbuf<std::string> sib2{data};
buf.resize(data.size()); buf.resize(data.size());
size_t got = sib2.sgetn(&buf[0], buf.size()); auto got = sib2.sgetn(&buf[0], static_cast<std::streamsize>(buf.size()));
CAF_CHECK_EQUAL(got, data.size()); CAF_CHECK_EQUAL(static_cast<size_t>(got), data.size());
CAF_CHECK_EQUAL(buf.size(), data.size()); CAF_CHECK_EQUAL(buf.size(), data.size());
CAF_CHECK(std::equal(buf.begin(), buf.end(), data.begin() /*, data.end() */)); CAF_CHECK(std::equal(buf.begin(), buf.end(), data.begin() /*, data.end() */));
} }
...@@ -146,13 +146,14 @@ public: ...@@ -146,13 +146,14 @@ public:
/// Adds a new hook to the middleman. /// Adds a new hook to the middleman.
template<class C, typename... Ts> template<class C, typename... Ts>
void add_hook(Ts&&... xs) { C* add_hook(Ts&&... xs) {
// if only we could move a unique_ptr into a lambda in C++11 // if only we could move a unique_ptr into a lambda in C++11
auto ptr = new C(system_, std::forward<Ts>(xs)...); auto ptr = new C(system_, std::forward<Ts>(xs)...);
backend().dispatch([=] { backend().dispatch([=] {
ptr->next.swap(hooks_); ptr->next.swap(hooks_);
hooks_.reset(ptr); hooks_.reset(ptr);
}); });
return ptr;
} }
/// Returns whether this middleman has any hooks installed. /// Returns whether this middleman has any hooks installed.
......
...@@ -600,6 +600,7 @@ behavior basp_broker::make_behavior() { ...@@ -600,6 +600,7 @@ behavior basp_broker::make_behavior() {
} }
catch (std::exception& e) { catch (std::exception& e) {
CAF_LOG_DEBUG("failed to assign scribe from handle: " << e.what()); CAF_LOG_DEBUG("failed to assign scribe from handle: " << e.what());
CAF_IGNORE_UNUSED(e);
rp.deliver(sec::failed_to_assign_scribe_from_handle); rp.deliver(sec::failed_to_assign_scribe_from_handle);
return; return;
} }
......
...@@ -132,16 +132,16 @@ public: ...@@ -132,16 +132,16 @@ public:
cached_.emplace(key, std::make_tuple(nid, addr, sigs)); cached_.emplace(key, std::make_tuple(nid, addr, sigs));
auto res = make_message(ok_atom::value, std::move(nid), auto res = make_message(ok_atom::value, std::move(nid),
std::move(addr), std::move(sigs)); std::move(addr), std::move(sigs));
for (auto& x : i->second) for (auto& promise : i->second)
x.deliver(res); promise.deliver(res);
pending_.erase(i); pending_.erase(i);
}, },
[=](error& err) { [=](error& err) {
auto i = pending_.find(key); auto i = pending_.find(key);
if (i == pending_.end()) if (i == pending_.end())
return; return;
for (auto& x : i->second) for (auto& promise : i->second)
x.deliver(err); promise.deliver(err);
pending_.erase(i); pending_.erase(i);
} }
); );
......
...@@ -469,7 +469,7 @@ CAF_TEST(non_empty_server_handshake) { ...@@ -469,7 +469,7 @@ CAF_TEST(non_empty_server_handshake) {
buffer buf; buffer buf;
instance().add_published_actor(4242, actor_cast<strong_actor_ptr>(self()), instance().add_published_actor(4242, actor_cast<strong_actor_ptr>(self()),
{"caf::replies_to<@u16>::with<@u16>"}); {"caf::replies_to<@u16>::with<@u16>"});
instance().write_server_handshake(mpx(), buf, 4242); instance().write_server_handshake(mpx(), buf, uint16_t{4242});
buffer expected_buf; buffer expected_buf;
basp::header expected{basp::message_type::server_handshake, 0, basp::version, basp::header expected{basp::message_type::server_handshake, 0, basp::version,
this_node(), invalid_node_id, this_node(), invalid_node_id,
......
...@@ -86,9 +86,8 @@ caf::behavior make_ping_behavior(caf::event_based_actor* self, ...@@ -86,9 +86,8 @@ caf::behavior make_ping_behavior(caf::event_based_actor* self,
std::string to_string(const std::vector<int>& vec) { std::string to_string(const std::vector<int>& vec) {
std::ostringstream os; std::ostringstream os;
for (auto i = 0; i + 1 < static_cast<int>(vec.size()); ++i) { for (size_t i = 0; i + 1 < vec.size(); ++i)
os << vec[i] << ", "; os << vec[i] << ", ";
}
os << vec.back(); os << vec.back();
return os.str(); return os.str();
} }
...@@ -106,14 +105,12 @@ caf::behavior make_sort_behavior() { ...@@ -106,14 +105,12 @@ caf::behavior make_sort_behavior() {
caf::behavior make_sort_requester_behavior(caf::event_based_actor* self, caf::behavior make_sort_requester_behavior(caf::event_based_actor* self,
caf::actor sorter) { caf::actor sorter) {
std::vector<int> vec = {5, 4, 3, 2, 1}; self->send(sorter, std::vector<int>{5, 4, 3, 2, 1});
self->send(sorter, std::move(vec));
return { return {
[=](const std::vector<int>& vec) { [=](const std::vector<int>& vec) {
CAF_MESSAGE("sort requester received: " << to_string(vec)); CAF_MESSAGE("sort requester received: " << to_string(vec));
for (int i = 1; i <= 5; ++i) { for (size_t i = 1; i < vec.size(); ++i)
CAF_CHECK_EQUAL(i, vec[i - 1]); CAF_CHECK_EQUAL(static_cast<int>(i), vec[i - 1]);
}
self->send_exit(sorter, caf::exit_reason::user_shutdown); self->send_exit(sorter, caf::exit_reason::user_shutdown);
self->quit(); self->quit();
} }
......
...@@ -214,12 +214,12 @@ void bootstrap(actor_system& system, ...@@ -214,12 +214,12 @@ void bootstrap(actor_system& system,
std::string slaveslist; std::string slaveslist;
for (size_t i = 0; i < slaves.size(); ++i) { for (size_t i = 0; i < slaves.size(); ++i) {
self->receive( self->receive(
[&](ok_atom, const string& host, uint16_t port) { [&](ok_atom, const string& host, uint16_t slave_port) {
if (! slaveslist.empty()) if (! slaveslist.empty())
slaveslist += ','; slaveslist += ',';
slaveslist += host; slaveslist += host;
slaveslist += '/'; slaveslist += '/';
slaveslist += std::to_string(port); slaveslist += std::to_string(slave_port);
}, },
[](const string& node) { [](const string& node) {
cerr << "unable to launch process via SSH at node " << node << endl; cerr << "unable to launch process via SSH at node " << node << endl;
......
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