File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ rfs::~rfs()
120120 delete[] m_sinks_list;
121121
122122 while (m_attach_flow_data_vector.size () > 0 ) {
123- delete m_attach_flow_data_vector.back ();
123+ free ( m_attach_flow_data_vector.back () );
124124 m_attach_flow_data_vector.pop_back ();
125125 }
126126}
Original file line number Diff line number Diff line change 88#ifndef RFS_H
99#define RFS_H
1010
11+ #include < stdlib.h>
12+ #include < type_traits>
1113#include < vector>
1214
1315#include " vma/ib/base/verbs_extra.h"
@@ -213,6 +215,15 @@ class rfs
213215 virtual bool rx_dispatch_packet (mem_buf_desc_t * p_rx_wc_buf_desc, void * pv_fd_ready_array) = 0;
214216
215217protected:
218+ template <class T , typename ...Args>
219+ T * new_malloc (Args ... args) {
220+ static_assert (std::is_trivially_destructible<T>::value == true );
221+ void * p = aligned_alloc (alignof (T), sizeof (T));
222+ if (!p)
223+ throw std::bad_alloc{};
224+ return new (p) T (args...);
225+ }
226+
216227 flow_tuple m_flow_tuple;
217228 ring_slave* m_p_ring;
218229 rfs_rule_filter* m_p_rule_filter;
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ bool rfs_mc::prepare_flow_spec()
5656#ifdef DEFINED_IBV_FLOW_SPEC_IB
5757 attach_flow_data_ib_v1_t * attach_flow_data_ib_v1 = NULL ;
5858
59- attach_flow_data_ib_v1 = new attach_flow_data_ib_v1_t (p_ring->m_p_qp_mgr );
59+ attach_flow_data_ib_v1 = new_malloc< attach_flow_data_ib_v1_t > (p_ring->m_p_qp_mgr );
6060
6161 uint8_t dst_gid[16 ];
6262 create_mgid_from_ipv4_mc_ip (dst_gid, p_ring->m_p_qp_mgr ->get_partiton (), m_flow_tuple.get_dst_ip ());
@@ -70,7 +70,7 @@ bool rfs_mc::prepare_flow_spec()
7070#endif
7171 }
7272
73- attach_flow_data_ib_v2 = new attach_flow_data_ib_v2_t (p_ring->m_p_qp_mgr );
73+ attach_flow_data_ib_v2 = new_malloc< attach_flow_data_ib_v2_t > (p_ring->m_p_qp_mgr );
7474
7575 ibv_flow_spec_ipv4_set (&(attach_flow_data_ib_v2->ibv_flow_attr .ipv4 ),
7676 m_flow_tuple.get_dst_ip (),
@@ -88,7 +88,7 @@ bool rfs_mc::prepare_flow_spec()
8888 {
8989 attach_flow_data_eth_ipv4_tcp_udp_t * attach_flow_data_eth = NULL ;
9090
91- attach_flow_data_eth = new attach_flow_data_eth_ipv4_tcp_udp_t (p_ring->m_p_qp_mgr );
91+ attach_flow_data_eth = new_malloc< attach_flow_data_eth_ipv4_tcp_udp_t > (p_ring->m_p_qp_mgr );
9292
9393 uint8_t dst_mac[6 ];
9494 create_multicast_mac_from_ip (dst_mac, m_flow_tuple.get_dst_ip ());
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ bool rfs_uc::prepare_flow_spec()
5959 if (0 == p_ring->m_p_qp_mgr ->get_underly_qpn ()) {
6060 attach_flow_data_ib_ipv4_tcp_udp_v1_t * attach_flow_data_ib_v1 = NULL ;
6161
62- attach_flow_data_ib_v1 = new attach_flow_data_ib_ipv4_tcp_udp_v1_t (p_ring->m_p_qp_mgr );
62+ attach_flow_data_ib_v1 = new_malloc< attach_flow_data_ib_ipv4_tcp_udp_v1_t > (p_ring->m_p_qp_mgr );
6363 ibv_flow_spec_ib_set_by_dst_qpn (&(attach_flow_data_ib_v1->ibv_flow_attr .ib ),
6464 htonl (((IPoIB_addr*)p_ring->m_p_l2_addr )->get_qpn ()));
6565 p_ipv4 = &(attach_flow_data_ib_v1->ibv_flow_attr .ipv4 );
@@ -68,7 +68,7 @@ bool rfs_uc::prepare_flow_spec()
6868 break ;
6969 }
7070#endif
71- attach_flow_data_ib_v2 = new attach_flow_data_ib_ipv4_tcp_udp_v2_t (p_ring->m_p_qp_mgr );
71+ attach_flow_data_ib_v2 = new_malloc< attach_flow_data_ib_ipv4_tcp_udp_v2_t > (p_ring->m_p_qp_mgr );
7272
7373 p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr .ipv4 );
7474 p_tcp_udp = &(attach_flow_data_ib_v2->ibv_flow_attr .tcp_udp );
@@ -77,7 +77,7 @@ bool rfs_uc::prepare_flow_spec()
7777 }
7878 case VMA_TRANSPORT_ETH:
7979 {
80- attach_flow_data_eth = new attach_flow_data_eth_ipv4_tcp_udp_t (p_ring->m_p_qp_mgr );
80+ attach_flow_data_eth = new_malloc< attach_flow_data_eth_ipv4_tcp_udp_t > (p_ring->m_p_qp_mgr );
8181
8282 ibv_flow_spec_eth_set (&(attach_flow_data_eth->ibv_flow_attr .eth ),
8383 p_ring->m_p_l2_addr ->get_address (),
You can’t perform that action at this time.
0 commit comments