refactor: run clang linter and formatter
This commit is contained in:
parent
7668befc06
commit
2dd2b9e087
27 changed files with 189 additions and 157 deletions
|
@ -17,7 +17,7 @@ constexpr auto cbor_magic_false = 0xf4;
|
|||
constexpr auto cbor_magic_type_array = 4;
|
||||
constexpr auto cbor_magic_type_map = 5;
|
||||
|
||||
enum class type {
|
||||
enum class type : uint8_t {
|
||||
number,
|
||||
bytes,
|
||||
string,
|
||||
|
@ -326,7 +326,7 @@ public:
|
|||
}
|
||||
auto operator*() -> value_accessor {
|
||||
if (n)
|
||||
return {b, e};
|
||||
return {.b = b, .e = e};
|
||||
throw std::out_of_range("cbor iterator out of range");
|
||||
}
|
||||
};
|
||||
|
@ -337,10 +337,10 @@ public:
|
|||
auto b = raw_cbegin();
|
||||
auto e = raw_cend();
|
||||
auto n = decode_range_header(b, e);
|
||||
return {b, e, n};
|
||||
return {.b = b, .e = e, .n = n};
|
||||
}
|
||||
[[nodiscard]] auto end() const -> value_iterator {
|
||||
return {raw_cend(), raw_cend()};
|
||||
return {.b = raw_cend(), .e = raw_cend()};
|
||||
}
|
||||
|
||||
class range {
|
||||
|
@ -355,10 +355,10 @@ public:
|
|||
auto b = raw_cbegin();
|
||||
auto e = raw_cend();
|
||||
auto n = decode_range_header(b, e);
|
||||
return {b, e, n};
|
||||
return {.b = b, .e = e, .n = n};
|
||||
}
|
||||
[[nodiscard]] auto end() const -> value_iterator {
|
||||
return {raw_cend(), raw_cend()};
|
||||
return {.b = raw_cend(), .e = raw_cend()};
|
||||
}
|
||||
|
||||
auto is_null() -> bool {
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace thespian::unx {
|
||||
|
||||
enum class mode { file, abstract };
|
||||
enum class mode : uint8_t { file, abstract };
|
||||
|
||||
struct acceptor_impl;
|
||||
using acceptor_dtor = void (*)(acceptor_impl *);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace {
|
||||
static void msg(const char *msg, const char *arg) {
|
||||
if (write(STDERR_FILENO, msg, strlen(msg)) != 0) {
|
||||
}
|
||||
|
@ -46,7 +47,7 @@ static auto get_debugger() -> const char * {
|
|||
}
|
||||
const char *const debugger = get_debugger();
|
||||
|
||||
void start_debugger(const char * dbg, const char **argv) {
|
||||
void start_debugger(const char *dbg, const char **argv) {
|
||||
#if defined(PR_SET_PTRACER)
|
||||
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); // NOLINT
|
||||
#endif
|
||||
|
@ -61,6 +62,7 @@ void start_debugger(const char * dbg, const char **argv) {
|
|||
waitpid(child_pid, &stat, 0);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" void sighdl_debugger(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
||||
get_pid_binpath();
|
||||
|
@ -73,14 +75,15 @@ extern "C" void sighdl_debugger(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
|||
extern "C" void sighdl_backtrace(int no, siginfo_t * /*sigi*/, void * /*uco*/) {
|
||||
get_pid_binpath();
|
||||
const char *argv[] = {// NOLINT
|
||||
lldb, "--batch", "-p", pid_s,
|
||||
lldb, "--batch", "-p", pid_s,
|
||||
"--one-line", "bt", binpath, nullptr};
|
||||
start_debugger(lldb, argv);
|
||||
(void)raise(no);
|
||||
}
|
||||
|
||||
namespace {
|
||||
static void install_crash_handler(void (*hdlr)(int, siginfo_t *, void *)) {
|
||||
struct sigaction action {};
|
||||
struct sigaction action{};
|
||||
sigemptyset(&action.sa_mask);
|
||||
action.sa_flags = SA_SIGINFO | SA_RESETHAND;
|
||||
#ifdef SA_FULLDUMP
|
||||
|
@ -93,6 +96,7 @@ static void install_crash_handler(void (*hdlr)(int, siginfo_t *, void *)) {
|
|||
sigaction(SIGTRAP, &action, nullptr);
|
||||
sigaction(SIGFPE, &action, nullptr);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" void install_debugger() { install_crash_handler(sighdl_debugger); }
|
||||
extern "C" void install_backtrace() { install_crash_handler(sighdl_backtrace); }
|
||||
|
|
|
@ -66,5 +66,4 @@ auto thespian_handle_is_expired(thespian_handle h) -> bool {
|
|||
h)};
|
||||
return h_->expired();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ using thespian::stop_metronome;
|
|||
|
||||
extern "C" {
|
||||
|
||||
auto thespian_metronome_create_ms(uint64_t ms)
|
||||
-> thespian_metronome_handle * {
|
||||
auto thespian_metronome_create_ms(uint64_t ms) -> thespian_metronome_handle * {
|
||||
try {
|
||||
auto *handle = thespian::create_metronome(milliseconds(ms)).ref.release();
|
||||
return reinterpret_cast<thespian_metronome_handle *>(handle); // NOLINT
|
||||
|
@ -27,8 +26,7 @@ auto thespian_metronome_create_ms(uint64_t ms)
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
auto thespian_metronome_create_us(uint64_t us)
|
||||
-> thespian_metronome_handle * {
|
||||
auto thespian_metronome_create_us(uint64_t us) -> thespian_metronome_handle * {
|
||||
try {
|
||||
auto *handle = thespian::create_metronome(microseconds(us)).ref.release();
|
||||
return reinterpret_cast<thespian_metronome_handle *>(handle); // NOLINT
|
||||
|
|
|
@ -18,5 +18,4 @@ void thespian_trace_to_cbor_file(const char *file_name) {
|
|||
void thespian_trace_to_mermaid_file(const char *file_name) {
|
||||
thespian::trace_to_mermaid_file(file_name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
25
src/cbor.cpp
25
src/cbor.cpp
|
@ -71,6 +71,7 @@ auto buffer::push_string(const string_view &s) -> buffer & {
|
|||
|
||||
using json_iter = string::const_iterator;
|
||||
|
||||
namespace {
|
||||
static auto match_wsp_char(json_iter &b, const json_iter &e) -> bool {
|
||||
if (b == e)
|
||||
return false;
|
||||
|
@ -347,6 +348,7 @@ static auto push_json_value(buffer &buf, json_iter &b, const json_iter &e)
|
|||
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::push_json(const string &s) -> void {
|
||||
json_iter b = s.cbegin();
|
||||
|
@ -360,6 +362,7 @@ auto buffer::push_json(const string &s) -> void {
|
|||
|
||||
using iter = buffer::const_iterator;
|
||||
|
||||
namespace {
|
||||
static auto decode_int_length_recurse(size_t length, iter &b, const iter &e,
|
||||
int64_t i) -> int64_t {
|
||||
if (b == e)
|
||||
|
@ -426,6 +429,7 @@ static auto decode_type(iter &b, const iter &e)
|
|||
++b;
|
||||
return make_tuple(uint8_t(type >> 5), uint8_t(type & 31), type);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::decode_range_header(iter &b, const iter &e) -> size_t {
|
||||
const auto [major, minor, type] = decode_type(b, e);
|
||||
|
@ -460,6 +464,7 @@ auto buffer::decode_map_header(iter &b, const iter &e) -> size_t {
|
|||
return decode_pint(minor, b, e);
|
||||
}
|
||||
|
||||
namespace {
|
||||
static auto skip_string(uint8_t type, iter &b, const iter &e) -> void {
|
||||
auto len = decode_pint(type, b, e);
|
||||
while (len) {
|
||||
|
@ -559,6 +564,7 @@ static auto match_type(iter &b, const iter &e, type &v) -> bool {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::match_value(iter &b, const iter &e, type t) -> bool {
|
||||
type v{type::any};
|
||||
|
@ -570,6 +576,7 @@ auto buffer::match_value(iter &b, const iter &e, type t) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
static auto match_uint(iter &b, const iter &e, unsigned long long int &val)
|
||||
-> bool {
|
||||
const auto [major, minor, type] = decode_type(b, e);
|
||||
|
@ -596,6 +603,7 @@ static auto match_int(iter &b, const iter &e, signed long long int &val)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::match_value(iter &b, const iter &e, unsigned long long int lit)
|
||||
-> bool {
|
||||
|
@ -613,6 +621,7 @@ auto buffer::match_value(iter &b, const iter &e, signed long long int lit)
|
|||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
static auto match_bool(iter &b, const iter &e, bool &v) -> bool {
|
||||
const auto [major, minor, type] = decode_type(b, e);
|
||||
if (major == 7) { // special
|
||||
|
@ -627,6 +636,7 @@ static auto match_bool(iter &b, const iter &e, bool &v) -> bool {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::match_value(iter &b, const iter &e, bool lit) -> bool {
|
||||
bool val{};
|
||||
|
@ -635,6 +645,7 @@ auto buffer::match_value(iter &b, const iter &e, bool lit) -> bool {
|
|||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
static auto match_string(iter &b, const iter &e, string_view &val) -> bool {
|
||||
const auto [major, minor, type] = decode_type(b, e);
|
||||
switch (major) {
|
||||
|
@ -649,6 +660,7 @@ static auto match_string(iter &b, const iter &e, string_view &val) -> bool {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::match_value(iter &b, const iter &e, const string_view lit)
|
||||
-> bool {
|
||||
|
@ -669,6 +681,7 @@ auto extract(type &t) -> buffer::extractor {
|
|||
return [&t](iter &b, const iter &e) { return match_type(b, e, t); };
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T> static auto extract_int(T &i) -> buffer::extractor {
|
||||
return [&i](iter &b, const iter &e) {
|
||||
signed long long int i_{};
|
||||
|
@ -681,6 +694,8 @@ template <typename T> static auto extract_int(T &i) -> buffer::extractor {
|
|||
return false;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// clang-format off
|
||||
auto extract(signed long long int &i) -> buffer::extractor { return extract_int(i); }
|
||||
auto extract(signed long int &i) -> buffer::extractor { return extract_int(i); }
|
||||
|
@ -692,6 +707,7 @@ auto extract(signed char &i) -> buffer::extractor { return extract_int(i); }
|
|||
auto extract(unsigned long long int &i) -> buffer::extractor {
|
||||
return [&i](iter &b, const iter &e) { return match_uint(b, e, i); };
|
||||
}
|
||||
namespace {
|
||||
template <typename T> static auto extract_uint(T &i) -> buffer::extractor {
|
||||
return [&i](iter &b, const iter &e) {
|
||||
unsigned long long int i_{};
|
||||
|
@ -704,6 +720,7 @@ template <typename T> static auto extract_uint(T &i) -> buffer::extractor {
|
|||
return false;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
// clang-format off
|
||||
auto extract(unsigned long int &i) -> buffer::extractor { return extract_uint(i); }
|
||||
auto extract(unsigned int &i) -> buffer::extractor { return extract_uint(i); }
|
||||
|
@ -748,6 +765,7 @@ auto buffer::match_value(iter &b, const iter &e, const extractor &ex) -> bool {
|
|||
return ex(b, e);
|
||||
}
|
||||
|
||||
namespace {
|
||||
static auto tohex(ostream &os, uint8_t v) -> ostream & {
|
||||
return os << hex << setfill('0') << setw(2) << static_cast<unsigned>(v);
|
||||
}
|
||||
|
@ -866,6 +884,7 @@ static auto to_json_(const iter &b_, const iter &e) -> string {
|
|||
}
|
||||
return ss.str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto buffer::to_json() const -> string {
|
||||
return to_json_(raw_cbegin(), raw_cend());
|
||||
|
@ -885,8 +904,8 @@ auto buffer::range::to_json(ostream &os) const -> void {
|
|||
extern "C" void cbor_to_json(cbor_buffer buf, cbor_to_json_callback cb) {
|
||||
auto cbor = cbor::buffer();
|
||||
const uint8_t *data = buf.base;
|
||||
std::copy(data, data + buf.len,
|
||||
back_inserter(cbor)); // NOLINT(*-pointer-arithmetic)
|
||||
std::copy(data, data + buf.len, // NOLINT(*-pointer-arithmetic)
|
||||
back_inserter(cbor));
|
||||
auto json = cbor.to_json();
|
||||
cb({json.data(), json.size()});
|
||||
}
|
||||
|
@ -909,11 +928,13 @@ auto buffer::value_accessor::type_() const -> type {
|
|||
return t;
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T> static auto get(iter b, const iter &e) -> T {
|
||||
T val;
|
||||
extract(val)(b, e);
|
||||
return val;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// clang-format off
|
||||
buffer::value_accessor::operator type() const { return get<type>(b, e); }
|
||||
|
|
|
@ -481,11 +481,11 @@ namespace unx {
|
|||
|
||||
struct socket_impl {
|
||||
explicit socket_impl(strand &strand)
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_}, socket_{
|
||||
*ctx->asio} {}
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_},
|
||||
socket_{*ctx->asio} {}
|
||||
explicit socket_impl(strand &strand, int fd)
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_}, socket_{*ctx->asio,
|
||||
fd} {}
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_},
|
||||
socket_{*ctx->asio, fd} {}
|
||||
auto bind(string_view path) -> error_code {
|
||||
error_code ec;
|
||||
ec = socket_.bind(path, ec);
|
||||
|
@ -615,8 +615,8 @@ namespace file_descriptor {
|
|||
|
||||
struct watcher_impl {
|
||||
explicit watcher_impl(strand &strand, int fd)
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_}, fd_{*ctx->asio,
|
||||
fd} {}
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_},
|
||||
fd_{*ctx->asio, fd} {}
|
||||
|
||||
void wait_read(watcher::handler h) {
|
||||
if (!read_in_progress_) {
|
||||
|
@ -680,8 +680,8 @@ struct file_stream_impl {
|
|||
explicit file_stream_impl(
|
||||
strand &strand,
|
||||
const asio::windows::stream_handle::native_handle_type &handle)
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_}, handle_{*ctx->asio,
|
||||
handle} {}
|
||||
: ctx{strand.ref->ctx}, strand_{strand.ref->strand_},
|
||||
handle_{*ctx->asio, handle} {}
|
||||
|
||||
void start_read(file_stream::read_handler h) {
|
||||
if (!read_in_progress_) {
|
||||
|
|
|
@ -91,7 +91,7 @@ struct hub_impl {
|
|||
set<string> msgs;
|
||||
for (const auto val : r)
|
||||
msgs.insert(string(val));
|
||||
subscribers_.emplace_back(move(from), [msgs](auto m) {
|
||||
subscribers_.emplace_back(move(from), [msgs](const auto &m) {
|
||||
string tag;
|
||||
return m(extract(tag), more) && (msgs.find(tag) != msgs.end());
|
||||
});
|
||||
|
|
161
src/instance.cpp
161
src/instance.cpp
|
@ -108,9 +108,11 @@ struct context_impl : context {
|
|||
};
|
||||
thread_local instance *current_instance{}; // NOLINT
|
||||
|
||||
namespace {
|
||||
auto impl(context &ctx) -> context_impl & {
|
||||
return *reinterpret_cast<context_impl *>(&ctx); // NOLINT
|
||||
}
|
||||
} // namespace
|
||||
|
||||
auto context::create() -> ref {
|
||||
return {new context_impl{executor::context::create()}, context_impl::destroy};
|
||||
|
@ -129,10 +131,12 @@ void context::on_last_exit(last_exit_handler h) {
|
|||
|
||||
namespace debug {
|
||||
|
||||
namespace {
|
||||
void register_instance(context_impl &ctx, const handle &h);
|
||||
void unregister_instance(context_impl &ctx, const string &name);
|
||||
auto get_name(context_impl &ctx, const string &name) -> handle;
|
||||
auto get_names(context_impl &ctx) -> buffer;
|
||||
} // namespace
|
||||
|
||||
} // namespace debug
|
||||
|
||||
|
@ -147,6 +151,7 @@ constexpr auto context_error = "call out of context";
|
|||
|
||||
auto handle_ref(handle &h) -> ref & { return h.ref_; }
|
||||
auto handle_ref(const handle &h) -> const ref & { return h.ref_; }
|
||||
namespace {
|
||||
auto make_handle(ref &&r) -> handle {
|
||||
handle h{};
|
||||
handle_ref(h) = move(r);
|
||||
|
@ -159,12 +164,13 @@ template <typename... Ts> auto exit_message(string_view e, Ts &&...parms) {
|
|||
return buffer(array("exit", e, forward<Ts>(parms)...));
|
||||
}
|
||||
|
||||
[[nodiscard]] auto exit() -> result { return to_error(exit_message("normal")); }
|
||||
|
||||
template <typename... Ts>
|
||||
[[nodiscard]] auto exit(std::string_view e, Ts &&...parms) -> result {
|
||||
return to_error(exit_message(e, std::forward<Ts>(parms)...));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
[[nodiscard]] auto exit() -> result { return to_error(exit_message("normal")); }
|
||||
|
||||
[[nodiscard]] auto exit(std::string_view e) -> result {
|
||||
return to_error(exit_message(e));
|
||||
|
@ -186,7 +192,9 @@ template <typename... Ts>
|
|||
return exit("UNEXPECTED_MESSAGE:" + b.to_json());
|
||||
}
|
||||
|
||||
namespace {
|
||||
auto deadsend(const buffer &m, const ref &from) -> result;
|
||||
} // namespace
|
||||
const auto exit_normal_msg = array("exit", "normal");
|
||||
const auto exit_noreceive_msg = array("exit", "noreceive");
|
||||
const auto exit_nosyncreceive_msg = array("exit", "nosyncreceive");
|
||||
|
@ -221,7 +229,7 @@ struct instance : std::enable_shared_from_this<instance> {
|
|||
env_(move(env)) {
|
||||
if (eh)
|
||||
exit_handlers_.emplace_front(eh);
|
||||
receiver_ = [this, b{move(b)}](auto, auto) {
|
||||
receiver_ = [this, b{move(b)}](const auto &, const auto &) {
|
||||
this->do_trace(channel::lifetime, "init");
|
||||
receiver b_;
|
||||
b_.swap(receiver_);
|
||||
|
@ -245,8 +253,8 @@ struct instance : std::enable_shared_from_this<instance> {
|
|||
}
|
||||
|
||||
static auto spawn(context_impl &ctx, behaviour b, exit_handler eh,
|
||||
string_view name, const ref &link,
|
||||
env_t env) -> expected<handle, error> {
|
||||
string_view name, const ref &link, env_t env)
|
||||
-> expected<handle, error> {
|
||||
auto pimpl = make_shared<instance>(ctx, move(b), move(eh), name, move(env));
|
||||
pimpl->lifetime_ = pimpl;
|
||||
handle_ref(pimpl->self_ref_) = pimpl->lifetime_;
|
||||
|
@ -316,7 +324,7 @@ struct instance : std::enable_shared_from_this<instance> {
|
|||
auto trace_enabled(channel c) { return env_.enabled(c); }
|
||||
|
||||
template <class F> void submit_msg_task(F f) {
|
||||
strand_.post(msg_task_T<F>(f));
|
||||
strand_.post(msg_task_T<F>(move(f)));
|
||||
}
|
||||
|
||||
[[nodiscard]] auto dispatch_sync_raw(buffer m) -> result {
|
||||
|
@ -447,8 +455,8 @@ struct instance : std::enable_shared_from_this<instance> {
|
|||
return send_raw(array(std::forward<Ts>(parms)...));
|
||||
}
|
||||
|
||||
auto spawn_link(behaviour b, string_view name,
|
||||
env_t env) -> expected<handle, error> {
|
||||
auto spawn_link(behaviour b, string_view name, env_t env)
|
||||
-> expected<handle, error> {
|
||||
auto ret = instance::spawn(ctx, move(b), exit_handler{}, name, lifetime_,
|
||||
move(env));
|
||||
if (not ret)
|
||||
|
@ -497,6 +505,7 @@ struct instance : std::enable_shared_from_this<instance> {
|
|||
env_t env_;
|
||||
};
|
||||
|
||||
namespace {
|
||||
auto deadsend(const buffer &m, const ref &from) -> result {
|
||||
if (current_instance and !current_instance->is_in_shutdown() and
|
||||
!m("exit", type::more)) {
|
||||
|
@ -505,6 +514,7 @@ auto deadsend(const buffer &m, const ref &from) -> result {
|
|||
}
|
||||
return ok();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
[[nodiscard]] auto handle::send_raw(buffer m) const -> result {
|
||||
if (auto p = ref_.lock()) {
|
||||
|
@ -517,6 +527,7 @@ auto operator==(const handle &a, const handle &b) -> bool {
|
|||
return a.ref_.lock() == b.ref_.lock();
|
||||
}
|
||||
|
||||
namespace {
|
||||
auto ref_m(const void *p, string name) -> buffer {
|
||||
stringstream ss;
|
||||
ss << p;
|
||||
|
@ -530,7 +541,9 @@ auto ref_m(const ref &r) -> buffer {
|
|||
return ref_m(p.get(), p->name());
|
||||
return ref_m(nullptr, "none");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
auto private_call() -> instance & {
|
||||
if (!current_instance)
|
||||
throw domain_error{context_error};
|
||||
|
@ -544,6 +557,7 @@ auto private_call_noexcept() noexcept -> instance * {
|
|||
}
|
||||
|
||||
auto trace_enabled(channel c) { return private_call().env_.enabled(c); }
|
||||
} // namespace
|
||||
|
||||
auto spawn(behaviour b, string_view name) -> expected<handle, error> {
|
||||
auto &p = private_call();
|
||||
|
@ -551,15 +565,15 @@ auto spawn(behaviour b, string_view name) -> expected<handle, error> {
|
|||
p.env_);
|
||||
}
|
||||
|
||||
auto spawn(behaviour b, string_view name,
|
||||
env_t env) -> expected<handle, error> {
|
||||
auto spawn(behaviour b, string_view name, env_t env)
|
||||
-> expected<handle, error> {
|
||||
auto &p = private_call();
|
||||
return instance::spawn(p.ctx, move(b), exit_handler{}, name, thespian::ref{},
|
||||
move(env));
|
||||
}
|
||||
|
||||
auto context::spawn(behaviour b, string_view name,
|
||||
env_t env) -> expected<handle, error> {
|
||||
auto context::spawn(behaviour b, string_view name, env_t env)
|
||||
-> expected<handle, error> {
|
||||
return instance::spawn(impl(*this), move(b), exit_handler{}, name,
|
||||
thespian::ref{}, move(env));
|
||||
}
|
||||
|
@ -577,8 +591,8 @@ auto context::spawn_link(behaviour b, exit_handler eh, string_view name,
|
|||
move(env));
|
||||
}
|
||||
|
||||
auto context::spawn_link(behaviour b, exit_handler eh,
|
||||
string_view name) -> expected<handle, error> {
|
||||
auto context::spawn_link(behaviour b, exit_handler eh, string_view name)
|
||||
-> expected<handle, error> {
|
||||
return spawn_link(move(b), move(eh), name, env_t{});
|
||||
}
|
||||
|
||||
|
@ -588,8 +602,8 @@ auto self_ref() -> handle & { return private_call().self_ref_; }
|
|||
auto spawn_link(behaviour b, string_view name) -> expected<handle, error> {
|
||||
return private_call().spawn_link(move(b), name);
|
||||
}
|
||||
auto spawn_link(behaviour b, string_view name,
|
||||
env_t env) -> expected<handle, error> {
|
||||
auto spawn_link(behaviour b, string_view name, env_t env)
|
||||
-> expected<handle, error> {
|
||||
return private_call().spawn_link(move(b), name, move(env));
|
||||
}
|
||||
auto send_raw(buffer m) -> result { return private_call().send_raw(move(m)); }
|
||||
|
@ -603,12 +617,6 @@ auto on_trace(trace_handler h) -> trace_handler {
|
|||
return private_call().env_.on_trace(move(h));
|
||||
}
|
||||
|
||||
auto get_strand(const handle &h) -> executor::strand * {
|
||||
if (auto p = handle_ref(h).lock())
|
||||
return &p->strand_;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct signal_impl {
|
||||
signal_impl(const signal_impl &) = delete;
|
||||
signal_impl(signal_impl &&) = delete;
|
||||
|
@ -827,8 +835,8 @@ struct udp_impl {
|
|||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] auto sendto(string_view data, in6_addr ip,
|
||||
port_t port) -> size_t {
|
||||
[[nodiscard]] auto sendto(string_view data, in6_addr ip, port_t port)
|
||||
-> size_t {
|
||||
if (is_trace_enabled_)
|
||||
owner_.env_.trace(
|
||||
array("udp", tag_, "sendto", data, executor::to_string(ip), port));
|
||||
|
@ -868,8 +876,8 @@ auto udp::create(string tag) -> udp {
|
|||
struct file_descriptor_impl {
|
||||
file_descriptor_impl(const file_descriptor_impl &) = delete;
|
||||
file_descriptor_impl(file_descriptor_impl &&) = delete;
|
||||
auto
|
||||
operator=(const file_descriptor_impl &) -> file_descriptor_impl & = delete;
|
||||
auto operator=(const file_descriptor_impl &)
|
||||
-> file_descriptor_impl & = delete;
|
||||
auto operator=(file_descriptor_impl &&) -> file_descriptor_impl & = delete;
|
||||
|
||||
file_descriptor_impl(string_view tag, int fd)
|
||||
|
@ -1263,16 +1271,7 @@ void connector::cancel() { ref->cancel(); }
|
|||
|
||||
namespace unx {
|
||||
|
||||
auto unx_mode_string(mode m) -> const char * {
|
||||
switch (m) {
|
||||
case mode::file:
|
||||
return "file";
|
||||
case mode::abstract:
|
||||
return "abstract";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
namespace {
|
||||
auto unx_mode_path(mode m, string_view path) -> string {
|
||||
switch (m) {
|
||||
case mode::file:
|
||||
|
@ -1285,6 +1284,7 @@ auto unx_mode_path(mode m, string_view path) -> string {
|
|||
}
|
||||
return "unknown";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
struct acceptor_impl {
|
||||
explicit acceptor_impl(string_view tag)
|
||||
|
@ -1498,16 +1498,16 @@ struct connection {
|
|||
return ok();
|
||||
}
|
||||
|
||||
static auto start(int fd, const handle &owner,
|
||||
const char *tag) -> expected<handle, error> {
|
||||
static auto start(int fd, const handle &owner, const char *tag)
|
||||
-> expected<handle, error> {
|
||||
return spawn(
|
||||
[fd, owner, tag]() {
|
||||
link(owner);
|
||||
trap(true);
|
||||
::thespian::receive(
|
||||
[p{make_shared<connection>(fd, owner, tag)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<connection>(fd, owner, tag)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
|
@ -1516,9 +1516,8 @@ struct connection {
|
|||
static void attach(int fd, handle owner, const char *tag) {
|
||||
private_call().name_ = tag;
|
||||
::thespian::receive(
|
||||
[p{make_shared<connection>(fd, owner, tag)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
[p{make_shared<connection>(fd, owner, tag)}](
|
||||
const auto &from, const auto &m) { return p->receive(from, m); });
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1579,11 +1578,11 @@ struct connector {
|
|||
return spawn_link(
|
||||
[=]() {
|
||||
trap(true);
|
||||
::thespian::receive(
|
||||
[p{make_shared<connector>(ip, port, owner, retry_time,
|
||||
retry_count)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<connector>(
|
||||
ip, port, owner, retry_time, retry_count)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
|
@ -1633,10 +1632,10 @@ struct acceptor {
|
|||
return spawn_link(
|
||||
[=]() {
|
||||
trap(true);
|
||||
::thespian::receive(
|
||||
[p{make_shared<acceptor>(ip, port, owner)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<acceptor>(ip, port, owner)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
|
@ -1714,11 +1713,11 @@ struct connector {
|
|||
return spawn_link(
|
||||
[path{string(path)}, m_, owner, retry_time, retry_count]() {
|
||||
trap(true);
|
||||
::thespian::receive(
|
||||
[p{make_shared<connector>(path, m_, owner, retry_time,
|
||||
retry_count)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<connector>(
|
||||
path, m_, owner, retry_time, retry_count)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
|
@ -1770,10 +1769,10 @@ struct acceptor {
|
|||
return spawn_link(
|
||||
[path{string(path)}, m_, owner]() {
|
||||
trap(true);
|
||||
::thespian::receive(
|
||||
[p{make_shared<acceptor>(path, m_, owner)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<acceptor>(path, m_, owner)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
|
@ -1794,14 +1793,19 @@ auto connect(string_view path, mode m, milliseconds retry_time,
|
|||
|
||||
namespace debug {
|
||||
|
||||
namespace {
|
||||
void enable(context_impl &ctx) {
|
||||
ctx.debug_enabled.fetch_add(1, memory_order_relaxed);
|
||||
}
|
||||
} // namespace
|
||||
void enable(context &ctx) { enable(impl(ctx)); }
|
||||
namespace {
|
||||
auto isenabled(context_impl &ctx) -> bool {
|
||||
return ctx.debug_enabled.load(memory_order_relaxed) > 0;
|
||||
}
|
||||
} // namespace
|
||||
auto isenabled(context &ctx) -> bool { return isenabled(impl(ctx)); }
|
||||
namespace {
|
||||
void disable(context_impl &ctx) {
|
||||
auto prev = ctx.debug_enabled.fetch_sub(1, memory_order_relaxed);
|
||||
if (prev == 1) {
|
||||
|
@ -1809,8 +1813,10 @@ void disable(context_impl &ctx) {
|
|||
ctx.registry.clear();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
void disable(context &ctx) { disable(impl(ctx)); }
|
||||
|
||||
namespace {
|
||||
void register_instance(context_impl &ctx, const handle &h) {
|
||||
if (not isenabled(ctx))
|
||||
return;
|
||||
|
@ -1856,6 +1862,7 @@ auto get_names(context_impl &ctx) -> buffer {
|
|||
}
|
||||
return b;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace tcp {
|
||||
|
||||
|
@ -1994,14 +2001,14 @@ struct connection {
|
|||
return ok();
|
||||
}
|
||||
|
||||
static auto start(context_impl &ctx, int fd,
|
||||
const string &prompt) -> expected<handle, error> {
|
||||
static auto start(context_impl &ctx, int fd, const string &prompt)
|
||||
-> expected<handle, error> {
|
||||
return spawn(
|
||||
[&ctx, fd, prompt]() {
|
||||
::thespian::receive(
|
||||
[p{make_shared<connection>(ctx, fd, prompt)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<connection>(ctx, fd, prompt)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
|
@ -2051,22 +2058,22 @@ struct acceptor {
|
|||
return ok();
|
||||
}
|
||||
|
||||
static auto start(context_impl &ctx, port_t port,
|
||||
const string &prompt) -> expected<handle, error> {
|
||||
static auto start(context_impl &ctx, port_t port, const string &prompt)
|
||||
-> expected<handle, error> {
|
||||
return spawn(
|
||||
[&ctx, port, prompt]() {
|
||||
::thespian::receive(
|
||||
[p{make_shared<acceptor>(ctx, port, prompt)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::thespian::receive([p{make_shared<acceptor>(ctx, port, prompt)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
tag);
|
||||
}
|
||||
};
|
||||
|
||||
auto create(context &ctx, port_t port,
|
||||
const string &prompt) -> expected<handle, error> {
|
||||
auto create(context &ctx, port_t port, const string &prompt)
|
||||
-> expected<handle, error> {
|
||||
return acceptor::start(impl(ctx), port, prompt);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,7 @@ template <typename T, typename Q> struct trace_file {
|
|||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
auto to_mermaid(ostream &s, const buffer &m) -> void {
|
||||
string_view from;
|
||||
string_view typ;
|
||||
|
@ -124,6 +125,7 @@ auto to_mermaid(ostream &s, const buffer &m) -> void {
|
|||
s << " Note right of " << from << ": EXIT " << msg << '\n';
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
static const auto cbor_cr = array("\n");
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <thespian/instance.hpp>
|
||||
#include <thespian/trace.hpp>
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
using cbor::A;
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <memory>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <winsock2.h>
|
||||
#include <in6addr.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2ipdef.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
@ -60,9 +60,10 @@ struct debuggee {
|
|||
static auto start() -> expected<handle, error> {
|
||||
return spawn_link(
|
||||
[=]() {
|
||||
::receive([p{make_shared<debuggee>()}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
});
|
||||
::receive(
|
||||
[p{make_shared<debuggee>()}](const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
"debuggee");
|
||||
|
@ -188,9 +189,9 @@ auto debug(context &ctx, bool &result, env_t env_) -> ::result {
|
|||
ret2 = debuggee.send("ping");
|
||||
if (not ret2)
|
||||
return ret2;
|
||||
receive([p{make_shared<controller>(debug_tcp, debuggee)}](auto from,
|
||||
auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
receive([p{make_shared<controller>(debug_tcp, debuggee)}](
|
||||
const auto &from, const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
#include <utility>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <winsock2.h>
|
||||
#include <in6addr.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2ipdef.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
@ -86,8 +86,9 @@ auto endpoint_tcp(context &ctx, bool &result, env_t env_) -> ::result {
|
|||
if (not ret)
|
||||
return ret;
|
||||
|
||||
receive([p{make_shared<controller>(ep_listen)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
receive([p{make_shared<controller>(ep_listen)}](const auto &from,
|
||||
const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
|
|
|
@ -91,8 +91,9 @@ auto endpoint_unx(context &ctx, bool &result, env_t env_) -> ::result {
|
|||
[path]() {
|
||||
link(env().proc("log"));
|
||||
handle ep_listen = listen(path).value();
|
||||
receive([p{make_shared<controller>(ep_listen)}](auto from, auto m) {
|
||||
return p->receive(move(from), move(m));
|
||||
receive([p{make_shared<controller>(ep_listen)}](const auto &from,
|
||||
const auto &m) {
|
||||
return p->receive(from, m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
|
|
|
@ -33,7 +33,7 @@ auto sub_plain(const hub &h, const handle &controller, string name) -> result {
|
|||
ret = controller.send("ready", name);
|
||||
if (not ret)
|
||||
return ret;
|
||||
receive([=](auto /*from*/, auto m) {
|
||||
receive([=](const auto & /*from*/, const auto &m) {
|
||||
string_view cmd;
|
||||
check(m("parmA", "parmB", "parmC", extract(cmd)));
|
||||
check(cmd == "continue" || cmd == "done");
|
||||
|
@ -50,13 +50,13 @@ auto sub_plain(const hub &h, const handle &controller, string name) -> result {
|
|||
auto sub_filtered(const hub &h, const handle &controller, string name)
|
||||
-> result {
|
||||
auto ret = h.subscribe(
|
||||
[](auto m) { return m(type::any, type::any, type::any, "done"); });
|
||||
[](const auto &m) { return m(type::any, type::any, type::any, "done"); });
|
||||
if (not ret)
|
||||
return ret;
|
||||
ret = controller.send("ready", name);
|
||||
if (not ret)
|
||||
return ret;
|
||||
receive([=](auto /*from*/, auto m) {
|
||||
receive([=](const auto & /*from*/, const auto &m) {
|
||||
check(m("parmA", "parmB", "parmC", "done"));
|
||||
auto ret = controller.send("done", name);
|
||||
if (not ret)
|
||||
|
@ -66,7 +66,7 @@ auto sub_filtered(const hub &h, const handle &controller, string name)
|
|||
return ok();
|
||||
}
|
||||
|
||||
map<string, auto(*)(const hub &, const handle &, string)->result>
|
||||
map<string, auto (*)(const hub &, const handle &, string)->result>
|
||||
subscription_defs // NOLINT
|
||||
= {
|
||||
{"sub_plain", sub_plain},
|
||||
|
@ -95,7 +95,7 @@ auto controller() -> result {
|
|||
submap not_ready = subs;
|
||||
submap done = subs;
|
||||
|
||||
receive([=](auto, auto m) mutable {
|
||||
receive([=](const auto &, const auto &m) mutable {
|
||||
string name;
|
||||
if (m("ready", extract(name))) {
|
||||
not_ready.erase(name);
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#if !defined(_WIN32)
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <in6addr.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2ipdef.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
@ -80,7 +80,9 @@ struct client_connection {
|
|||
[fd, connector]() {
|
||||
::thespian::receive(
|
||||
[p{make_shared<client_connection>(fd, connector)}](
|
||||
auto /*from*/, auto m) { return p->receive(move(m)); });
|
||||
const auto & /*from*/, const auto &m) {
|
||||
return p->receive(m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
"client_connection");
|
||||
|
@ -111,9 +113,8 @@ struct client {
|
|||
|
||||
static auto init(handle server, port_t server_port) -> result {
|
||||
::thespian::receive(
|
||||
[p{make_shared<client>(server, server_port)}](auto /*from*/, auto m) {
|
||||
return p->receive(move(m));
|
||||
});
|
||||
[p{make_shared<client>(server, server_port)}](
|
||||
const auto & /*from*/, const auto &m) { return p->receive(m); });
|
||||
return ok();
|
||||
}
|
||||
};
|
||||
|
@ -155,9 +156,10 @@ struct server_connection {
|
|||
[[nodiscard]] static auto init(int fd, const handle &server) {
|
||||
return spawn_link(
|
||||
[fd, server]() {
|
||||
::thespian::receive(
|
||||
[p{make_shared<server_connection>(fd, server)}](
|
||||
auto /*from*/, auto m) { return p->receive(move(m)); });
|
||||
::thespian::receive([p{make_shared<server_connection>(fd, server)}](
|
||||
const auto & /*from*/, const auto &m) {
|
||||
return p->receive(m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
"server_connection");
|
||||
|
@ -210,7 +212,7 @@ struct server {
|
|||
if (not ret)
|
||||
return to_result(ret);
|
||||
thespian::receive(
|
||||
[p](auto /*from*/, auto m) { return p->receive(move(m)); });
|
||||
[p](const auto & /*from*/, const auto &m) { return p->receive(m); });
|
||||
return ok();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#if !defined(_WIN32)
|
||||
#include <netinet/in.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <in6addr.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2ipdef.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
@ -116,8 +116,9 @@ auto ip_udp_echo(context &ctx, bool &result, env_t env_) -> ::result {
|
|||
return to_result(ctx.spawn_link(
|
||||
[=]() {
|
||||
link(env().proc("log"));
|
||||
receive([p{make_shared<controller>()}](auto /*from*/, auto m) {
|
||||
return p->receive(move(m));
|
||||
receive([p{make_shared<controller>()}](const auto & /*from*/,
|
||||
const auto &m) {
|
||||
return p->receive(m);
|
||||
});
|
||||
return ok();
|
||||
},
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using cbor::buffer;
|
||||
using std::move;
|
||||
|
@ -64,7 +63,9 @@ auto initA() {
|
|||
}
|
||||
};
|
||||
shared_ptr<state_t> state{new state_t};
|
||||
receive([state](auto, auto m) mutable { return state->receive(m); });
|
||||
receive([state](const auto &, const auto &m) mutable {
|
||||
return state->receive(m);
|
||||
});
|
||||
return ok();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ using clk = std::chrono::system_clock;
|
|||
|
||||
namespace {
|
||||
|
||||
enum class tag {
|
||||
enum class tag : uint8_t {
|
||||
ready = 1,
|
||||
done = 2,
|
||||
};
|
||||
|
|
|
@ -28,8 +28,8 @@ auto slave(const handle &last, int n) -> result {
|
|||
if (n)
|
||||
next = spawn_link([=]() { return slave(last, n - 1); }, "slave").value();
|
||||
|
||||
receive([n, next, last](auto, auto m) {
|
||||
return n ? next.send_raw(move(m)) : last.send_raw(move(m));
|
||||
receive([n, next, last](const auto &, const auto &m) {
|
||||
return n ? next.send_raw(m) : last.send_raw(m);
|
||||
});
|
||||
return ok();
|
||||
}
|
||||
|
@ -41,11 +41,11 @@ auto controller(const int slaves) -> result {
|
|||
auto ret = spawn_link([=]() { return slave(last, slaves); }, "slave");
|
||||
if (not ret)
|
||||
return to_result(ret);
|
||||
handle first = ret.value();
|
||||
const handle &first = ret.value();
|
||||
auto ret2 = first.send("forward");
|
||||
if (not ret2)
|
||||
return ret2;
|
||||
receive([loop, first, verbose](auto, auto m) mutable {
|
||||
receive([loop, first, verbose](const auto &, const auto &m) mutable {
|
||||
if (loop) {
|
||||
if (verbose)
|
||||
auto _ = env().proc("log").send(loop);
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "thespian/env.hpp"
|
||||
#include <thespian/instance.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using cbor::extract;
|
||||
using std::move;
|
||||
using thespian::context;
|
||||
|
@ -21,7 +19,7 @@ using thespian::unexpected;
|
|||
namespace {
|
||||
|
||||
auto slave(const int slaves, int spawned) -> result {
|
||||
receive([slaves, spawned](auto, auto m) mutable {
|
||||
receive([slaves, spawned](const auto &, const auto &m) mutable {
|
||||
int n{0};
|
||||
if (!m(extract(n)))
|
||||
return unexpected(m);
|
||||
|
@ -50,7 +48,7 @@ auto controller(const int slaves) -> result {
|
|||
auto ret2 = ret.value().send(slaves - 1);
|
||||
if (not ret2)
|
||||
return ret2;
|
||||
receive([](auto, auto) { return exit(); });
|
||||
receive([](const auto &, const auto &) { return exit(); });
|
||||
return ok();
|
||||
}
|
||||
} // namespace
|
||||
|
|
|
@ -34,7 +34,7 @@ auto initE() {
|
|||
auto ret = env().proc("A").send("shutdown");
|
||||
if (not ret)
|
||||
return ret;
|
||||
receive([](auto, auto) { return ok(); });
|
||||
receive([](const auto &, const auto &) { return ok(); });
|
||||
return ok();
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ auto initD() {
|
|||
auto ret = spawn(initE, "E");
|
||||
if (not ret)
|
||||
return to_result(ret);
|
||||
receive([](auto, auto m) {
|
||||
receive([](const auto &, const auto &m) {
|
||||
if (m("die"))
|
||||
return exit("died");
|
||||
return unexpected(m);
|
||||
|
@ -56,7 +56,7 @@ auto initC() {
|
|||
if (not ret)
|
||||
return to_result(ret);
|
||||
trap(true);
|
||||
receive([](auto /*from*/, auto m) {
|
||||
receive([](const auto & /*from*/, const auto &m) {
|
||||
if (m("exit", "died"))
|
||||
return exit();
|
||||
return unexpected(m);
|
||||
|
@ -66,7 +66,7 @@ auto initC() {
|
|||
|
||||
auto initB() {
|
||||
env().str("initBsays") = "noyoudont";
|
||||
receive([](auto from, auto m) {
|
||||
receive([](const auto &from, const auto &m) {
|
||||
if (m("shutdown")) {
|
||||
auto ret = from.send("done");
|
||||
if (not ret)
|
||||
|
@ -87,7 +87,7 @@ auto initA() {
|
|||
if (not ret)
|
||||
return ret;
|
||||
spawn_link(initC, "C").value();
|
||||
receive([i{0}](auto, auto m) mutable {
|
||||
receive([i{0}](const auto &, const auto &m) mutable {
|
||||
if (m("shutdown") || m("done"))
|
||||
++i;
|
||||
else
|
||||
|
|
|
@ -67,7 +67,7 @@ struct logger {
|
|||
[name, &trace_m, verbose]() {
|
||||
thespian::receive(
|
||||
[p{make_shared<logger>(name, trace_m, verbose)}](
|
||||
auto, auto m) { return p->receive(move(m)); });
|
||||
const auto &, const auto &m) { return p->receive(m); });
|
||||
return ok();
|
||||
},
|
||||
string("logger_") + name, move(env))
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
int runtestcase(const char *name); // NOLINT
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <thespian/env.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string_view>
|
||||
|
||||
constexpr auto check(bool expression) -> void {
|
||||
if (!expression)
|
||||
|
@ -12,7 +11,7 @@ constexpr auto check(bool expression) -> void {
|
|||
}
|
||||
|
||||
using testcase = auto(thespian::context &ctx, bool &result, thespian::env_t env)
|
||||
-> thespian::result;
|
||||
-> thespian::result;
|
||||
|
||||
testcase cbor_match;
|
||||
testcase debug;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using cbor::array;
|
||||
using cbor::buffer;
|
||||
|
@ -47,7 +46,9 @@ auto initA() -> result {
|
|||
}
|
||||
};
|
||||
shared_ptr<state_t> state{new state_t};
|
||||
receive([state](auto, auto m) mutable { return state->receive(m); });
|
||||
receive([state](const auto &, const auto &m) mutable {
|
||||
return state->receive(m);
|
||||
});
|
||||
return ok();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue