diff options
author | Marcus Müller <mueller@kit.edu> | 2018-02-20 15:47:12 +0100 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-02-23 19:06:50 +0100 |
commit | 2fc414578985b59c5bfbb15103f3c3677a1c6fdc (patch) | |
tree | 082f8be4333be7fa3264fdf09c30d61ce3ec033d | |
parent | 4cce1a032a929d72948d54c2b429dc8ebd530a36 (diff) |
blocks: don't pmt::mp("string") for every single PDU
Replaced the usage of `#define PDU_PORT_ID pmt::mp("pdus")` – that was
the actual way to *enforce* rehashing on every single use.
Now, static const member of namespace `gr::blocks::pdu` as
`s_pdu_port_id`. Should speed up the PDU blocks a bit. Removes run-time
malloc'ing. Good thing.
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/pdu.h | 3 | ||||
-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 | 18 | ||||
-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 |
7 files changed, 21 insertions, 22 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/pdu.h b/gr-blocks/include/gnuradio/blocks/pdu.h index 0ce8615948..78250b1b82 100644 --- a/gr-blocks/include/gnuradio/blocks/pdu.h +++ b/gr-blocks/include/gnuradio/blocks/pdu.h @@ -27,12 +27,11 @@ #include <gnuradio/gr_complex.h> #include <pmt/pmt.h> -#define PDU_PORT_ID pmt::mp("pdus") 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 size_t itemsize(vector_type type); diff --git a/gr-blocks/lib/pdu_to_tagged_stream_impl.cc b/gr-blocks/lib/pdu_to_tagged_stream_impl.cc index aec5d335c4..594a1591d1 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_PORT_ID); + message_port_register_in(pdu::s_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_PORT_ID, 100)); + pmt::pmt_t msg(delete_head_blocking(pdu::s_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 91a404c5dd..ea2d470d2b 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_PORT_ID); + message_port_register_out(pdu::s_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_PORT_ID, pdu); + message_port_pub(pdu::s_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 efb778f404..2e154d2c1f 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_PORT_ID); - message_port_register_out(PDU_PORT_ID); + message_port_register_in(pdu::s_pdu_port_id); + message_port_register_out(pdu::s_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_PORT_ID, boost::bind(&socket_pdu_impl::tcp_server_send, this, _1)); + set_msg_handler(pdu::s_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_PORT_ID, boost::bind(&socket_pdu_impl::tcp_client_send, this, _1)); + set_msg_handler(pdu::s_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_PORT_ID, boost::bind(&socket_pdu_impl::udp_send, this, _1)); + set_msg_handler(pdu::s_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_PORT_ID, boost::bind(&socket_pdu_impl::udp_send, this, _1)); + set_msg_handler(pdu::s_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_PORT_ID, pdu); + message_port_pub(pdu::s_pdu_port_id, pdu); d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf), boost::bind(&socket_pdu_impl::handle_tcp_read, this, @@ -231,7 +231,7 @@ namespace gr { memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), send_len); offset += send_len; d_udp_socket->send_to(boost::asio::buffer(txbuf, send_len), d_udp_endpoint_other); - } + } } void @@ -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_PORT_ID, pdu); + message_port_pub(pdu::s_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 04871aef8f..7e1f54f1a9 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_PORT_ID); + message_port_register_out(pdu::s_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_PORT_ID, msg); + message_port_pub(pdu::s_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 200e82b89f..4dba1e9edc 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_PORT_ID, pdu); + d_block->message_port_pub(pdu::s_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 7bd0889d5e..dba76d1ba4 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_PORT_ID); - start_rxthread(this, PDU_PORT_ID); + message_port_register_out(pdu::s_pdu_port_id); + start_rxthread(this, pdu::s_pdu_port_id); // set up input message port - message_port_register_in(PDU_PORT_ID); - set_msg_handler(PDU_PORT_ID, boost::bind(&tuntap_pdu_impl::send, this, _1)); + 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)); } int |