diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2018-03-30 13:17:10 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-03-30 20:46:04 +0200 |
commit | 9a6bf484394f5954483477856f6a6712331b9ee6 (patch) | |
tree | 91fd88420a8b373adb5ea2e76d002048cf78fa99 | |
parent | 50e0156324bec28d4e07b9598798b6267fb39155 (diff) |
blocks: avoid potential static initialization order fiasco
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/pdu.h | 2 | ||||
-rw-r--r-- | gr-blocks/lib/pdu.cc | 6 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_filter_impl.cc | 8 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_remove_impl.cc | 8 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_set_impl.cc | 8 | ||||
-rw-r--r-- | gr-blocks/lib/pdu_to_tagged_stream_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/random_pdu_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/socket_pdu_impl.cc | 16 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_stream_to_pdu_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/tcp_connection.cc | 2 | ||||
-rw-r--r-- | gr-blocks/lib/tuntap_pdu_impl.cc | 8 | ||||
-rw-r--r-- | gr-digital/lib/header_payload_demux_impl.cc | 10 | ||||
-rw-r--r-- | gr-digital/lib/header_payload_demux_impl.h | 2 |
13 files changed, 46 insertions, 36 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/pdu.h b/gr-blocks/include/gnuradio/blocks/pdu.h index 78250b1b82..f33575fcf9 100644 --- a/gr-blocks/include/gnuradio/blocks/pdu.h +++ b/gr-blocks/include/gnuradio/blocks/pdu.h @@ -31,9 +31,9 @@ namespace gr { namespace blocks { namespace pdu { - static const pmt::pmt_t s_pdu_port_id = pmt::mp("pdus"); enum vector_type { byte_t, float_t, complex_t }; + BLOCKS_API const pmt::pmt_t pdu_port_id(); BLOCKS_API size_t itemsize(vector_type type); BLOCKS_API bool type_matches(vector_type type, pmt::pmt_t v); BLOCKS_API pmt::pmt_t make_pdu_vector(vector_type type, const uint8_t* buf, size_t items); diff --git a/gr-blocks/lib/pdu.cc b/gr-blocks/lib/pdu.cc index 54e0bad5d0..f0e610209f 100644 --- a/gr-blocks/lib/pdu.cc +++ b/gr-blocks/lib/pdu.cc @@ -30,6 +30,12 @@ namespace gr { namespace blocks { namespace pdu { + const + pmt::pmt_t pdu_port_id(){ + static const pmt::pmt_t pdu_port_id = pmt::mp("pdus"); + return pdu_port_id; + } + size_t itemsize(vector_type type) { diff --git a/gr-blocks/lib/pdu_filter_impl.cc b/gr-blocks/lib/pdu_filter_impl.cc index 17879d4b5a..31c737af53 100644 --- a/gr-blocks/lib/pdu_filter_impl.cc +++ b/gr-blocks/lib/pdu_filter_impl.cc @@ -43,9 +43,9 @@ namespace gr { io_signature::make (0, 0, 0)), d_k(k), d_v(v), d_invert(invert) { - message_port_register_out(pdu::s_pdu_port_id); - message_port_register_in(pdu::s_pdu_port_id); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&pdu_filter_impl::handle_msg, this, _1)); + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_filter_impl::handle_msg, this, _1)); } void @@ -63,7 +63,7 @@ namespace gr { // if all tests pass, propagate the pdu if(output){ - message_port_pub(pdu::s_pdu_port_id, pdu); + message_port_pub(pdu::pdu_port_id(), pdu); } } diff --git a/gr-blocks/lib/pdu_remove_impl.cc b/gr-blocks/lib/pdu_remove_impl.cc index afa853c06b..ab6dd4a4e7 100644 --- a/gr-blocks/lib/pdu_remove_impl.cc +++ b/gr-blocks/lib/pdu_remove_impl.cc @@ -43,9 +43,9 @@ namespace gr { io_signature::make (0, 0, 0)), d_k(k) { - message_port_register_out(pdu::s_pdu_port_id); - message_port_register_in(pdu::s_pdu_port_id); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&pdu_remove_impl::handle_msg, this, _1)); + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_remove_impl::handle_msg, this, _1)); } void @@ -59,7 +59,7 @@ namespace gr { throw std::runtime_error("pdu_remove received non PDU input"); } meta = pmt::dict_delete(meta, d_k); - message_port_pub(pdu::s_pdu_port_id, pmt::cons(meta, pmt::cdr(pdu))); + message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu))); } } /* namespace blocks */ diff --git a/gr-blocks/lib/pdu_set_impl.cc b/gr-blocks/lib/pdu_set_impl.cc index cbac65a766..df09e2e9f9 100644 --- a/gr-blocks/lib/pdu_set_impl.cc +++ b/gr-blocks/lib/pdu_set_impl.cc @@ -43,9 +43,9 @@ namespace gr { io_signature::make (0, 0, 0)), d_k(k), d_v(v) { - message_port_register_out(pdu::s_pdu_port_id); - message_port_register_in(pdu::s_pdu_port_id); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&pdu_set_impl::handle_msg, this, _1)); + message_port_register_out(pdu::pdu_port_id()); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&pdu_set_impl::handle_msg, this, _1)); } void @@ -59,7 +59,7 @@ namespace gr { throw std::runtime_error("pdu_set received non PDU input"); } meta = pmt::dict_add(meta, d_k, d_v); - message_port_pub(pdu::s_pdu_port_id, pmt::cons(meta, pmt::cdr(pdu))); + message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu))); } } /* namespace blocks */ diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc index 594a1591d1..a58f73c991 100644 --- a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc +++ b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc @@ -46,7 +46,7 @@ namespace gr { d_type(type), d_curr_len(0) { - message_port_register_in(pdu::s_pdu_port_id); + message_port_register_in(pdu::pdu_port_id()); } int pdu_to_tagged_stream_impl::calculate_output_stream_length(const gr_vector_int &) @@ -55,7 +55,7 @@ namespace gr { /* FIXME: This blocking call is far from ideal but is the best we * can do at the moment */ - pmt::pmt_t msg(delete_head_blocking(pdu::s_pdu_port_id, 100)); + pmt::pmt_t msg(delete_head_blocking(pdu::pdu_port_id(), 100)); if (msg.get() == NULL) { return 0; } diff --git a/gr-blocks/lib/random_pdu_impl.cc b/gr-blocks/lib/random_pdu_impl.cc index ea2d470d2b..9dfc761a2b 100644 --- a/gr-blocks/lib/random_pdu_impl.cc +++ b/gr-blocks/lib/random_pdu_impl.cc @@ -48,7 +48,7 @@ namespace gr { d_mask(byte_mask), d_length_modulo(length_modulo) { - message_port_register_out(pdu::s_pdu_port_id); + message_port_register_out(pdu::pdu_port_id()); message_port_register_in(pmt::mp("generate")); set_msg_handler(pmt::mp("generate"), boost::bind(&random_pdu_impl::generate_pdu, this, _1)); if(length_modulo < 1) @@ -80,7 +80,7 @@ namespace gr { pmt::pmt_t vecpmt(pmt::make_blob(&vec[0], len)); pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL, vecpmt)); - message_port_pub(pdu::s_pdu_port_id, pdu); + message_port_pub(pdu::pdu_port_id(), pdu); } } /* namespace blocks */ diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc index 2e154d2c1f..e20f1478f0 100644 --- a/gr-blocks/lib/socket_pdu_impl.cc +++ b/gr-blocks/lib/socket_pdu_impl.cc @@ -46,8 +46,8 @@ namespace gr { { d_rxbuf.resize(MTU); - message_port_register_in(pdu::s_pdu_port_id); - message_port_register_out(pdu::s_pdu_port_id); + message_port_register_in(pdu::pdu_port_id()); + message_port_register_out(pdu::pdu_port_id()); if ((type == "TCP_SERVER") && ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces int port_num = atoi(port.c_str()); @@ -86,7 +86,7 @@ namespace gr { start_tcp_accept(); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::tcp_server_send, this, _1)); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::tcp_server_send, this, _1)); } else if (type =="TCP_CLIENT") { boost::system::error_code error = boost::asio::error::host_not_found; @@ -96,7 +96,7 @@ namespace gr { throw boost::system::system_error(error); d_tcp_socket->set_option(boost::asio::ip::tcp::no_delay(d_tcp_no_delay)); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::tcp_client_send, this, _1)); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::tcp_client_send, this, _1)); d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf), boost::bind(&socket_pdu_impl::handle_tcp_read, this, @@ -110,7 +110,7 @@ namespace gr { boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::udp_send, this, _1)); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::udp_send, this, _1)); } else if (type =="UDP_CLIENT") { d_udp_socket.reset(new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint)); @@ -119,7 +119,7 @@ namespace gr { boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::udp_send, this, _1)); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&socket_pdu_impl::udp_send, this, _1)); } else throw std::runtime_error("gr::blocks:socket_pdu: unknown socket type"); @@ -151,7 +151,7 @@ namespace gr { if (!error) { pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t *)&d_rxbuf[0]); pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); - message_port_pub(pdu::s_pdu_port_id, pdu); + message_port_pub(pdu::pdu_port_id(), pdu); d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf), boost::bind(&socket_pdu_impl::handle_tcp_read, this, @@ -241,7 +241,7 @@ namespace gr { pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]); pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); - message_port_pub(pdu::s_pdu_port_id, pdu); + message_port_pub(pdu::pdu_port_id(), pdu); d_udp_socket->async_receive_from(boost::asio::buffer(d_rxbuf), d_udp_endpoint_other, boost::bind(&socket_pdu_impl::handle_udp_read, this, diff --git a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc index 7e1f54f1a9..feada488c7 100644 --- a/gr-blocks/lib/tagged_stream_to_pdu_impl.cc +++ b/gr-blocks/lib/tagged_stream_to_pdu_impl.cc @@ -45,7 +45,7 @@ namespace gr { d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL) { - message_port_register_out(pdu::s_pdu_port_id); + message_port_register_out(pdu::pdu_port_id()); } int @@ -71,7 +71,7 @@ namespace gr { // Send msg pmt::pmt_t msg = pmt::cons(d_pdu_meta, d_pdu_vector); - message_port_pub(pdu::s_pdu_port_id, msg); + message_port_pub(pdu::pdu_port_id(), msg); return ninput_items[0]; } diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc index 4dba1e9edc..4c0dfc27ac 100644 --- a/gr-blocks/lib/tcp_connection.cc +++ b/gr-blocks/lib/tcp_connection.cc @@ -94,7 +94,7 @@ namespace gr { pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_buf[0]); pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector); - d_block->message_port_pub(pdu::s_pdu_port_id, pdu); + d_block->message_port_pub(pdu::pdu_port_id(), pdu); } d_socket.async_read_some(boost::asio::buffer(d_buf), diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc index dba76d1ba4..dd4ce90982 100644 --- a/gr-blocks/lib/tuntap_pdu_impl.cc +++ b/gr-blocks/lib/tuntap_pdu_impl.cc @@ -92,12 +92,12 @@ namespace gr { ) % dev % dev << std::endl; // set up output message port - message_port_register_out(pdu::s_pdu_port_id); - start_rxthread(this, pdu::s_pdu_port_id); + message_port_register_out(pdu::pdu_port_id()); + start_rxthread(this, pdu::pdu_port_id()); // set up input message port - message_port_register_in(pdu::s_pdu_port_id); - set_msg_handler(pdu::s_pdu_port_id, boost::bind(&tuntap_pdu_impl::send, this, _1)); + message_port_register_in(pdu::pdu_port_id()); + set_msg_handler(pdu::pdu_port_id(), boost::bind(&tuntap_pdu_impl::send, this, _1)); } int diff --git a/gr-digital/lib/header_payload_demux_impl.cc b/gr-digital/lib/header_payload_demux_impl.cc index 646902d506..c6ec53ba35 100644 --- a/gr-digital/lib/header_payload_demux_impl.cc +++ b/gr-digital/lib/header_payload_demux_impl.cc @@ -31,7 +31,11 @@ namespace gr { namespace digital { - const pmt::pmt_t header_payload_demux_impl::s_msg_port_id = pmt::mp("header_data"); + const pmt::pmt_t header_payload_demux_impl::msg_port_id() + { + static const pmt::pmt_t msg_port_id = pmt::mp("header_data"); + return msg_port_id; + } //! Returns a PMT time tuple (uint seconds, double fraction) as the sum of // another PMT time tuple and a time diff in seconds. @@ -149,8 +153,8 @@ namespace gr { ); } set_tag_propagation_policy(TPP_DONT); - message_port_register_in(s_msg_port_id); - set_msg_handler(s_msg_port_id, boost::bind(&header_payload_demux_impl::parse_header_data_msg, this, _1)); + message_port_register_in(msg_port_id()); + set_msg_handler(msg_port_id(), boost::bind(&header_payload_demux_impl::parse_header_data_msg, this, _1)); for (size_t i = 0; i < special_tags.size(); i++) { d_special_tags.push_back(pmt::string_to_symbol(special_tags[i])); d_special_tags_last_value.push_back(pmt::PMT_NIL); diff --git a/gr-digital/lib/header_payload_demux_impl.h b/gr-digital/lib/header_payload_demux_impl.h index dfadfd58e6..8f1acd4fb4 100644 --- a/gr-digital/lib/header_payload_demux_impl.h +++ b/gr-digital/lib/header_payload_demux_impl.h @@ -55,7 +55,7 @@ namespace gr { std::vector<pmt::pmt_t> d_special_tags; //!< List of special tags std::vector<pmt::pmt_t> d_special_tags_last_value; //!< The current value of the special tags - static const pmt::pmt_t s_msg_port_id; //!< Message Port Id + static const pmt::pmt_t msg_port_id(); //!< Message Port Id // Helper functions to make the state machine more readable |