Commit 4166b8e1 authored by Etienne Baratte's avatar Etienne Baratte

fix local_group::erase_subscriber

parent 4836d709
...@@ -232,6 +232,17 @@ bool operator<(const intrusive_ptr<T>& x, const intrusive_ptr<T>& y) { ...@@ -232,6 +232,17 @@ bool operator<(const intrusive_ptr<T>& x, const intrusive_ptr<T>& y) {
return x.get() < y.get(); return x.get() < y.get();
} }
/// @relates intrusive_ptr
template <class T>
bool operator<(const intrusive_ptr<T>& x, const T* y) {
return x.get() < y;
}
/// @relates intrusive_ptr
template <class T>
bool operator<(const T* x, const intrusive_ptr<T>& y) {
return x < y.get();
}
template <class T> template <class T>
std::string to_string(const intrusive_ptr<T>& x) { std::string to_string(const intrusive_ptr<T>& x) {
auto v = reinterpret_cast<uintptr_t>(x.get()); auto v = reinterpret_cast<uintptr_t>(x.get());
......
...@@ -87,12 +87,16 @@ public: ...@@ -87,12 +87,16 @@ public:
std::pair<bool, size_t> erase_subscriber(const actor_control_block* who) { std::pair<bool, size_t> erase_subscriber(const actor_control_block* who) {
CAF_LOG_TRACE(""); // serializing who would cause a deadlock CAF_LOG_TRACE(""); // serializing who would cause a deadlock
exclusive_guard guard(mtx_); exclusive_guard guard(mtx_);
auto cmp = [](const strong_actor_ptr& lhs, const actor_control_block* rhs) {
return actor_addr::compare(lhs.get(), rhs) < 0;
};
auto e = subscribers_.end(); auto e = subscribers_.end();
auto i = std::lower_bound(subscribers_.begin(), e, who, cmp); #if __cplusplus > 201103L
if (i == e || actor_addr::compare(i->get(), who) != 0) auto i = subscribers_.find(who);
#else
auto cmp = [&](const strong_actor_ptr& lhs) {
return lhs.get() == who;
};
auto i = std::find_if(subscribers_.begin(), e, cmp);
#endif
if(i == e)
return {false, subscribers_.size()}; return {false, subscribers_.size()};
subscribers_.erase(i); subscribers_.erase(i);
return {true, subscribers_.size()}; return {true, subscribers_.size()};
...@@ -126,7 +130,11 @@ public: ...@@ -126,7 +130,11 @@ public:
protected: protected:
detail::shared_spinlock mtx_; detail::shared_spinlock mtx_;
#if __cplusplus > 201103L
std::set<strong_actor_ptr, std::less<>> subscribers_;
#else
std::set<strong_actor_ptr> subscribers_; std::set<strong_actor_ptr> subscribers_;
#endif
actor broker_; actor broker_;
}; };
......
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