Commit bdb7d450 authored by Dominik Charousset's avatar Dominik Charousset

Maintenance and coding style

parent 9f16ab2e
......@@ -122,7 +122,9 @@ class proper_actor_base : public Policies::resume_policy::template
awaited_response);
}
inline bool hidden() const { return this->m_hidden; }
inline bool hidden() const {
return this->m_hidden;
}
void cleanup(uint32_t reason) override {
CAF_LOG_TRACE(CAF_ARG(reason));
......@@ -167,8 +169,7 @@ class proper_actor_base : public Policies::resume_policy::template
// this is the nonblocking version of proper_actor; it assumes that Base is
// derived from local_actor and uses the behavior_stack_based mixin
template <class Base,
class Policies,
template <class Base, class Policies,
bool OverrideDequeue = std::is_base_of<blocking_actor, Base>::value>
class proper_actor
: public proper_actor_base<Base, proper_actor<Base, Policies, false>,
......@@ -179,10 +180,10 @@ class proper_actor
static_assert(std::is_base_of<local_actor, Base>::value,
"Base is not derived from local_actor");
template <class... Ts>
proper_actor(Ts&&... args)
: super(std::forward<Ts>(args)...) {}
proper_actor(Ts&&... args) : super(std::forward<Ts>(args)...) {
// nop
}
// required by event_based_resume::mixin::resume
......@@ -245,7 +246,6 @@ class proper_actor<Base, Policies, true>
if (!tmp_vec.empty()) {
this->cache_prepend(tmp_vec.begin(), tmp_vec.end());
}
};
while (!this->cache_empty()) {
auto tmp = this->cache_take_first();
......@@ -270,15 +270,17 @@ class proper_actor<Base, Policies, true>
if (has_timeout) {
auto e = pending_timeouts.end();
auto i = std::find(pending_timeouts.begin(), e, timeout_id);
if (i != e) pending_timeouts.erase(i);
if (i != e) {
pending_timeouts.erase(i);
}
}
});
// read incoming messages
for (;;) {
auto msg = this->next_message();
if (!msg)
if (!msg) {
this->await_ready();
else {
} else {
if (this->invoke_message(msg, bhvr, mid)) {
// we're done
return;
......@@ -300,8 +302,9 @@ class proper_actor<Base, Policies, true>
this->m_host);
// auto e = this->new_mailbox_element(this, std::move(msg));
// this->m_mailbox.enqueue(e);
} else
} else {
this->delayed_send_tuple(this, d, std::move(msg));
}
m_pending_timeouts.push_back(tid);
return tid;
}
......
......@@ -225,9 +225,9 @@ class single_reader_queue {
template <class Mutex, class CondVar>
bool synchronized_enqueue(Mutex& mtx, CondVar& cv, pointer new_element) {
std::unique_lock<Mutex> guard(mtx);
switch (enqueue(new_element)) {
case enqueue_result::unblocked_reader: {
std::unique_lock<Mutex> guard(mtx);
cv.notify_one();
return true;
}
......@@ -244,18 +244,18 @@ class single_reader_queue {
template <class Mutex, class CondVar>
void synchronized_await(Mutex& mtx, CondVar& cv) {
std::unique_lock<Mutex> guard(mtx);
CAF_REQUIRE(!closed());
if (try_block()) {
std::unique_lock<Mutex> guard(mtx);
while (blocked()) cv.wait(guard);
}
}
template <class Mutex, class CondVar, class TimePoint>
bool synchronized_await(Mutex& mtx, CondVar& cv, const TimePoint& timeout) {
std::unique_lock<Mutex> guard(mtx);
CAF_REQUIRE(!closed());
if (try_block()) {
std::unique_lock<Mutex> guard(mtx);
while (blocked()) {
if (cv.wait_until(guard, timeout) == std::cv_status::timeout) {
// if we're unable to set the queue from blocked to empty,
......
......@@ -11,30 +11,28 @@
namespace caf {
namespace policy {
// this policy simply forwards calls to @p await_data to the scheduling
// policy and throws an exception whenever @p resume is called;
// it intentionally works only with the no_scheduling policy
class no_resume {
public:
template <class Base, class Derived>
struct mixin : Base {
template <class... Ts>
mixin(Ts&&... args)
: Base(std::forward<Ts>(args)...), m_hidden(true) {}
mixin(Ts&&... args) : Base(std::forward<Ts>(args)...), m_hidden(true) {
// nop
}
inline void attach_to_scheduler() { this->ref(); }
void attach_to_scheduler() {
this->ref();
}
inline void detach_from_scheduler() { this->deref(); }
void detach_from_scheduler() {
this->deref();
}
inline resumable::resume_result resume(execution_unit*) {
resumable::resume_result resume(execution_unit*) {
auto done_cb = [=](uint32_t reason) {
this->planned_exit_reason(reason);
this->on_exit();
this->cleanup(reason);
};
try {
this->act();
......@@ -50,14 +48,12 @@ class no_resume {
}
bool m_hidden;
};
template <class Actor>
void await_ready(Actor* self) {
self->await_data();
}
};
} // namespace policy
......
......@@ -37,15 +37,17 @@
#include "caf/detail/sync_request_bouncer.hpp"
#include "caf/detail/single_reader_queue.hpp"
#include "caf/actor_ostream.hpp"
namespace caf {
namespace policy {
class no_scheduling {
using lock_type = std::unique_lock<std::mutex>;
public:
using timeout_type = std::chrono::high_resolution_clock::time_point;
template <class Actor>
......@@ -83,8 +85,7 @@ class no_scheduling {
}).detach();
}
// await_data is being called from no_scheduling (only)
// await_data is being called from no_resume (only)
template <class Actor>
void await_data(Actor* self) {
if (self->has_next_message()) return;
......@@ -100,10 +101,8 @@ class no_scheduling {
}
private:
std::mutex m_mtx;
std::condition_variable m_cv;
};
} // namespace policy
......
......@@ -113,12 +113,10 @@ class timer_actor final : public detail::proper_actor<blocking_actor,
on(atom("_Send"), arg_match) >> [&](const duration& d,
actor_addr& from, channel& to,
message_id mid, message& tup) {
aout(this) << "new timeout requested!\n";
insert_dmsg(messages, d, std::move(from),
std::move(to), mid, std::move(tup));
},
[&](const exit_msg&) {
aout(this) << "DONE!\n";
done = true;
},
others() >> [&] {
......@@ -136,7 +134,6 @@ aout(this) << "DONE!\n";
// handle timeouts (send messages)
auto it = messages.begin();
while (it != messages.end() && (it->first) <= tout) {
aout(this) << "deliver timeout!\n";
deliver(it->second);
messages.erase(it);
it = messages.begin();
......
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