Skip to content

Commit 16afd92

Browse files
Integrate review feedback
1 parent 827ce03 commit 16afd92

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

libcaf_core/caf/actor_control_block.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ CAF_CORE_EXPORT void intrusive_ptr_release_weak(actor_control_block* x);
136136

137137
/// @relates actor_control_block
138138
inline void intrusive_ptr_add_ref(actor_control_block* x) {
139-
x->strong_refs.fetch_add(1, std::memory_order_relaxed);
139+
#define CAF_UNLIKELY(x) __builtin_expect(!!(x), 0)
140+
if (CAF_UNLIKELY(x->strong_refs.fetch_add(1, std::memory_order_relaxed) == 0)) {
141+
CAF_LOG_CRITICAL("increased the strong reference count of an expired actor");
142+
}
143+
#undef CAF_UNLIKELY
140144
}
141145

142146
/// @relates actor_control_block

libcaf_core/src/response_promise.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,16 @@ void response_promise::state::cancel() {
167167
void response_promise::state::deliver_impl(message msg) {
168168
CAF_LOG_TRACE(CAF_ARG(msg));
169169
auto cancel_guard = detail::make_scope_guard([this] {
170-
cancel();
171-
});
170+
cancel();
171+
});
172172
if (msg.empty() && id.is_async()) {
173173
CAF_LOG_DEBUG("drop response: empty response to asynchronous input");
174174
return;
175175
}
176+
if (source == nullptr) {
177+
CAF_LOG_DEBUG("drop response: source is nullptr");
178+
return;
179+
}
176180
auto self = weak_self.lock();
177181
if (self == nullptr) {
178182
auto element = make_mailbox_element(self, id.response_id(),
@@ -181,15 +185,14 @@ void response_promise::state::deliver_impl(message msg) {
181185
source->enqueue(std::move(element), nullptr);
182186
return;
183187
}
184-
auto local_self = static_cast<local_actor*>(weak_self.get()->get());
188+
auto local_self = static_cast<local_actor*>(self->get());
185189
if (!stages.empty()) {
186190
auto next = std::move(stages.back());
187191
stages.pop_back();
188192
detail::profiled_send(local_self, std::move(source), next, id, std::move(stages),
189193
local_self->context(), std::move(msg));
190194
return;
191195
}
192-
CAF_ASSERT(source != nullptr);
193196
detail::profiled_send(local_self, local_self->ctrl(), source, id.response_id(),
194197
forwarding_stack{}, local_self->context(), std::move(msg));
195198
}

0 commit comments

Comments
 (0)