Commit c03e6b9f authored by Dominik Charousset's avatar Dominik Charousset

Use a weak pointer for stream IDs

parent 0a66cc86
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
#include <cstdint> #include <cstdint>
#include "caf/actor_addr.hpp"
#include "caf/meta/type_name.hpp" #include "caf/meta/type_name.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/detail/comparable.hpp" #include "caf/detail/comparable.hpp"
...@@ -31,17 +32,22 @@ namespace caf { ...@@ -31,17 +32,22 @@ namespace caf {
class stream_id : detail::comparable<stream_id> { class stream_id : detail::comparable<stream_id> {
public: public:
stream_id() = default;
stream_id(stream_id&&) = default; stream_id(stream_id&&) = default;
stream_id(const stream_id&) = default; stream_id(const stream_id&) = default;
stream_id& operator=(stream_id&&) = default; stream_id& operator=(stream_id&&) = default;
stream_id& operator=(const stream_id&) = default; stream_id& operator=(const stream_id&) = default;
stream_id(strong_actor_ptr origin_actor, uint64_t origin_nr); stream_id();
stream_id(actor_addr origin_actor, uint64_t origin_nr);
stream_id(actor_control_block* origin_actor, uint64_t origin_nr);
stream_id(const strong_actor_ptr& origin_actor, uint64_t origin_nr);
int64_t compare(const stream_id& other) const; int64_t compare(const stream_id& other) const;
strong_actor_ptr origin; actor_addr origin;
uint64_t nr; uint64_t nr;
inline bool valid() const { inline bool valid() const {
......
...@@ -23,12 +23,27 @@ ...@@ -23,12 +23,27 @@
namespace caf { namespace caf {
stream_id::stream_id(strong_actor_ptr origin_actor, uint64_t origin_nr) stream_id::stream_id() : origin(nullptr), nr(0) {
// nop
}
stream_id::stream_id(actor_addr origin_actor, uint64_t origin_nr)
: origin(std::move(origin_actor)), : origin(std::move(origin_actor)),
nr(origin_nr) { nr(origin_nr) {
// nop // nop
} }
stream_id::stream_id(actor_control_block* origin_actor, uint64_t origin_nr)
: stream_id(origin_actor->address(), origin_nr) {
// nop
}
stream_id::stream_id(const strong_actor_ptr& origin_actor, uint64_t origin_nr)
: stream_id(origin_actor->address(), origin_nr) {
// nop
}
int64_t stream_id::compare(const stream_id& other) const { int64_t stream_id::compare(const stream_id& other) const {
auto r0 = static_cast<ptrdiff_t>(origin.get() - other.origin.get()); auto r0 = static_cast<ptrdiff_t>(origin.get() - other.origin.get());
if (r0 != 0) if (r0 != 0)
......
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