diff --git a/include/villas/path.h b/include/villas/path.h index 578397c91..e3684f304 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -35,12 +35,13 @@ #include #include #include -#include #include #include #include #ifdef __cplusplus + #include + extern "C" { #endif @@ -86,11 +87,13 @@ struct path { char *_name; /**< Singleton: A string which is used to print this path to screen. */ - struct bitset mask; /**< A mask of path_sources which are enabled for poll(). */ - struct bitset received; /**< A mask of path_sources for which we already received samples. */ - pthread_t tid; /**< The thread id for this path. */ json_t *cfg; /**< A JSON object containing the configuration of the path. */ + +#ifdef __cplusplus + std::bitset<128> mask; /**< A mask of path_sources which are enabled for poll(). */ + std::bitset<128> received; /**< A mask of path_sources for which we already received samples. */ +#endif }; /** Initialize internal data structures. */ diff --git a/lib/hooks/average.cpp b/lib/hooks/average.cpp index 24a2f28cc..2521e5704 100644 --- a/lib/hooks/average.cpp +++ b/lib/hooks/average.cpp @@ -24,13 +24,14 @@ * @{ */ +#include + #include #include #include #include #include -#include namespace villas { namespace node { @@ -40,7 +41,7 @@ class AverageHook : public Hook { protected: int offset; - bitset mask; + std::bitset<128> mask; vlist signal_names; public: @@ -53,20 +54,12 @@ public: if (ret) throw RuntimeError("Failed to intialize list"); - ret = bitset_init(&mask, 128); - if (ret) - throw RuntimeError("Failed to intialize bitset"); - - bitset_clear_all(&mask); - state = STATE_INITIALIZED; } virtual ~AverageHook() { vlist_destroy(&signal_names, nullptr, true); - - bitset_destroy(&mask); } virtual void prepare() @@ -84,10 +77,10 @@ public: if (index < 0) throw RuntimeError("Failed to find signal {}", signal_name); - bitset_set(&mask, index); + mask.set(index); } - if (!bitset_get_value(&mask)) + if (mask.none()) throw RuntimeError("Invalid signal mask"); /* Add averaged signal */ @@ -130,7 +123,7 @@ public: break; case JSON_INTEGER: - bitset_set(&mask, json_integer_value(json_signal)); + mask.set(json_integer_value(json_signal)); break; default: @@ -149,7 +142,7 @@ public: assert(state == STATE_STARTED); for (unsigned k = 0; k < smp->length; k++) { - if (!bitset_test(&mask, k)) + if (!mask.test(k)) continue; switch (sample_format(smp, k)) { diff --git a/lib/path.cpp b/lib/path.cpp index 5373db3f8..db8a7bd49 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -218,8 +218,8 @@ int path_prepare(struct path *p) return ret; } - bitset_init(&p->received, vlist_length(&p->sources)); - bitset_init(&p->mask, vlist_length(&p->sources)); + new (&p->received) std::bitset<128>; + new (&p->mask) std::bitset<128>; /* Initialize sources */ for (size_t i = 0; i < vlist_length(&p->sources); i++) { @@ -230,7 +230,7 @@ int path_prepare(struct path *p) return ret; if (ps->masked) - bitset_set(&p->mask, i); + p->mask.set(i); ret = mapping_list_prepare(&ps->mappings); if (ret) @@ -535,7 +535,6 @@ int path_start(struct path *p) { int ret; const char *mode; - char *mask; assert(p->state == STATE_PREPARED); @@ -553,8 +552,6 @@ int path_start(struct path *p) break; } - mask = bitset_dump(&p->mask); - info("Starting path %s: #signals=%zu, #hooks=%zu, #sources=%zu, #destinations=%zu, mode=%s, poll=%s, mask=%s, rate=%.2f, enabled=%s, reversed=%s, queuelen=%d, original_sequence_no=%s", path_name(p), vlist_length(&p->signals), @@ -563,7 +560,7 @@ int path_start(struct path *p) vlist_length(&p->destinations), mode, p->poll ? "yes" : "no", - mask, + p->mask.to_string().c_str(), p->rate, path_is_enabled(p) ? "yes" : "no", path_is_reversed(p) ? "yes" : "no", @@ -571,8 +568,6 @@ int path_start(struct path *p) p->original_sequence_no ? "yes" : "no" ); - free(mask); - #ifdef WITH_HOOKS ret = hook_list_start(&p->hooks); if (ret) @@ -581,7 +576,7 @@ int path_start(struct path *p) p->last_sequence = 0; - bitset_clear_all(&p->received); + p->received.reset(); /* We initialize the intial sample */ p->last_sample = sample_alloc(&p->pool); diff --git a/lib/path_source.cpp b/lib/path_source.cpp index dae9a574a..e4ee715f6 100644 --- a/lib/path_source.cpp +++ b/lib/path_source.cpp @@ -21,7 +21,6 @@ *********************************************************************************/ #include -#include #include #include #include @@ -97,7 +96,7 @@ int path_source_read(struct path_source *ps, struct path *p, int i) else if (recv < allocated) warning("Partial read for path %s: read=%u, expected=%u", path_name(p), recv, allocated); - bitset_set(&p->received, i); + p->received.set(i); if (p->mode == PATH_MODE_ANY) { /* Mux all samples */ tomux_smps = read_smps; @@ -130,7 +129,7 @@ int path_source_read(struct path_source *ps, struct path *p, int i) sample_copy(p->last_sample, muxed_smps[tomux-1]); - debug(15, "Path %s received = %s", path_name(p), bitset_dump(&p->received)); + debug(15, "Path %s received = %s", path_name(p), p->received.to_string().c_str()); #ifdef WITH_HOOKS toenqueue = hook_list_process(&p->hooks, muxed_smps, tomux); @@ -143,14 +142,14 @@ int path_source_read(struct path_source *ps, struct path *p, int i) toenqueue = tomux; #endif - if (bitset_test(&p->mask, i)) { + if (p->mask.test(i)) { /* Check if we received an update from all nodes/ */ if ((p->mode == PATH_MODE_ANY) || - (p->mode == PATH_MODE_ALL && !bitset_cmp(&p->mask, &p->received))) { + (p->mode == PATH_MODE_ALL && p->mask == p->received)) { path_destination_enqueue(p, muxed_smps, toenqueue); - /* Reset bitset of updated nodes */ - bitset_clear_all(&p->received); + /* Reset mask of updated nodes */ + p->received.reset(); enqueued = toenqueue; }