Unverified Commit 25dc1ce3 authored by Joseph Noir's avatar Joseph Noir Committed by GitHub

Merge pull request #994

Remove legacy duration type (replaced by timespan)
parents 07931b0b d9532e20
......@@ -90,7 +90,6 @@ set(CAF_CORE_SOURCES
src/detail/uri_impl.cpp
src/downstream_manager.cpp
src/downstream_manager_base.cpp
src/duration.cpp
src/error.cpp
src/event_based_actor.cpp
src/execution_unit.cpp
......
......@@ -18,17 +18,19 @@
#pragma once
#include <chrono>
#include <tuple>
#include <type_traits>
#include "caf/detail/core_export.hpp"
#include "caf/timeout_definition.hpp"
#include "caf/timespan.hpp"
namespace caf {
class CAF_CORE_EXPORT timeout_definition_builder {
public:
constexpr timeout_definition_builder(duration d) : tout_(d) {
explicit constexpr timeout_definition_builder(timespan d) : tout_(d) {
// nop
}
......@@ -38,19 +40,14 @@ public:
}
private:
duration tout_;
timespan tout_;
};
/// Returns a generator for timeouts.
constexpr timeout_definition_builder after(duration d) {
return {d};
}
/// Returns a generator for timeouts.
template <class Rep, class Period>
constexpr timeout_definition_builder
after(std::chrono::duration<Rep, Period> d) {
return after(duration{d});
constexpr auto after(std::chrono::duration<Rep, Period> d) {
using std::chrono::duration_cast;
return timeout_definition_builder{duration_cast<timespan>(d)};
}
} // namespace caf
......@@ -62,7 +62,6 @@
#include "caf/deserializer.hpp"
#include "caf/detail/config_value_adaptor_field_impl.hpp"
#include "caf/downstream_msg.hpp"
#include "caf/duration.hpp"
#include "caf/error.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/exec_main.hpp"
......
......@@ -25,9 +25,9 @@
#include "caf/detail/core_export.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/duration.hpp"
#include "caf/none.hpp"
#include "caf/timeout_definition.hpp"
#include "caf/timespan.hpp"
namespace caf {
......@@ -87,9 +87,9 @@ public:
impl_->handle_timeout();
}
/// Returns the duration after which receive operations
/// Returns the timespan after which receive operations
/// using this behavior should time out.
inline const duration& timeout() const {
timespan timeout() const noexcept {
return impl_->timeout();
}
......
......@@ -28,7 +28,6 @@
#include "caf/detail/invoke_result_visitor.hpp"
#include "caf/detail/tail_argument_token.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/duration.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/make_counted.hpp"
#include "caf/match_case.hpp"
......@@ -39,6 +38,7 @@
#include "caf/response_promise.hpp"
#include "caf/skip.hpp"
#include "caf/timeout_definition.hpp"
#include "caf/timespan.hpp"
#include "caf/typed_response_promise.hpp"
#include "caf/variant.hpp"
......@@ -56,7 +56,9 @@ public:
~behavior_impl() override;
behavior_impl(duration tout = duration{});
behavior_impl();
explicit behavior_impl(timespan tout);
virtual match_case::result invoke_empty(detail::invoke_result_visitor& f);
......@@ -71,14 +73,14 @@ public:
virtual void handle_timeout();
inline const duration& timeout() const {
timespan timeout() const noexcept {
return timeout_;
}
pointer or_else(const pointer& other);
protected:
duration timeout_;
timespan timeout_;
match_case_info* begin_;
match_case_info* end_;
};
......
......@@ -22,6 +22,7 @@
#include "caf/catch_all.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/timeout_definition.hpp"
#include "caf/timespan.hpp"
namespace caf::detail {
......@@ -36,7 +37,7 @@ public:
virtual result<message> fallback(message_view&);
virtual duration timeout();
virtual timespan timeout();
virtual void handle_timeout();
};
......@@ -70,7 +71,7 @@ public:
blocking_behavior_v3(blocking_behavior_v3&&) = default;
duration timeout() override {
timespan timeout() override {
return f.timeout;
}
......@@ -96,7 +97,7 @@ public:
return f1.handler(x);
}
duration timeout() override {
timespan timeout() override {
return f2.timeout;
}
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* 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. *
******************************************************************************/
#pragma once
#include <chrono>
#include <cstdint>
#include <stdexcept>
#include <string>
#include "caf/detail/core_export.hpp"
#include "caf/error.hpp"
namespace caf {
/// SI time units to specify timeouts.
/// @relates duration
enum class time_unit : uint32_t {
invalid,
minutes,
seconds,
milliseconds,
microseconds,
nanoseconds
};
/// Relates time_unit
CAF_CORE_EXPORT std::string to_string(time_unit x);
// Calculates the index of a time_unit from the denominator of a ratio.
constexpr intmax_t denom_to_unit_index(intmax_t x, intmax_t offset = 2) {
return x < 1000 ? (x == 1 ? offset : 0)
: denom_to_unit_index(x / 1000, offset + 1);
}
constexpr time_unit denom_to_time_unit(intmax_t x) {
return static_cast<time_unit>(denom_to_unit_index(x));
}
/// Converts the ratio Num/Denom to a `time_unit` if the ratio describes
/// seconds, milliseconds, microseconds, or minutes. Minutes are mapped
/// to `time_unit::seconds`, any unrecognized ratio to `time_unit::invalid`.
/// @relates duration
template <intmax_t Num, intmax_t Denom>
struct ratio_to_time_unit_helper;
template <intmax_t Denom>
struct ratio_to_time_unit_helper<1, Denom> {
static constexpr time_unit value = denom_to_time_unit(Denom);
};
template <>
struct ratio_to_time_unit_helper<60, 1> {
static constexpr time_unit value = time_unit::minutes;
};
/// Converts an STL time period to a `time_unit`.
/// @relates duration
template <class Period>
constexpr time_unit get_time_unit_from_period() {
return ratio_to_time_unit_helper<Period::num, Period::den>::value;
}
/// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct infinite_t {
constexpr infinite_t() {
// nop
}
};
static constexpr infinite_t infinite = infinite_t{};
/// Time duration consisting of a `time_unit` and a 64 bit unsigned integer.
class CAF_CORE_EXPORT duration {
public:
constexpr duration() : unit(time_unit::invalid), count(0) {
// nop
}
constexpr duration(time_unit u, uint32_t v) : unit(u), count(v) {
// nop
}
constexpr duration(infinite_t) : unit(time_unit::invalid), count(0) {
// nop
}
/// Creates a new instance from an STL duration.
/// @throws std::invalid_argument Thrown if `d.count() is negative.
template <class Rep, class Period,
class E
= typename std::enable_if<std::is_integral<Rep>::value
&& get_time_unit_from_period<Period>()
!= time_unit::invalid>::type>
explicit duration(const std::chrono::duration<Rep, Period>& d)
: unit(get_time_unit_from_period<Period>()),
count(d.count() < 0 ? 0u : static_cast<uint64_t>(d.count())) {
// nop
}
/// Returns `unit != time_unit::invalid`.
constexpr bool valid() const {
return unit != time_unit::invalid;
}
/// Returns `count == 0`.
constexpr bool is_zero() const {
return count == 0;
}
time_unit unit;
uint64_t count;
};
/// @relates duration
template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, duration& x) {
return f(x.unit, x.count);
}
/// @relates duration
CAF_CORE_EXPORT std::string to_string(const duration& x);
/// @relates duration
CAF_CORE_EXPORT bool operator==(const duration& lhs, const duration& rhs);
/// @relates duration
inline bool operator!=(const duration& lhs, const duration& rhs) {
return !(lhs == rhs);
}
/// @relates duration
template <class Clock, class Duration>
std::chrono::time_point<Clock, Duration>&
operator+=(std::chrono::time_point<Clock, Duration>& lhs, const duration& rhs) {
switch (rhs.unit) {
case time_unit::invalid:
break;
case time_unit::minutes:
lhs += std::chrono::minutes(rhs.count);
break;
case time_unit::seconds:
lhs += std::chrono::seconds(rhs.count);
break;
case time_unit::milliseconds:
lhs += std::chrono::milliseconds(rhs.count);
break;
case time_unit::microseconds:
lhs += std::chrono::microseconds(rhs.count);
break;
case time_unit::nanoseconds:
lhs += std::chrono::nanoseconds(rhs.count);
break;
}
return lhs;
}
} // namespace caf
......@@ -26,6 +26,7 @@
#include "caf/expected.hpp"
#include "caf/response_type.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/timespan.hpp"
#include "caf/typed_actor.hpp"
namespace caf {
......@@ -35,7 +36,7 @@ class function_view_storage {
public:
using type = function_view_storage;
function_view_storage(T& storage) : storage_(&storage) {
explicit function_view_storage(T& storage) : storage_(&storage) {
// nop
}
......@@ -52,7 +53,8 @@ class function_view_storage<std::tuple<Ts...>> {
public:
using type = function_view_storage;
function_view_storage(std::tuple<Ts...>& storage) : storage_(&storage) {
explicit function_view_storage(std::tuple<Ts...>& storage)
: storage_(&storage) {
// nop
}
......@@ -69,7 +71,7 @@ class function_view_storage<unit_t> {
public:
using type = function_view_storage;
function_view_storage(unit_t&) {
explicit function_view_storage(unit_t&) {
// nop
}
......@@ -81,7 +83,7 @@ public:
struct CAF_CORE_EXPORT function_view_storage_catch_all {
message* storage_;
function_view_storage_catch_all(message& ptr) : storage_(&ptr) {
explicit function_view_storage_catch_all(message& ptr) : storage_(&ptr) {
// nop
}
......@@ -135,11 +137,20 @@ class function_view {
public:
using type = Actor;
function_view(duration rel_timeout = infinite) : timeout(rel_timeout) {
function_view() : timeout(infinite) {
// nop
}
function_view(type impl, duration rel_timeout = infinite)
explicit function_view(timespan rel_timeout) : timeout(rel_timeout) {
// nop
}
explicit function_view(type impl)
: timeout(infinite), impl_(std::move(impl)) {
new_self(impl_);
}
function_view(type impl, timespan rel_timeout)
: timeout(rel_timeout), impl_(std::move(impl)) {
new_self(impl_);
}
......@@ -206,7 +217,7 @@ public:
return impl_;
}
duration timeout;
timespan timeout;
private:
template <class T>
......@@ -258,8 +269,8 @@ bool operator!=(std::nullptr_t x, const function_view<T>& y) {
/// @relates function_view
/// @experimental
template <class T>
function_view<T> make_function_view(const T& x, duration t = infinite) {
return {x, t};
auto make_function_view(const T& x, timespan t = infinite) {
return function_view<T>{x, t};
}
} // namespace caf
......@@ -105,7 +105,6 @@ class config_value;
class deserializer;
class downstream_manager;
class downstream_manager_base;
class duration;
class error;
class event_based_actor;
class execution_unit;
......
......@@ -38,7 +38,6 @@
#include "caf/detail/type_traits.hpp"
#include "caf/detail/typed_actor_util.hpp"
#include "caf/detail/unique_function.hpp"
#include "caf/duration.hpp"
#include "caf/error.hpp"
#include "caf/fwd.hpp"
#include "caf/message.hpp"
......@@ -50,6 +49,7 @@
#include "caf/response_type.hpp"
#include "caf/resumable.hpp"
#include "caf/spawn_options.hpp"
#include "caf/timespan.hpp"
#include "caf/typed_actor.hpp"
#include "caf/typed_response_promise.hpp"
......@@ -91,7 +91,7 @@ public:
/// Requests a new timeout for `mid`.
/// @pre `mid.is_request()`
void request_response_timeout(const duration& d, message_id mid);
void request_response_timeout(timespan d, message_id mid);
// -- spawn functions --------------------------------------------------------
......
......@@ -27,7 +27,6 @@
#include "caf/behavior.hpp"
#include "caf/detail/behavior_impl.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/duration.hpp"
#include "caf/fwd.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/match_case.hpp"
......
......@@ -25,7 +25,6 @@
#include "caf/actor.hpp"
#include "caf/check_typed_input.hpp"
#include "caf/detail/profiled_send.hpp"
#include "caf/duration.hpp"
#include "caf/fwd.hpp"
#include "caf/message.hpp"
#include "caf/message_id.hpp"
......@@ -58,9 +57,10 @@ public:
/// @returns A handle identifying a future-like handle to the response.
/// @warning The returned handle is actor specific and the response to the
/// sent message cannot be received by another actor.
template <message_priority P = message_priority::normal, class Handle = actor,
class... Ts>
auto request(const Handle& dest, const duration& timeout, Ts&&... xs) {
template <message_priority P = message_priority::normal, class Rep = int,
class Period = std::ratio<1>, class Handle = actor, class... Ts>
auto request(const Handle& dest, std::chrono::duration<Rep, Period> timeout,
Ts&&... xs) {
using namespace detail;
static_assert(sizeof...(Ts) > 0, "no message to send");
using token = type_list<implicit_conversions_t<decay_t<Ts>>...>;
......@@ -84,14 +84,6 @@ public:
return handle_type{self, req_id.response_id()};
}
/// @copydoc request
template <message_priority P = message_priority::normal, class Rep = int,
class Period = std::ratio<1>, class Handle = actor, class... Ts>
auto request(const Handle& dest, std::chrono::duration<Rep, Period> timeout,
Ts&&... xs) {
return request(dest, duration{timeout}, std::forward<Ts>(xs)...);
}
/// Sends `{xs...}` to each actor in the range `destinations` as a synchronous
/// message. Response messages get combined into a single result according to
/// the `MergePolicy`.
......@@ -113,10 +105,10 @@ public:
/// @note The returned handle is actor-specific. Only the actor that called
/// `request` can use it for setting response handlers.
template <template <class> class MergePolicy,
message_priority Prio = message_priority::normal, class Container,
class... Ts>
auto fan_out_request(const Container& destinations, const duration& timeout,
Ts&&... xs) {
message_priority Prio = message_priority::normal, class Rep = int,
class Period = std::ratio<1>, class Container, class... Ts>
auto fan_out_request(const Container& destinations,
std::chrono::duration<Rep, Period> timeout, Ts&&... xs) {
using handle_type = typename Container::value_type;
using namespace detail;
static_assert(sizeof...(Ts) > 0, "no message to send");
......@@ -148,16 +140,6 @@ public:
using result_type = response_handle<Subtype, MergePolicy<response_type>>;
return result_type{dptr, std::move(ids)};
}
/// @copydoc fan_out_request
template <template <class> class MergePolicy,
message_priority Prio = message_priority::normal, class Rep,
class Period, class Container, class... Ts>
auto fan_out_request(const Container& destinations,
std::chrono::duration<Rep, Period> timeout, Ts&&... xs) {
return request<MergePolicy, Prio>(destinations, duration{timeout},
std::forward<Ts>(xs)...);
}
};
} // namespace caf::mixin
......@@ -28,7 +28,6 @@
#include "caf/check_typed_input.hpp"
#include "caf/detail/profiled_send.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/duration.hpp"
#include "caf/fwd.hpp"
#include "caf/message.hpp"
#include "caf/message_priority.hpp"
......
......@@ -29,7 +29,6 @@
#include "caf/actor_system.hpp"
#include "caf/atom.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/duration.hpp"
#include "caf/fwd.hpp"
#include "caf/message.hpp"
......
......@@ -22,7 +22,7 @@
#include <type_traits>
#include "caf/detail/core_export.hpp"
#include "caf/duration.hpp"
#include "caf/timespan.hpp"
namespace caf {
......@@ -31,7 +31,7 @@ namespace detail {
class behavior_impl;
CAF_CORE_EXPORT behavior_impl*
new_default_behavior(duration d, std::function<void()> fun);
new_default_behavior(timespan d, std::function<void()> fun);
} // namespace detail
......@@ -39,7 +39,7 @@ template <class F>
struct timeout_definition {
static constexpr bool may_have_timeout = true;
duration timeout;
timespan timeout;
F handler;
......@@ -51,7 +51,8 @@ struct timeout_definition {
timeout_definition(timeout_definition&&) = default;
timeout_definition(const timeout_definition&) = default;
timeout_definition(duration d, F&& f) : timeout(d), handler(std::move(f)) {
timeout_definition(timespan timeout, F&& f)
: timeout(timeout), handler(std::move(f)) {
// nop
}
......
......@@ -20,10 +20,15 @@
#include <chrono>
#include <cstdint>
#include <limits>
namespace caf {
/// A portable timespan type with nanosecond resolution.
using timespan = std::chrono::duration<int64_t, std::nano>;
/// Constant representing an infinite amount of time.
static constexpr timespan infinite
= timespan{std::numeric_limits<int64_t>::max()};
} // namespace caf
......@@ -49,7 +49,6 @@ using sorted_builtin_types
config_value, // @config_value
down_msg, // @down
downstream_msg, // @downstream_msg
duration, // @duration
error, // @error
exit_msg, // @exit
group, // @group
......
......@@ -23,6 +23,7 @@
#include "caf/interface_mismatch.hpp"
#include "caf/message_handler.hpp"
#include "caf/system_messages.hpp"
#include "caf/timespan.hpp"
#include "caf/detail/typed_actor_util.hpp"
......@@ -210,7 +211,7 @@ public:
/// Returns the duration after which receives using
/// this behavior should time out.
const duration& timeout() const {
timespan timeout() const noexcept {
return bhvr_.timeout();
}
......
......@@ -32,7 +32,6 @@
#include "caf/detail/core_export.hpp"
#include "caf/detail/shared_spinlock.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/duration.hpp"
#include "caf/fwd.hpp"
#include "caf/node_id.hpp"
#include "caf/system_messages.hpp"
......
......@@ -247,7 +247,7 @@ void blocking_actor::receive_impl(receive_cond& rcc,
do {
// Reset the timeout each iteration.
auto rel_tout = bhvr.timeout();
if (!rel_tout.valid()) {
if (rel_tout == infinite) {
await_data();
} else {
auto abs_tout = std::chrono::high_resolution_clock::now();
......@@ -289,14 +289,12 @@ void blocking_actor::varargs_tup_receive(receive_cond& rcc, message_id mid,
std::tuple<behavior&>& tup) {
using namespace detail;
auto& bhvr = std::get<0>(tup);
if (bhvr.timeout().valid()) {
auto tmp = after(bhvr.timeout()) >> [&] {
bhvr.handle_timeout();
};
auto fun = make_blocking_behavior(&bhvr, std::move(tmp));
if (bhvr.timeout() == infinite) {
auto fun = make_blocking_behavior(&bhvr);
receive_impl(rcc, mid, fun);
} else {
auto fun = make_blocking_behavior(&bhvr);
auto tmp = after(bhvr.timeout()) >> [&] { bhvr.handle_timeout(); };
auto fun = make_blocking_behavior(&bhvr, std::move(tmp));
receive_impl(rcc, mid, fun);
}
}
......
......@@ -78,7 +78,12 @@ behavior_impl::~behavior_impl() {
// nop
}
behavior_impl::behavior_impl(duration tout)
behavior_impl::behavior_impl()
: timeout_(infinite), begin_(nullptr), end_(nullptr) {
// nop
}
behavior_impl::behavior_impl(timespan tout)
: timeout_(tout), begin_(nullptr), end_(nullptr) {
// nop
}
......
......@@ -32,8 +32,8 @@ result<message> blocking_behavior::fallback(message_view&) {
return skip;
}
duration blocking_behavior::timeout() {
return {};
timespan blocking_behavior::timeout() {
return infinite;
}
void blocking_behavior::handle_timeout() {
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* 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 <sstream>
#include "caf/duration.hpp"
namespace caf {
namespace {
const char* time_unit_strings[] = {
"invalid",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds"
};
const char* time_unit_short_strings[] = {
"?",
"min",
"s",
"ms",
"us",
"ns"
};
} // namespace
std::string to_string(time_unit x) {
return time_unit_strings[static_cast<uint32_t>(x)];
}
std::string to_string(const duration& x) {
if (x.unit == time_unit::invalid)
return "infinite";
auto result = std::to_string(x.count);
result += time_unit_short_strings[static_cast<uint32_t>(x.unit)];
return result;
}
bool operator==(const duration& lhs, const duration& rhs) {
return lhs.unit == rhs.unit && lhs.count == rhs.count;
}
} // namespace caf
......@@ -60,12 +60,12 @@ void local_actor::on_destroy() {
}
}
void local_actor::request_response_timeout(const duration& d, message_id mid) {
CAF_LOG_TRACE(CAF_ARG(d) << CAF_ARG(mid));
if (!d.valid())
void local_actor::request_response_timeout(timespan timeout, message_id mid) {
CAF_LOG_TRACE(CAF_ARG(timeout) << CAF_ARG(mid));
if (timeout == infinite)
return;
auto t = clock().now();
t += d;
t += timeout;
clock().set_request_timeout(t, this, mid.response_id());
}
......
......@@ -480,12 +480,12 @@ uint64_t scheduled_actor::set_receive_timeout() {
CAF_LOG_TRACE("");
if (bhvr_stack_.empty())
return 0;
auto d = bhvr_stack_.back().timeout();
if (!d.valid()) {
auto timeout = bhvr_stack_.back().timeout();
if (timeout == infinite) {
unsetf(has_timeout_flag);
return 0;
}
if (d.is_zero()) {
if (timeout == timespan{0}) {
// immediately enqueue timeout message if duration == 0s
auto id = ++timeout_id_;
auto type = receive_atom::value;
......@@ -493,7 +493,7 @@ uint64_t scheduled_actor::set_receive_timeout() {
return id;
}
auto t = clock().now();
t += d;
t += timeout;
return set_receive_timeout(t);
}
......@@ -532,14 +532,14 @@ uint64_t scheduled_actor::set_stream_timeout(actor_clock::time_point x) {
void scheduled_actor::add_awaited_response_handler(message_id response_id,
behavior bhvr) {
if (bhvr.timeout().valid())
if (bhvr.timeout() != infinite)
request_response_timeout(bhvr.timeout(), response_id);
awaited_responses_.emplace_front(response_id, std::move(bhvr));
}
void scheduled_actor::add_multiplexed_response_handler(message_id response_id,
behavior bhvr) {
if (bhvr.timeout().valid())
if (bhvr.timeout() != infinite)
request_response_timeout(bhvr.timeout(), response_id);
multiplexed_responses_.emplace(response_id, std::move(bhvr));
}
......
......@@ -32,7 +32,6 @@
#include "caf/actor_system_config.hpp"
#include "caf/after.hpp"
#include "caf/defaults.hpp"
#include "caf/duration.hpp"
#include "caf/logger.hpp"
#include "caf/others.hpp"
#include "caf/policy/work_stealing.hpp"
......
......@@ -34,7 +34,6 @@
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/downstream_msg.hpp"
#include "caf/duration.hpp"
#include "caf/group.hpp"
#include "caf/locks.hpp"
#include "caf/logger.hpp"
......@@ -64,7 +63,6 @@ const char* numbered_type_names[] = {
"@config_value",
"@down",
"@downstream_msg",
"@duration",
"@error",
"@exit",
"@group",
......
......@@ -30,9 +30,9 @@
using namespace caf;
namespace {
using namespace std::chrono_literals;
using std::chrono::seconds;
namespace {
struct testee_state {
uint64_t timeout_id = 41;
......@@ -42,17 +42,17 @@ behavior testee(stateful_actor<testee_state, raw_event_based_actor>* self,
detail::test_actor_clock* t) {
return {
[=](ok_atom) {
auto n = t->now() + seconds(10);
auto n = t->now() + 10s;
self->state.timeout_id += 1;
t->set_ordinary_timeout(n, self, atom(""), self->state.timeout_id);
},
[=](add_atom) {
auto n = t->now() + seconds(10);
auto n = t->now() + 10s;
self->state.timeout_id += 1;
t->set_multi_timeout(n, self, atom(""), self->state.timeout_id);
},
[=](put_atom) {
auto n = t->now() + seconds(10);
auto n = t->now() + 10s;
self->state.timeout_id += 1;
auto mid = make_message_id(self->state.timeout_id).response_id();
t->set_request_timeout(n, self, mid);
......@@ -66,12 +66,8 @@ behavior testee(stateful_actor<testee_state, raw_event_based_actor>* self,
[](const std::string&) {
// nop
},
[=](group& grp) {
self->join(grp);
},
[=](exit_msg& x) {
self->quit(x.reason);
}
[=](group& grp) { self->join(grp); },
[=](exit_msg& x) { self->quit(x.reason); },
};
}
......@@ -103,7 +99,7 @@ CAF_TEST(single_receive_timeout) {
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time to send timeout message.
t.advance_time(seconds(10));
t.advance_time(10s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
......@@ -122,7 +118,7 @@ CAF_TEST(override_receive_timeout) {
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time to send timeout message.
t.advance_time(seconds(10));
t.advance_time(10s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
......@@ -136,20 +132,20 @@ CAF_TEST(multi_timeout) {
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time just a little bit.
t.advance_time(seconds(5));
t.advance_time(5s);
// Have AUT call t.set_multi_timeout() again.
self->send(aut, add_atom::value);
expect((add_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 2u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 2u);
// Advance time to send timeout message.
t.advance_time(seconds(5));
t.advance_time(5s);
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Have AUT receive the timeout.
expect((timeout_msg), from(aut).to(aut).with(tid{42}));
// Advance time to send second timeout message.
t.advance_time(seconds(5));
t.advance_time(5s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
......@@ -163,25 +159,24 @@ CAF_TEST(mixed_receive_and_multi_timeouts) {
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time just a little bit.
t.advance_time(seconds(5));
t.advance_time(5s);
// Have AUT call t.set_multi_timeout() again.
self->send(aut, ok_atom::value);
expect((ok_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 2u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 2u);
// Advance time to send timeout message.
t.advance_time(seconds(5));
t.advance_time(5s);
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Have AUT receive the timeout.
expect((timeout_msg), from(aut).to(aut).with(tid{42}));
// Advance time to send second timeout message.
t.advance_time(seconds(5));
t.advance_time(5s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
expect((timeout_msg), from(aut).to(aut).with(tid{43}));
}
CAF_TEST(single_request_timeout) {
......@@ -191,7 +186,7 @@ CAF_TEST(single_request_timeout) {
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Advance time to send timeout message.
t.advance_time(seconds(10));
t.advance_time(10s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
......@@ -205,20 +200,20 @@ CAF_TEST(mixed_receive_and_request_timeouts) {
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Cause the request timeout to arrive later.
t.advance_time(seconds(5));
t.advance_time(5s);
// Have AUT call t.set_request_timeout().
self->send(aut, put_atom::value);
expect((put_atom), from(self).to(aut).with(_));
CAF_CHECK_EQUAL(t.schedule().size(), 2u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 2u);
// Advance time to send receive timeout message.
t.advance_time(seconds(5));
t.advance_time(5s);
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 1u);
// Have AUT receive the timeout.
expect((timeout_msg), from(aut).to(aut).with(tid{42}));
// Advance time to send request timeout message.
t.advance_time(seconds(10));
t.advance_time(10s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the timeout.
......@@ -227,15 +222,15 @@ CAF_TEST(mixed_receive_and_request_timeouts) {
CAF_TEST(delay_actor_message) {
// Schedule a message for now + 10s.
auto n = t.now() + seconds(10);
auto n = t.now() + 10s;
auto autptr = actor_cast<strong_actor_ptr>(aut);
t.schedule_message(n, autptr,
make_mailbox_element(autptr, make_message_id(),
no_stages, "foo"));
make_mailbox_element(autptr, make_message_id(), no_stages,
"foo"));
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Advance time to send the message.
t.advance_time(seconds(10));
t.advance_time(10s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the message.
......@@ -248,13 +243,13 @@ CAF_TEST(delay_group_message) {
self->send(aut, grp);
expect((group), from(self).to(aut).with(_));
// Schedule a message for now + 10s.
auto n = t.now() + seconds(10);
auto n = t.now() + 10s;
auto autptr = actor_cast<strong_actor_ptr>(aut);
t.schedule_message(n, std::move(grp), autptr, make_message("foo"));
CAF_CHECK_EQUAL(t.schedule().size(), 1u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Advance time to send the message.
t.advance_time(seconds(10));
t.advance_time(10s);
CAF_CHECK_EQUAL(t.schedule().size(), 0u);
CAF_CHECK_EQUAL(t.actor_lookup().size(), 0u);
// Have AUT receive the message.
......
......@@ -29,7 +29,6 @@
#include "caf/actor_system_config.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/duration.hpp"
#include "caf/timestamp.hpp"
using namespace caf;
......@@ -55,7 +54,6 @@ struct test_data {
int64_t i64_;
float f32_;
double f64_;
caf::duration dur_;
caf::timestamp ts_;
test_enum te_;
std::string str_;
......@@ -70,7 +68,7 @@ bool operator==(const test_data& data, const test_data& other) {
template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, test_data& x) {
return f(caf::meta::type_name("test_data"), x.i32_, x.i64_, x.f32_, x.f64_,
x.dur_, x.ts_, x.te_, x.str_);
x.ts_, x.te_, x.str_);
}
struct fixture {
......@@ -189,13 +187,6 @@ CAF_TEST(container types) {
}
CAF_TEST(binary serializer picks up inspect functions) {
SUBTEST("duration") {
CHECK_LOAD(duration, duration(time_unit::minutes, 3),
// Bytes 1-4 contain the time_unit.
0_b, 0_b, 0_b, 1_b,
// Bytes 5-12 contain the count.
0_b, 0_b, 0_b, 0_b, 0_b, 0_b, 0_b, 3_b);
}
SUBTEST("node ID") {
auto nid = make_node_id(123, "000102030405060708090A0B0C0D0E0F10111213");
CHECK_LOAD(node_id, unbox(nid),
......@@ -213,7 +204,6 @@ CAF_TEST(binary serializer picks up inspect functions) {
-1234567890123456789ll,
3.45,
54.3,
caf::duration(caf::time_unit::seconds, 123),
caf::timestamp{caf::timestamp::duration{1478715821 * 1000000000ll}},
test_enum::b,
"Lorem ipsum dolor sit amet."};
......@@ -226,10 +216,6 @@ CAF_TEST(binary serializer picks up inspect functions) {
0x40_b, 0x5C_b, 0xCC_b, 0xCD_b,
// 64-bit f64_ member: 54.3
0x40_b, 0x4B_b, 0x26_b, 0x66_b, 0x66_b, 0x66_b, 0x66_b, 0x66_b,
// 32-bit dur_.unit member: time_unit::seconds
0x00_b, 0x00_b, 0x00_b, 0x02_b,
// 64-bit dur_.count member: 123
0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x7B_b,
// 64-bit ts_ member.
0x14_b, 0x85_b, 0x74_b, 0x34_b, 0x62_b, 0x74_b, 0x82_b, 0x00_b,
// 32-bit te_ member: test_enum::b
......
......@@ -29,7 +29,6 @@
#include "caf/actor_system_config.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/duration.hpp"
#include "caf/timestamp.hpp"
using namespace caf;
......@@ -55,7 +54,6 @@ struct test_data {
int64_t i64_;
float f32_;
double f64_;
caf::duration dur_;
caf::timestamp ts_;
test_enum te_;
std::string str_;
......@@ -64,7 +62,7 @@ struct test_data {
template <class Inspector>
typename Inspector::result_type inspect(Inspector& f, test_data& x) {
return f(caf::meta::type_name("test_data"), x.i32_, x.i64_, x.f32_, x.f64_,
x.dur_, x.ts_, x.te_, x.str_);
x.ts_, x.te_, x.str_);
}
struct fixture {
......@@ -182,13 +180,6 @@ CAF_TEST(container types) {
}
CAF_TEST(binary serializer picks up inspect functions) {
SUBTEST("duration") {
CHECK_SAVE(duration, duration(time_unit::minutes, 3),
// Bytes 1-4 contain the time_unit.
0_b, 0_b, 0_b, 1_b,
// Bytes 5-12 contain the count.
0_b, 0_b, 0_b, 0_b, 0_b, 0_b, 0_b, 3_b);
}
SUBTEST("node ID") {
auto nid = make_node_id(123, "000102030405060708090A0B0C0D0E0F10111213");
CHECK_SAVE(node_id, unbox(nid),
......@@ -206,7 +197,6 @@ CAF_TEST(binary serializer picks up inspect functions) {
-1234567890123456789ll,
3.45,
54.3,
caf::duration(caf::time_unit::seconds, 123),
ts,
test_enum::b,
"Lorem ipsum dolor sit amet."};
......@@ -219,10 +209,6 @@ CAF_TEST(binary serializer picks up inspect functions) {
0x40_b, 0x5C_b, 0xCC_b, 0xCD_b,
// 64-bit f64_ member: 54.3
0x40_b, 0x4B_b, 0x26_b, 0x66_b, 0x66_b, 0x66_b, 0x66_b, 0x66_b,
// 32-bit dur_.unit member: time_unit::seconds
0x00_b, 0x00_b, 0x00_b, 0x02_b,
// 64-bit dur_.count member: 123
0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x00_b, 0x7B_b,
// 64-bit ts_ member.
0x14_b, 0x85_b, 0x74_b, 0x34_b, 0x62_b, 0x74_b, 0x82_b, 0x00_b,
// 32-bit te_ member: test_enum::b
......
......@@ -144,7 +144,6 @@ struct fixture : test_coordinator_fixture<config> {
int64_t i64 = -1234567890123456789ll;
float f32 = 3.45f;
double f64 = 54.3;
duration dur = duration{time_unit::seconds, 123};
timestamp ts = timestamp{timestamp::duration{1478715821 * 1000000000ll}};
test_enum te = test_enum::b;
string str = "Lorem ipsum dolor sit amet.";
......@@ -198,7 +197,7 @@ struct fixture : test_coordinator_fixture<config> {
fixture() {
rs.str.assign(string(str.rbegin(), str.rend()));
msg = make_message(i32, i64, dur, ts, te, str, rs);
msg = make_message(i32, i64, ts, te, str, rs);
config_value::dictionary dict;
put(dict, "scheduler.policy", atom("none"));
put(dict, "scheduler.max-threads", 42);
......@@ -255,7 +254,6 @@ CAF_TEST(serializing and then deserializing produces the same value) {
CHECK_RT(i64);
CHECK_RT(f32);
CHECK_RT(f64);
CHECK_RT(dur);
CHECK_RT(ts);
CHECK_RT(te);
CHECK_RT(str);
......@@ -268,7 +266,6 @@ CAF_TEST(messages serialize and deserialize their content) {
CHECK_MSG_RT(i64);
CHECK_MSG_RT(f32);
CHECK_MSG_RT(f64);
CHECK_MSG_RT(dur);
CHECK_MSG_RT(ts);
CHECK_MSG_RT(te);
CHECK_MSG_RT(str);
......@@ -321,14 +318,14 @@ CAF_TEST(messages) {
auto buf1 = serialize(msg);
deserialize(buf1, x);
CAF_CHECK_EQUAL(to_string(msg), to_string(x));
CAF_CHECK(is_message(x).equal(i32, i64, dur, ts, te, str, rs));
CAF_CHECK(is_message(x).equal(i32, i64, ts, te, str, rs));
// serialize fully dynamic message again (do another roundtrip)
message y;
auto buf2 = serialize(x);
CAF_CHECK_EQUAL(buf1, buf2);
deserialize(buf2, y);
CAF_CHECK_EQUAL(to_string(msg), to_string(y));
CAF_CHECK(is_message(y).equal(i32, i64, dur, ts, te, str, rs));
CAF_CHECK(is_message(y).equal(i32, i64, ts, te, str, rs));
CAF_CHECK_EQUAL(to_string(recursive), to_string(roundtrip(recursive)));
}
......@@ -342,7 +339,7 @@ CAF_TEST(multiple_messages) {
CAF_CHECK_EQUAL(std::make_tuple(t, to_string(m1), to_string(m2)),
std::make_tuple(te, to_string(m), to_string(msg)));
CAF_CHECK(is_message(m1).equal(rs, te));
CAF_CHECK(is_message(m2).equal(i32, i64, dur, ts, te, str, rs));
CAF_CHECK(is_message(m2).equal(i32, i64, ts, te, str, rs));
}
CAF_TEST(type_erased_value) {
......
......@@ -75,14 +75,6 @@ timer::behavior_type timer_impl2(timer::pointer self) {
CAF_TEST_FIXTURE_SCOPE(simple_timeout_tests, test_coordinator_fixture<>)
CAF_TEST(duration_conversion) {
duration d1{time_unit::milliseconds, 100};
std::chrono::milliseconds d2{100};
duration d3{d2};
CAF_CHECK_EQUAL(d1.count, static_cast<uint64_t>(d2.count()));
CAF_CHECK_EQUAL(d1, d3);
}
CAF_TEST(single_timeout) {
sys.spawn(timer_impl);
}
......
......@@ -18,6 +18,7 @@
#pragma once
#include <chrono>
#include <map>
#include <memory>
#include <thread>
......@@ -34,6 +35,7 @@
#include "caf/node_id.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/send.hpp"
#include "caf/timespan.hpp"
namespace caf::io {
......@@ -156,7 +158,7 @@ public:
template <class Handle>
expected<Handle>
remote_spawn(const node_id& nid, std::string name, message args,
duration timeout = duration(time_unit::minutes, 1)) {
timespan timeout = timespan{std::chrono::minutes{1}}) {
if (!nid || name.empty())
return sec::invalid_argument;
auto res = remote_spawn_impl(nid, name, args,
......@@ -172,7 +174,7 @@ public:
remote_spawn(const node_id& nid, std::string name, message args,
std::chrono::duration<Rep, Period> timeout) {
return remote_spawn<Handle>(nid, std::move(name), std::move(args),
duration{timeout});
timespan{timeout});
}
/// Smart pointer for `network::multiplexer`.
......@@ -207,7 +209,7 @@ public:
/// Returns a new functor-based broker connected
/// to `host:port` or an `error`.
/// @warning Blocks the caller for the duration of the connection process.
/// @warning Blocks the caller for the timespan of the connection process.
template <spawn_options Os = no_spawn_options,
class F = std::function<void(broker*)>, class... Ts>
expected<typename infer_handle_from_fun<F>::type>
......@@ -304,7 +306,7 @@ private:
expected<strong_actor_ptr>
remote_spawn_impl(const node_id& nid, std::string& name, message& args,
std::set<std::string> s, duration timeout);
std::set<std::string> s, timespan timeout);
expected<uint16_t>
publish(const strong_actor_ptr& whom, std::set<std::string> sigs,
......
......@@ -102,7 +102,7 @@ middleman::middleman(actor_system& sys) : system_(sys) {
expected<strong_actor_ptr>
middleman::remote_spawn_impl(const node_id& nid, std::string& name,
message& args, std::set<std::string> s,
duration timeout) {
timespan timeout) {
auto f = make_function_view(actor_handle(), timeout);
return f(spawn_atom::value, nid, std::move(name), std::move(args),
std::move(s));
......
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