From 037bfcb81e164349037a9db0dfa47d6cfba7c6ed Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 16 Jun 2020 02:35:34 +0200 Subject: [PATCH] fix initialization errors --- common | 2 +- lib/formats/csv.cpp | 14 +++----------- lib/formats/iotagent_ul.cpp | 6 +----- lib/formats/json.cpp | 6 +----- lib/formats/json_reserve.cpp | 6 +----- lib/formats/protobuf.cpp | 6 +----- lib/formats/raw.cpp | 6 +----- lib/formats/villas_binary.cpp | 12 ++---------- lib/formats/villas_human.cpp | 8 ++------ lib/hook.cpp | 2 -- lib/hooks/print.cpp | 2 -- lib/io.cpp | 5 ----- lib/node_direction.cpp | 3 --- lib/node_type.cpp | 4 ++-- lib/nodes/amqp.cpp | 6 +----- lib/nodes/comedi.cpp | 6 +----- lib/nodes/ethercat.cpp | 8 +------- lib/nodes/example.cpp | 6 +----- lib/nodes/exec.cpp | 31 ++++++++++++++++++++++++++----- lib/nodes/file.cpp | 6 +----- lib/nodes/iec61850_sv.cpp | 6 +----- lib/nodes/infiniband.cpp | 6 +----- lib/nodes/influxdb.cpp | 6 +----- lib/nodes/loopback.cpp | 6 +----- lib/nodes/mqtt.cpp | 6 +----- lib/nodes/nanomsg.cpp | 6 +----- lib/nodes/ngsi.cpp | 6 +----- lib/nodes/opal.cpp | 6 +----- lib/nodes/rtp.cpp | 6 +----- lib/nodes/shmem.cpp | 6 +----- lib/nodes/signal_generator.cpp | 6 +----- lib/nodes/socket.cpp | 6 +----- lib/nodes/stats.cpp | 6 +----- lib/nodes/test_rtt.cpp | 6 +----- lib/nodes/uldaq.cpp | 6 +----- lib/nodes/websocket.cpp | 8 ++------ lib/nodes/zeromq.cpp | 9 +-------- lib/path.cpp | 5 +---- lib/plugin.cpp | 2 +- lib/shmem.cpp | 2 -- lib/super_node.cpp | 8 -------- src/villas-convert.cpp | 1 - src/villas-hook.cpp | 3 --- src/villas-pipe.cpp | 5 ----- src/villas-signal.cpp | 7 ------- src/villas-test-cmp.cpp | 3 --- tests/unit/io.cpp | 14 +++++++------- tests/unit/mapping.cpp | 3 +-- tests/unit/pool.cpp | 2 +- tests/unit/queue.cpp | 6 +----- tests/unit/queue_signalled.cpp | 1 - 51 files changed, 76 insertions(+), 238 deletions(-) diff --git a/common b/common index fc20afe09..fe3413e12 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit fc20afe09c84a6127821d448155cfea7a59467a7 +Subproject commit fe3413e12bb9eec496283551dbfad147dc8bd8ec diff --git a/lib/formats/csv.cpp b/lib/formats/csv.cpp index 79f49444b..6b2c544f1 100644 --- a/lib/formats/csv.cpp +++ b/lib/formats/csv.cpp @@ -197,10 +197,7 @@ void csv_header(struct io *io, const struct sample *smp) static struct plugin p1; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - - p1.name = "tsv"; + p1.name = "tsv"; p1.description = "Tabulator-separated values"; p1.type = PluginType::FORMAT; p1.format.header = csv_header; @@ -215,15 +212,11 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p1); + vlist_remove_all(&plugins, &p1); } static struct plugin p2; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p2.name = "csv"; p2.description = "Comma-separated values"; p2.type = PluginType::FORMAT; @@ -239,6 +232,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p2); + vlist_remove_all(&plugins, &p2); } diff --git a/lib/formats/iotagent_ul.cpp b/lib/formats/iotagent_ul.cpp index 06fe3a7f9..548e8b1e8 100644 --- a/lib/formats/iotagent_ul.cpp +++ b/lib/formats/iotagent_ul.cpp @@ -60,9 +60,6 @@ int iotagent_ul_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, str static struct plugin p; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "iotagent_ul"; p.description = "FIWARE IotAgent UltraLight format"; p.type = PluginType::FORMAT; @@ -73,6 +70,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/formats/json.cpp b/lib/formats/json.cpp index 1cf84e799..b575cbeaf 100644 --- a/lib/formats/json.cpp +++ b/lib/formats/json.cpp @@ -362,9 +362,6 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err); static struct plugin p; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "json"; p.description = "Javascript Object Notation"; p.type = PluginType::FORMAT; @@ -380,6 +377,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/formats/json_reserve.cpp b/lib/formats/json_reserve.cpp index 3c980e1ac..3540f8c37 100644 --- a/lib/formats/json_reserve.cpp +++ b/lib/formats/json_reserve.cpp @@ -326,9 +326,6 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err); static struct plugin p; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "json.reserve"; p.description = "RESERVE JSON format"; p.type = PluginType::FORMAT; @@ -342,6 +339,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/formats/protobuf.cpp b/lib/formats/protobuf.cpp index 668a607b0..6fccd0787 100644 --- a/lib/formats/protobuf.cpp +++ b/lib/formats/protobuf.cpp @@ -227,9 +227,6 @@ int protobuf_sscan(struct io *io, const char *buf, size_t len, size_t *rbytes, s static struct plugin p; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "protobuf"; p.description = "Google Protobuf"; p.type = PluginType::FORMAT; @@ -242,7 +239,6 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/formats/raw.cpp b/lib/formats/raw.cpp index 3497ef989..79898f869 100644 --- a/lib/formats/raw.cpp +++ b/lib/formats/raw.cpp @@ -414,9 +414,6 @@ int raw_sscan(struct io *io, const char *buf, size_t len, size_t *rbytes, struct #define REGISTER_FORMAT_RAW(i, n, d, f) \ static struct plugin i; \ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { \ - if (plugins.state == State::DESTROYED) \ - vlist_init(&plugins); \ - \ i.name = n; \ i.description = d; \ i.type = PluginType::FORMAT; \ @@ -429,8 +426,7 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { \ } \ \ __attribute__((destructor(110))) static void UNIQUE(__dtor)() { \ - if (plugins.state != State::DESTROYED) \ - vlist_remove_all(&plugins, &i); \ + vlist_remove_all(&plugins, &i); \ } /* Feel free to add additional format identifiers here to suit your needs */ REGISTER_FORMAT_RAW(p_8, "raw.8", "Raw 8 bit", RAW_BITS_8) diff --git a/lib/formats/villas_binary.cpp b/lib/formats/villas_binary.cpp index 82dff3210..c6d6ae44a 100644 --- a/lib/formats/villas_binary.cpp +++ b/lib/formats/villas_binary.cpp @@ -121,9 +121,6 @@ int villas_binary_sscan(struct io *io, const char *buf, size_t len, size_t *rbyt static struct plugin p1; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p1.name = "villas.binary"; p1.description = "VILLAS binary network format"; p1.type = PluginType::FORMAT; @@ -137,17 +134,13 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p1); + vlist_remove_all(&plugins, &p1); } /** The WebSocket node-type usually uses little endian byte order intead of network byte order */ static struct plugin p2; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p2.name = "villas.web"; p2.description = "VILLAS binary network format for WebSockets"; p2.type = PluginType::FORMAT; @@ -161,6 +154,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p2); + vlist_remove_all(&plugins, &p2); } diff --git a/lib/formats/villas_human.cpp b/lib/formats/villas_human.cpp index d452e1013..466ccd84f 100644 --- a/lib/formats/villas_human.cpp +++ b/lib/formats/villas_human.cpp @@ -225,10 +225,7 @@ void villas_human_header(struct io *io, const struct sample *smp) static struct plugin p; __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - - p.name = "villas.human"; + p.name = "villas.human"; p.description = "VILLAS human readable format"; p.type = PluginType::FORMAT; p.format.header = villas_human_header; @@ -243,6 +240,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/hook.cpp b/lib/hook.cpp index 3bba84898..b7629c6ba 100644 --- a/lib/hook.cpp +++ b/lib/hook.cpp @@ -50,8 +50,6 @@ Hook::Hook(struct vpath *p, struct node *n, int fl, int prio, bool en) : logger = logging.get("hook"); - signals.state = State::DESTROYED; - ret = signal_list_init(&signals); if (ret) throw RuntimeError("Failed to initialize signal list"); diff --git a/lib/hooks/print.cpp b/lib/hooks/print.cpp index 192ab5f1f..c4d3e0247 100644 --- a/lib/hooks/print.cpp +++ b/lib/hooks/print.cpp @@ -50,8 +50,6 @@ public: prefix(nullptr), uri(nullptr) { - io.state = State::DESTROYED; - format = format_type_lookup("villas.human"); } diff --git a/lib/io.cpp b/lib/io.cpp index 031920c6f..887719f0a 100644 --- a/lib/io.cpp +++ b/lib/io.cpp @@ -117,7 +117,6 @@ int io_init2(struct io *io, const struct format_type *fmt, const char *dt, int f struct vlist *signals; signals = new struct vlist; - signals->state = State::DESTROYED; ret = vlist_init(signals); if (ret) @@ -152,15 +151,11 @@ int io_destroy(struct io *io) return ret; } - io->state = State::DESTROYED; - return 0; } int io_check(struct io *io) { - assert(io->state != State::DESTROYED); - io->state = State::CHECKED; return 0; diff --git a/lib/node_direction.cpp b/lib/node_direction.cpp index 59088fc32..e777c5852 100644 --- a/lib/node_direction.cpp +++ b/lib/node_direction.cpp @@ -56,9 +56,6 @@ int node_direction_init(struct node_direction *nd, enum NodeDir dir, struct node nd->vectorize = 1; nd->builtin = 1; - nd->hooks.state = State::DESTROYED; - nd->signals.state = State::DESTROYED; - #ifdef WITH_HOOKS ret = hook_list_init(&nd->hooks); if (ret) diff --git a/lib/node_type.cpp b/lib/node_type.cpp index 804f41888..c730ad31d 100644 --- a/lib/node_type.cpp +++ b/lib/node_type.cpp @@ -33,7 +33,7 @@ int node_type_start(struct node_type *vt, villas::node::SuperNode *sn) { int ret; - if (vt->state != State::DESTROYED) + if (vt->state == State::STARTED) return 0; info("Initializing " CLR_YEL("%s") " node type which is used by %zu nodes", node_type_name(vt), vlist_length(&vt->instances)); @@ -56,7 +56,7 @@ int node_type_stop(struct node_type *vt) ret = vt->type.stop ? vt->type.stop() : 0; if (ret == 0) - vt->state = State::DESTROYED; + vt->state = State::STOPPED; return ret; } diff --git a/lib/nodes/amqp.cpp b/lib/nodes/amqp.cpp index dd340de7a..59423f2a2 100644 --- a/lib/nodes/amqp.cpp +++ b/lib/nodes/amqp.cpp @@ -398,9 +398,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "amqp"; p.description = "Advanced Message Queueing Protoocl (rabbitmq-c)"; p.type = PluginType::NODE; @@ -422,8 +419,7 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/comedi.cpp b/lib/nodes/comedi.cpp index b3a131d03..287c0f550 100644 --- a/lib/nodes/comedi.cpp +++ b/lib/nodes/comedi.cpp @@ -992,9 +992,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "comedi"; p.description = "Comedi-compatible DAQ/ADC cards"; p.type = PluginType::NODE; @@ -1015,6 +1012,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/ethercat.cpp b/lib/nodes/ethercat.cpp index ab99fcf37..02295de7b 100644 --- a/lib/nodes/ethercat.cpp +++ b/lib/nodes/ethercat.cpp @@ -366,8 +366,6 @@ int ethercat_init(struct node *n) int ret; struct ethercat *w = (struct ethercat *) n->_vd; - w->pool.state = State::DESTROYED; - /* Default values */ w->rate = 1000; @@ -447,9 +445,6 @@ int ethercat_poll_fds(struct node *n, int *fds) __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "ethercat"; p.description = "Send and receive samples of an ethercat connection"; p.type = PluginType::NODE; @@ -475,7 +470,6 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/example.cpp b/lib/nodes/example.cpp index 51fc21a29..1fb80c836 100644 --- a/lib/nodes/example.cpp +++ b/lib/nodes/example.cpp @@ -225,9 +225,6 @@ int example_netem_fds(struct node *n, int fds[]) __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "example"; p.description = "An example for staring new node-type implementations"; p.type = PluginType::NODE; @@ -258,6 +255,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/exec.cpp b/lib/nodes/exec.cpp index 3123d4357..3507cb01c 100644 --- a/lib/nodes/exec.cpp +++ b/lib/nodes/exec.cpp @@ -136,6 +136,19 @@ int exec_prepare(struct node *n) return 0; } +int exec_init(struct node *n) +{ + struct exec *e = (struct exec *) n->_vd; + + new (&e->proc) std::unique_ptr(); + new (&e->working_dir) std::string(); + new (&e->command) std::string(); + new (&e->arguments) Popen::arg_list(); + new (&e->environment) Popen::env_map(); + + return 0; +} + int exec_destroy(struct node *n) { int ret; @@ -147,6 +160,17 @@ int exec_destroy(struct node *n) return ret; } + using uptr = std::unique_ptr; + using str = std::string; + using al = Popen::arg_list; + using em = Popen::env_map; + + e->proc.~uptr(); + e->working_dir.~str(); + e->command.~str(); + e->arguments.~al(); + e->environment.~em(); + return 0; } @@ -242,9 +266,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "exec"; p.description = "run subprocesses with stdin/stdout communication"; p.type = PluginType::NODE; @@ -254,6 +275,7 @@ static void register_plugin() { p.node.parse = exec_parse; p.node.print = exec_print; p.node.prepare = exec_prepare; + p.node.init = exec_init; p.node.destroy = exec_destroy; p.node.start = exec_start; p.node.stop = exec_stop; @@ -267,6 +289,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/file.cpp b/lib/nodes/file.cpp index 552706f29..1d5a2a8f8 100644 --- a/lib/nodes/file.cpp +++ b/lib/nodes/file.cpp @@ -494,9 +494,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "file"; p.description = "support for file log / replay node type"; p.type = PluginType::NODE; @@ -520,6 +517,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/iec61850_sv.cpp b/lib/nodes/iec61850_sv.cpp index 2e5338cf4..ba422d86e 100644 --- a/lib/nodes/iec61850_sv.cpp +++ b/lib/nodes/iec61850_sv.cpp @@ -479,9 +479,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "iec61850-9-2"; p.description = "IEC 61850-9-2 (Sampled Values)"; p.type = PluginType::NODE; @@ -505,8 +502,7 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } #endif /* CONFIG_IEC61850_SAMPLED_VALUES_SUPPORT */ diff --git a/lib/nodes/infiniband.cpp b/lib/nodes/infiniband.cpp index ecb4750dc..b6e00b1b3 100644 --- a/lib/nodes/infiniband.cpp +++ b/lib/nodes/infiniband.cpp @@ -1006,9 +1006,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "infiniband"; p.description = "Infiniband interface (libibverbs, librdmacm)"; p.type = PluginType::NODE; @@ -1033,6 +1030,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/influxdb.cpp b/lib/nodes/influxdb.cpp index 65d3c7038..93168247c 100644 --- a/lib/nodes/influxdb.cpp +++ b/lib/nodes/influxdb.cpp @@ -216,9 +216,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "influxdb"; p.description = "Write results to InfluxDB"; p.type = PluginType::NODE; @@ -238,6 +235,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/loopback.cpp b/lib/nodes/loopback.cpp index a95989a4c..64cb50622 100644 --- a/lib/nodes/loopback.cpp +++ b/lib/nodes/loopback.cpp @@ -156,9 +156,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "loopback"; p.description = "Loopback to connect multiple paths"; p.type = PluginType::NODE; @@ -180,6 +177,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/mqtt.cpp b/lib/nodes/mqtt.cpp index f1921a867..7adfc3d68 100644 --- a/lib/nodes/mqtt.cpp +++ b/lib/nodes/mqtt.cpp @@ -524,9 +524,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "mqtt"; p.description = "Message Queuing Telemetry Transport (libmosquitto)"; p.type = PluginType::NODE; @@ -552,6 +549,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/nanomsg.cpp b/lib/nodes/nanomsg.cpp index d8f662182..d294e2bce 100644 --- a/lib/nodes/nanomsg.cpp +++ b/lib/nodes/nanomsg.cpp @@ -296,9 +296,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "nanomsg"; p.description = "scalability protocols library (libnanomsg)"; p.type = PluginType::NODE; @@ -322,6 +319,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/ngsi.cpp b/lib/nodes/ngsi.cpp index 9196e9140..b9aa4aae0 100644 --- a/lib/nodes/ngsi.cpp +++ b/lib/nodes/ngsi.cpp @@ -602,9 +602,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "ngsi"; p.description = "OMA Next Generation Services Interface 10 (libcurl, libjansson)"; p.type = PluginType::NODE; @@ -629,6 +626,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/opal.cpp b/lib/nodes/opal.cpp index 1f4f13900..1125d68c3 100644 --- a/lib/nodes/opal.cpp +++ b/lib/nodes/opal.cpp @@ -307,9 +307,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "opal"; p.description = "run as OPAL Asynchronous Process (libOpalAsyncApi)"; p.type = PluginType::NODE; @@ -331,6 +328,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/rtp.cpp b/lib/nodes/rtp.cpp index 1799e1508..49958399a 100644 --- a/lib/nodes/rtp.cpp +++ b/lib/nodes/rtp.cpp @@ -609,9 +609,6 @@ int rtp_netem_fds(struct node *n, int fds[]) __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "rtp"; #ifdef WITH_NETEM p.description = "real-time transport protocol (libre, libnl3 netem support)"; @@ -642,6 +639,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/shmem.cpp b/lib/nodes/shmem.cpp index 0cda4c5b4..60a98c42d 100644 --- a/lib/nodes/shmem.cpp +++ b/lib/nodes/shmem.cpp @@ -201,9 +201,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "shmem"; p.description = "POSIX shared memory interface with external processes"; p.type = PluginType::NODE; @@ -224,6 +221,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/signal_generator.cpp b/lib/nodes/signal_generator.cpp index 0d69de3a1..b8e4e8b53 100644 --- a/lib/nodes/signal_generator.cpp +++ b/lib/nodes/signal_generator.cpp @@ -314,9 +314,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "signal"; p.description = "Signal generator"; p.type = PluginType::NODE; @@ -341,6 +338,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/socket.cpp b/lib/nodes/socket.cpp index f5c044a6d..01320755e 100644 --- a/lib/nodes/socket.cpp +++ b/lib/nodes/socket.cpp @@ -565,9 +565,6 @@ int socket_fds(struct node *n, int fds[]) __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "socket"; #ifdef WITH_NETEM p.description = "BSD network sockets for Ethernet / IP / UDP (libnl3, netem support)"; @@ -596,6 +593,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/stats.cpp b/lib/nodes/stats.cpp index c21acb6b1..87c5401a9 100644 --- a/lib/nodes/stats.cpp +++ b/lib/nodes/stats.cpp @@ -247,9 +247,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "stats"; p.description = "Send statistics to another node"; p.type = PluginType::NODE; @@ -273,6 +270,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/test_rtt.cpp b/lib/nodes/test_rtt.cpp index 173bf6e97..440d0cd93 100644 --- a/lib/nodes/test_rtt.cpp +++ b/lib/nodes/test_rtt.cpp @@ -435,9 +435,6 @@ int test_rtt_poll_fds(struct node *n, int fds[]) __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "test_rtt"; p.description = "Test round-trip time with loopback"; p.type = PluginType::NODE; @@ -461,6 +458,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/uldaq.cpp b/lib/nodes/uldaq.cpp index 835c9dd83..4fc656f43 100644 --- a/lib/nodes/uldaq.cpp +++ b/lib/nodes/uldaq.cpp @@ -643,9 +643,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "uldaq"; p.description = "Measurement Computing DAQ devices like UL201 (libuldaq)"; p.type = PluginType::NODE; @@ -668,6 +665,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index 561a03934..6e56ceb2d 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -42,7 +42,7 @@ using namespace villas::utils; #define DEFAULT_WEBSOCKET_BUFFER_SIZE (1 << 12) /* Private static storage */ -static struct vlist connections = { .state = State::DESTROYED }; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */ +static struct vlist connections; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */ static villas::node::Web *web; @@ -602,9 +602,6 @@ int websocket_poll_fds(struct node *n, int fds[]) } __attribute__((constructor(110))) static void UNIQUE(__ctor)() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "websocket"; p.description = "Send and receive samples of a WebSocket connection (libwebsockets)"; p.type = PluginType::NODE; @@ -626,6 +623,5 @@ __attribute__((constructor(110))) static void UNIQUE(__ctor)() { } __attribute__((destructor(110))) static void UNIQUE(__dtor)() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/nodes/zeromq.cpp b/lib/nodes/zeromq.cpp index 331fc06e5..d52b493e8 100644 --- a/lib/nodes/zeromq.cpp +++ b/lib/nodes/zeromq.cpp @@ -104,9 +104,6 @@ int zeromq_init(struct node *n) z->curve.enabled = false; z->ipv6 = 0; - z->in.endpoints.state = State::DESTROYED; - z->out.endpoints.state = State::DESTROYED; - z->in.pending = 0; z->out.pending = 0; @@ -642,9 +639,6 @@ static struct plugin p; __attribute__((constructor(110))) static void register_plugin() { - if (plugins.state == State::DESTROYED) - vlist_init(&plugins); - p.name = "zeromq"; p.description = "ZeroMQ Distributed Messaging (libzmq)"; p.type = PluginType::NODE; @@ -672,6 +666,5 @@ static void register_plugin() { __attribute__((destructor(110))) static void deregister_plugin() { - if (plugins.state != State::DESTROYED) - vlist_remove_all(&plugins, &p); + vlist_remove_all(&plugins, &p); } diff --git a/lib/path.cpp b/lib/path.cpp index e7ff205b4..39b65c6f9 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -320,8 +320,7 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) const char *mode = nullptr; - struct vlist destinations = { .state = State::DESTROYED }; - + struct vlist destinations; vlist_init(&destinations); ret = json_unpack_ex(cfg, &err, 0, "{ s: o, s?: o, s?: o, s?: b, s?: b, s?: b, s?: i, s?: s, s?: b, s?: F, s?: o, s?: b}", @@ -388,8 +387,6 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes) ps->node = me->node; ps->masked = false; - ps->mappings.state = State::DESTROYED; - vlist_init(&ps->mappings); vlist_push(&p->sources, ps); diff --git a/lib/plugin.cpp b/lib/plugin.cpp index 276e6d390..f2b9b5a4f 100644 --- a/lib/plugin.cpp +++ b/lib/plugin.cpp @@ -26,7 +26,7 @@ #include /** Global list of all known plugins */ -struct vlist plugins = { .state = State::DESTROYED }; +struct vlist plugins; LIST_INIT_STATIC(&plugins) diff --git a/lib/shmem.cpp b/lib/shmem.cpp index 1cd81e383..7ed78d1ae 100644 --- a/lib/shmem.cpp +++ b/lib/shmem.cpp @@ -109,14 +109,12 @@ retry: fd = shm_open(wname, O_RDWR|O_CREAT|O_EXCL, 0600); ? QueueSignalledMode::POLLING : QueueSignalledMode::PTHREAD; - shared->queue.queue.state = State::DESTROYED; ret = queue_signalled_init(&shared->queue, conf->queuelen, manager, mode, flags); if (ret) { errno = ENOMEM; return -6; } - shared->pool.state = State::DESTROYED; ret = pool_init(&shared->pool, conf->queuelen, SAMPLE_LENGTH(conf->samplelen), manager); if (ret) { errno = ENOMEM; diff --git a/lib/super_node.cpp b/lib/super_node.cpp index 011ae41f0..8acfd75df 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -64,10 +64,6 @@ SuperNode::SuperNode() : hugepages(DEFAULT_NR_HUGEPAGES), task(CLOCK_REALTIME) { - nodes.state = State::DESTROYED; - paths.state = State::DESTROYED; - interfaces.state = State::DESTROYED; - vlist_init(&nodes); vlist_init(&paths); vlist_init(&interfaces); @@ -161,10 +157,6 @@ void SuperNode::parse(json_t *cfg) if (!n) throw RuntimeError("Failed to allocate memory"); - n->state = State::DESTROYED; - n->in.state = State::DESTROYED; - n->out.state = State::DESTROYED; - ret = node_init(n, nt); if (ret) throw RuntimeError("Failed to initialize node"); diff --git a/src/villas-convert.cpp b/src/villas-convert.cpp index 481279ec4..a4bde06da 100644 --- a/src/villas-convert.cpp +++ b/src/villas-convert.cpp @@ -56,7 +56,6 @@ public: for (unsigned i = 0; i < ARRAY_LEN(dirs); i++) { dirs[i].name = i == 0 ? "in" : "out"; dirs[i].format = "villas.human"; - dirs[i].io.state = State::DESTROYED; } } diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index 4ede6d7e8..e93dde558 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -70,9 +70,6 @@ public: if (ret) throw RuntimeError("Failed to initialize memory"); - p.state = State::DESTROYED; - io.state = State::DESTROYED; - cfg_cli = json_object(); } diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index 8649d319f..d01f6ac3c 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -74,9 +74,6 @@ public: enabled(en), limit(lim) { - pool.state = State::DESTROYED; - pool.queue.state = State::DESTROYED; - /* Initialize memory */ unsigned vec = LOG2_CEIL(MAX(node->out.vectorize, node->in.vectorize)); unsigned pool_size = node_type(node)->pool_size ? node_type(node)->pool_size : vec; @@ -254,8 +251,6 @@ public: if (ret) throw RuntimeError("Failed to initialize memory"); - io.state = State::DESTROYED; - cfg_cli = json_object(); } diff --git a/src/villas-signal.cpp b/src/villas-signal.cpp index bd1f702ee..d1cb5a727 100644 --- a/src/villas-signal.cpp +++ b/src/villas-signal.cpp @@ -59,13 +59,6 @@ public: { int ret; - n.state = State::DESTROYED; - n.in.state = State::DESTROYED; - n.out.state = State::DESTROYED; - io.state = State::DESTROYED; - q.state = State::DESTROYED; - q.queue.state = State::DESTROYED; - ret = memory_init(DEFAULT_NR_HUGEPAGES); if (ret) throw RuntimeError("Failed to initialize memory"); diff --git a/src/villas-test-cmp.cpp b/src/villas-test-cmp.cpp index 5b486a73d..24f3ee046 100644 --- a/src/villas-test-cmp.cpp +++ b/src/villas-test-cmp.cpp @@ -59,7 +59,6 @@ public: { int ret; - io.state = State::DESTROYED; ret = io_init2(&io, format, dtypes.c_str(), 0); if (ret) throw RuntimeError("Failed to initialize IO"); @@ -103,8 +102,6 @@ public: dtypes("64f"), flags((int) SampleFlags::HAS_SEQUENCE | (int) SampleFlags::HAS_DATA | (int) SampleFlags::HAS_TS_ORIGIN) { - pool.state = State::DESTROYED; - int ret; ret = memory_init(DEFAULT_NR_HUGEPAGES); diff --git a/tests/unit/io.cpp b/tests/unit/io.cpp index 9c1c68653..58b38379f 100644 --- a/tests/unit/io.cpp +++ b/tests/unit/io.cpp @@ -230,9 +230,9 @@ ParameterizedTest(Param *p, io, lowlevel, .init = init_memory) struct format_type *f; - struct pool pool = { .state = State::DESTROYED }; - struct io io = { .state = State::DESTROYED }; - struct vlist signals = { .state = State::DESTROYED }; + struct pool pool; + struct io io; + struct vlist signals; struct sample *smps[p->cnt]; struct sample *smpt[p->cnt]; @@ -318,13 +318,13 @@ ParameterizedTest(Param *p, io, highlevel, .init = init_memory) struct format_type *f; - struct io io = { .state = State::DESTROYED }; - struct pool pool = { .state = State::DESTROYED }; - struct vlist signals = { .state = State::DESTROYED }; - struct sample *smps[p->cnt]; struct sample *smpt[p->cnt]; + struct pool pool; + struct vlist signals; + struct io io; + ret = pool_init(&pool, 2 * p->cnt, SAMPLE_LENGTH(NUM_VALUES)); cr_assert_eq(ret, 0); diff --git a/tests/unit/mapping.cpp b/tests/unit/mapping.cpp index c11416de7..f5cd05709 100644 --- a/tests/unit/mapping.cpp +++ b/tests/unit/mapping.cpp @@ -34,7 +34,7 @@ Test(mapping, parse_nodes) { int ret; struct mapping_entry m; - struct vlist nodes = { .state = State::DESTROYED }; + struct vlist nodes; const char *node_names[3] = { "apple", "cherry", "carrot" }; const char *signal_names[3][4] = { @@ -49,7 +49,6 @@ Test(mapping, parse_nodes) struct node *n = new struct node; n->name = strdup(node_names[i]); - n->in.signals.state = State::DESTROYED; vlist_init(&n->in.signals); diff --git a/tests/unit/pool.cpp b/tests/unit/pool.cpp index 8f9272340..4eb22279c 100644 --- a/tests/unit/pool.cpp +++ b/tests/unit/pool.cpp @@ -52,7 +52,7 @@ ParameterizedTestParameters(pool, basic) ParameterizedTest(struct param *p, pool, basic, .init = init_memory) { int ret; - struct pool pool = { .state = State::DESTROYED }; + struct pool pool; void *ptr, *ptrs[p->pool_size]; diff --git a/tests/unit/queue.cpp b/tests/unit/queue.cpp index 771c69fbe..2164890b1 100644 --- a/tests/unit/queue.cpp +++ b/tests/unit/queue.cpp @@ -42,7 +42,7 @@ extern void init_memory(); #define SIZE (1 << 10) -static struct queue q = { .state = ATOMIC_VAR_INIT(State::DESTROYED) }; +static struct queue q; #if defined(_POSIX_BARRIERS) && _POSIX_BARRIERS > 0 static pthread_barrier_t barrier; @@ -250,7 +250,6 @@ Test(queue, single_threaded, .init = init_memory) p.iter_count = 1 << 8; p.queue_size = 1 << 10; p.start = 1; /* we start immeadiatly */ - p.queue.state = ATOMIC_VAR_INIT(State::DESTROYED); ret = queue_init(&p.queue, p.queue_size, &memory_heap); cr_assert_eq(ret, 0, "Failed to create queue"); @@ -319,7 +318,6 @@ ParameterizedTest(struct param *p, queue, multi_threaded, .timeout = 20, .init = pthread_t threads[p->thread_count]; p->start = 0; - p->queue.state = ATOMIC_VAR_INIT(State::DESTROYED); ret = queue_init(&p->queue, p->queue_size, p->mt); cr_assert_eq(ret, 0, "Failed to create queue"); @@ -366,8 +364,6 @@ Test(queue, init_destroy, .init = init_memory) int ret; struct queue q; - q.state = ATOMIC_VAR_INIT(State::DESTROYED); - ret = queue_init(&q, 1024, &memory_heap); cr_assert_eq(ret, 0); /* Should succeed */ diff --git a/tests/unit/queue_signalled.cpp b/tests/unit/queue_signalled.cpp index 4262c4222..25a310cd9 100644 --- a/tests/unit/queue_signalled.cpp +++ b/tests/unit/queue_signalled.cpp @@ -132,7 +132,6 @@ ParameterizedTest(struct param *param, queue_signalled, simple, .timeout = 5, .i int ret; void *r1, *r2; struct queue_signalled q; - q.queue.state = State::DESTROYED; pthread_t t1, t2;