diff --git a/net/bluetooth/bluetooth.h b/net/bluetooth/bluetooth.h index c625d67578..aeac3269a3 100644 --- a/net/bluetooth/bluetooth.h +++ b/net/bluetooth/bluetooth.h @@ -143,20 +143,6 @@ struct sockaddr; /* Forward reference */ void bluetooth_initialize(void); -/**************************************************************************** - * Name: bluetooth_conn_initialize - * - * Description: - * Initialize the Bluetooth connection structure allocator. Called - * once and only from bluetooth_initialize(). - * - * Assumptions: - * Called early in the initialization sequence - * - ****************************************************************************/ - -void bluetooth_conn_initialize(void); - /**************************************************************************** * Name: bluetooth_conn_alloc() * diff --git a/net/bluetooth/bluetooth_conn.c b/net/bluetooth/bluetooth_conn.c index ad529326b6..9deb36247c 100644 --- a/net/bluetooth/bluetooth_conn.c +++ b/net/bluetooth/bluetooth_conn.c @@ -81,23 +81,6 @@ static const bt_addr_t g_any_addr = * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: bluetooth_conn_initialize - * - * Description: - * Initialize the Bluetooth connection structure allocator. Called - * once and only from bluetooth_initialize(). - * - * Assumptions: - * Called early in the initialization sequence - * - ****************************************************************************/ - -void bluetooth_conn_initialize(void) -{ - NET_BUFPOOL_INIT(g_bluetooth_connections); -} - /**************************************************************************** * Name: bluetooth_conn_alloc() * diff --git a/net/bluetooth/bluetooth_initialize.c b/net/bluetooth/bluetooth_initialize.c index 92e71719c6..0ab1a14fbe 100644 --- a/net/bluetooth/bluetooth_initialize.c +++ b/net/bluetooth/bluetooth_initialize.c @@ -48,10 +48,6 @@ void bluetooth_initialize(void) { - /* Initialize connection structions */ - - bluetooth_conn_initialize(); - /* Initialize the container allocator */ bluetooth_container_initialize(); diff --git a/net/can/can_conn.c b/net/can/can_conn.c index 6f26bab4c8..30f3899242 100644 --- a/net/can/can_conn.c +++ b/net/can/can_conn.c @@ -83,7 +83,6 @@ static dq_queue_t g_active_can_connections; void can_initialize(void) { - NET_BUFPOOL_INIT(g_can_connections); } /**************************************************************************** diff --git a/net/devif/devif.h b/net/devif/devif.h index 5b3bdaea11..875e21f150 100644 --- a/net/devif/devif.h +++ b/net/devif/devif.h @@ -310,19 +310,6 @@ extern "C" void devif_initialize(void); -/**************************************************************************** - * Name: devif_callback_init - * - * Description: - * Configure the pre-allocated callback structures into a free list. - * - * Assumptions: - * This function must be called with the network locked. - * - ****************************************************************************/ - -void devif_callback_init(void); - /**************************************************************************** * Name: devif_callback_alloc * diff --git a/net/devif/devif_callback.c b/net/devif/devif_callback.c index 6f451a2b38..ce633c3229 100644 --- a/net/devif/devif_callback.c +++ b/net/devif/devif_callback.c @@ -237,23 +237,6 @@ static bool devif_event_trigger(uint16_t events, uint16_t triggers) * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: devif_callback_init - * - * Description: - * Configure the pre-allocated callback structures into a free list. - * - * Assumptions: - * Called early in the initialization sequence so that no special - * protection is required. - * - ****************************************************************************/ - -void devif_callback_init(void) -{ - NET_BUFPOOL_INIT(g_cbprealloc); -} - /**************************************************************************** * Name: devif_callback_alloc * diff --git a/net/devif/devif_initialize.c b/net/devif/devif_initialize.c index 302c76b476..03b9e1d682 100644 --- a/net/devif/devif_initialize.c +++ b/net/devif/devif_initialize.c @@ -88,8 +88,5 @@ struct net_stats_s g_netstats; void devif_initialize(void) { - /* Initialize callback support */ - - devif_callback_init(); } #endif /* CONFIG_NET */ diff --git a/net/icmp/icmp.h b/net/icmp/icmp.h index 57a80fd97d..9e8f6e0080 100644 --- a/net/icmp/icmp.h +++ b/net/icmp/icmp.h @@ -162,19 +162,6 @@ EXTERN const struct sock_intf_s g_icmp_sockif; void icmp_input(FAR struct net_driver_s *dev); -/**************************************************************************** - * Name: icmp_sock_initialize - * - * Description: - * Initialize the IPPROTO_ICMP socket connection structures. Called once - * and only from the network initialization layer. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_ICMP_SOCKET -void icmp_sock_initialize(void); -#endif - /**************************************************************************** * Name: icmp_alloc * diff --git a/net/icmp/icmp_conn.c b/net/icmp/icmp_conn.c index 3fb3d1938c..f7e9256b6a 100644 --- a/net/icmp/icmp_conn.c +++ b/net/icmp/icmp_conn.c @@ -72,20 +72,6 @@ static dq_queue_t g_active_icmp_connections; * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: icmp_sock_initialize - * - * Description: - * Initialize the IPPROTO_ICMP socket connection structures. Called once - * and only from the network initialization layer. - * - ****************************************************************************/ - -void icmp_sock_initialize(void) -{ - NET_BUFPOOL_INIT(g_icmp_connections); -} - /**************************************************************************** * Name: icmp_alloc * diff --git a/net/icmpv6/icmpv6.h b/net/icmpv6/icmpv6.h index 5d4301892c..6f0c0e5822 100644 --- a/net/icmpv6/icmpv6.h +++ b/net/icmpv6/icmpv6.h @@ -563,19 +563,6 @@ void icmpv6_rnotify(FAR struct net_driver_s *dev, int result); # define icmpv6_rnotify(d,r) (0) #endif -/**************************************************************************** - * Name: icmpv6_sock_initialize - * - * Description: - * Initialize the IPPROTO_ICMP socket connection structures. Called once - * and only from the network initialization layer. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_ICMPv6_SOCKET -void icmpv6_sock_initialize(void); -#endif - /**************************************************************************** * Name: icmpv6_alloc * diff --git a/net/icmpv6/icmpv6_conn.c b/net/icmpv6/icmpv6_conn.c index 228f83e8d5..0d49222850 100644 --- a/net/icmpv6/icmpv6_conn.c +++ b/net/icmpv6/icmpv6_conn.c @@ -73,20 +73,6 @@ static dq_queue_t g_active_icmpv6_connections; * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: icmpv6_sock_initialize - * - * Description: - * Initialize the IPPROTO_ICMP socket connection structures. Called once - * and only from the network initialization layer. - * - ****************************************************************************/ - -void icmpv6_sock_initialize(void) -{ - NET_BUFPOOL_INIT(g_icmpv6_connections); -} - /**************************************************************************** * Name: icmpv6_alloc * diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h index 721a0f6218..af337d88b4 100644 --- a/net/ieee802154/ieee802154.h +++ b/net/ieee802154/ieee802154.h @@ -157,20 +157,6 @@ struct sockaddr; /* Forward reference */ void ieee802154_initialize(void); -/**************************************************************************** - * Name: ieee802154_conn_initialize - * - * Description: - * Initialize the IEEE 802.15.4 connection structure allocator. Called - * once and only from ieee802154_initialize(). - * - * Assumptions: - * Called early in the initialization sequence - * - ****************************************************************************/ - -void ieee802154_conn_initialize(void); - /**************************************************************************** * Name: ieee802154_conn_alloc() * diff --git a/net/ieee802154/ieee802154_conn.c b/net/ieee802154/ieee802154_conn.c index 46e7ff7047..ce89c02c6b 100644 --- a/net/ieee802154/ieee802154_conn.c +++ b/net/ieee802154/ieee802154_conn.c @@ -76,23 +76,6 @@ static dq_queue_t g_active_ieee802154_connections; * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: ieee802154_conn_initialize - * - * Description: - * Initialize the IEEE 802.15.4 connection structure allocator. Called - * once and only from ieee802154_initialize(). - * - * Assumptions: - * Called early in the initialization sequence - * - ****************************************************************************/ - -void ieee802154_conn_initialize(void) -{ - NET_BUFPOOL_INIT(g_ieee802154_connections); -} - /**************************************************************************** * Name: ieee802154_conn_alloc() * diff --git a/net/ieee802154/ieee802154_initialize.c b/net/ieee802154/ieee802154_initialize.c index 56e6352454..94364f874b 100644 --- a/net/ieee802154/ieee802154_initialize.c +++ b/net/ieee802154/ieee802154_initialize.c @@ -48,10 +48,6 @@ void ieee802154_initialize(void) { - /* Initialize connection structions */ - - ieee802154_conn_initialize(); - /* Initialize the container allocator */ ieee802154_container_initialize(); diff --git a/net/ipforward/ipfwd_alloc.c b/net/ipforward/ipfwd_alloc.c index dc3fb31ec0..2d993ce452 100644 --- a/net/ipforward/ipfwd_alloc.c +++ b/net/ipforward/ipfwd_alloc.c @@ -96,8 +96,6 @@ void ipfwd_initialize(void) */ DEBUGASSERT(MAX_HDRLEN <= CONFIG_IOB_BUFSIZE); - - NET_BUFPOOL_INIT(g_fwdpool); } /**************************************************************************** diff --git a/net/net_initialize.c b/net/net_initialize.c index d97f238d45..25d69c5a1e 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -131,38 +131,16 @@ void net_initialize(void) ipfwd_initialize(); #endif -#ifdef CONFIG_NET_ICMP_SOCKET - /* Initialize IPPPROTO_ICMP socket support */ - - icmp_sock_initialize(); -#endif - -#ifdef CONFIG_NET_ICMPv6_SOCKET - /* Initialize IPPPROTO_ICMP6 socket support */ - - icmpv6_sock_initialize(); -#endif - #ifdef NET_TCP_HAVE_STACK /* Initialize the TCP/IP connection structures */ tcp_initialize(); - - /* Initialize the TCP/IP write buffering */ - -#ifdef CONFIG_NET_TCP_WRITE_BUFFERS - tcp_wrbuffer_initialize(); -#endif #endif /* CONFIG_NET_TCP */ #ifdef NET_UDP_HAVE_STACK /* Initialize the UDP connection structures */ udp_initialize(); - -#ifdef CONFIG_NET_UDP_WRITE_BUFFERS - udp_wrbuffer_initialize(); -#endif #endif #ifdef CONFIG_NET_USRSOCK diff --git a/net/netlink/netlink_conn.c b/net/netlink/netlink_conn.c index dddb52bd5c..fa960a0cff 100644 --- a/net/netlink/netlink_conn.c +++ b/net/netlink/netlink_conn.c @@ -150,7 +150,6 @@ netlink_get_terminator(FAR const struct nlmsghdr *req) void netlink_initialize(void) { - NET_BUFPOOL_INIT(g_netlink_connections); } /**************************************************************************** diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c index 8856acb5bb..8482d68de3 100644 --- a/net/pkt/pkt_conn.c +++ b/net/pkt/pkt_conn.c @@ -87,7 +87,6 @@ static dq_queue_t g_active_pkt_connections; void pkt_initialize(void) { - NET_BUFPOOL_INIT(g_pkt_connections); } /**************************************************************************** diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 14dcdeee3a..10dacf8b5b 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -1768,21 +1768,6 @@ bool tcp_should_send_recvwindow(FAR struct tcp_conn_s *conn); int psock_tcp_cansend(FAR struct tcp_conn_s *conn); -/**************************************************************************** - * Name: tcp_wrbuffer_initialize - * - * Description: - * Initialize the list of free write buffers - * - * Assumptions: - * Called once early initialization. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_TCP_WRITE_BUFFERS -void tcp_wrbuffer_initialize(void); -#endif /* CONFIG_NET_TCP_WRITE_BUFFERS */ - #ifdef CONFIG_NET_TCP_WRITE_BUFFERS struct tcp_wrbuffer_s; diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index d8bc2eda91..19c1fd97cc 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -606,7 +606,6 @@ int tcp_selectport(uint8_t domain, void tcp_initialize(void) { - NET_BUFPOOL_INIT(g_tcp_connections); } /**************************************************************************** diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index e3fbf333bb..2450f2f832 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -62,22 +62,6 @@ NET_BUFPOOL_DECLARE(g_wrbuffer, sizeof(struct tcp_wrbuffer_s), * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: tcp_wrbuffer_initialize - * - * Description: - * Initialize the list of free write buffers - * - * Assumptions: - * Called once early initialization. - * - ****************************************************************************/ - -void tcp_wrbuffer_initialize(void) -{ - NET_BUFPOOL_INIT(g_wrbuffer); -} - /**************************************************************************** * Name: tcp_wrbuffer_timedalloc * diff --git a/net/udp/udp.h b/net/udp/udp.h index ab2f076434..b60295cd40 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -480,21 +480,6 @@ int udp_setsockopt(FAR struct socket *psock, int option, FAR const void *value, socklen_t value_len); #endif -/**************************************************************************** - * Name: udp_wrbuffer_initialize - * - * Description: - * Initialize the list of free write buffers - * - * Assumptions: - * Called once early initialization. - * - ****************************************************************************/ - -#ifdef CONFIG_NET_UDP_WRITE_BUFFERS -void udp_wrbuffer_initialize(void); -#endif /* CONFIG_NET_UDP_WRITE_BUFFERS */ - /**************************************************************************** * Name: udp_wrbuffer_alloc * diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index d2062b46ae..553401adee 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -549,7 +549,6 @@ errout: void udp_initialize(void) { - NET_BUFPOOL_INIT(g_udp_connections); } /**************************************************************************** diff --git a/net/udp/udp_wrbuffer.c b/net/udp/udp_wrbuffer.c index 37ca4b580c..c967d216e9 100644 --- a/net/udp/udp_wrbuffer.c +++ b/net/udp/udp_wrbuffer.c @@ -61,22 +61,6 @@ NET_BUFPOOL_DECLARE(g_wrbuffer, sizeof(struct udp_wrbuffer_s), * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: udp_wrbuffer_initialize - * - * Description: - * Initialize the list of free write buffers - * - * Assumptions: - * Called once early initialization. - * - ****************************************************************************/ - -void udp_wrbuffer_initialize(void) -{ - NET_BUFPOOL_INIT(g_wrbuffer); -} - /**************************************************************************** * Name: udp_wrbuffer_alloc * diff --git a/net/usrsock/usrsock_conn.c b/net/usrsock/usrsock_conn.c index 496f248d35..528b79ca28 100644 --- a/net/usrsock/usrsock_conn.c +++ b/net/usrsock/usrsock_conn.c @@ -300,8 +300,6 @@ void usrsock_setup_datain(FAR struct usrsock_conn_s *conn, void usrsock_initialize(void) { - NET_BUFPOOL_INIT(g_usrsock_connections); - /* Register /dev/usrsock character device. */ usrsock_register(); diff --git a/net/utils/net_bufpool.c b/net/utils/net_bufpool.c index 0bf1a231fa..70f0fba209 100644 --- a/net/utils/net_bufpool.c +++ b/net/utils/net_bufpool.c @@ -44,7 +44,7 @@ struct net_bufnode_s }; /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ /**************************************************************************** @@ -58,11 +58,13 @@ struct net_bufnode_s * ****************************************************************************/ -void net_bufpool_init(FAR struct net_bufpool_s *pool) +static void net_bufpool_init(FAR struct net_bufpool_s *pool) { int i; - sq_init(&pool->freebuffers); + DEBUGASSERT(pool->nodesize < 0); + pool->nodesize = -pool->nodesize; + for (i = 0; i < pool->prealloc; i++) { FAR struct net_bufnode_s *node = (FAR struct net_bufnode_s *) @@ -71,6 +73,10 @@ void net_bufpool_init(FAR struct net_bufpool_s *pool) } } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + /**************************************************************************** * Name: net_bufpool_timedalloc * @@ -95,6 +101,12 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool, int ret; int i; + if (pool->nodesize < 0) + { + net_bufpool_init(pool); + DEBUGASSERT(pool->nodesize > 0); + } + ret = net_sem_timedwait_uninterruptible(&pool->sem, timeout); if (ret != OK) { @@ -138,6 +150,8 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool, void net_bufpool_free(FAR struct net_bufpool_s *pool, FAR void *node) { + DEBUGASSERT(pool->nodesize > 0); + if (pool->dynalloc == 1 && ((FAR char *)node < pool->pool || (FAR char *)node >= pool->pool + pool->prealloc * pool->nodesize)) diff --git a/net/utils/utils.h b/net/utils/utils.h index 81080d7947..66059ddfec 100644 --- a/net/utils/utils.h +++ b/net/utils/utils.h @@ -94,11 +94,11 @@ pool##_buffer[0], \ prealloc, \ dynalloc, \ - nodesize, \ - SEM_INITIALIZER(NET_BUFPOOL_MAX(prealloc, dynalloc, maxalloc)) \ + -(int)(nodesize), \ + SEM_INITIALIZER(NET_BUFPOOL_MAX(prealloc, dynalloc, maxalloc)), \ + { NULL, NULL } \ }; -#define NET_BUFPOOL_INIT(p) net_bufpool_init(&p) #define NET_BUFPOOL_TIMEDALLOC(p,t) net_bufpool_timedalloc(&p, t) #define NET_BUFPOOL_TRYALLOC(p) net_bufpool_timedalloc(&p, 0) #define NET_BUFPOOL_ALLOC(p) net_bufpool_timedalloc(&p, UINT_MAX) @@ -125,9 +125,9 @@ struct net_bufpool_s /* Allocation configuration */ FAR char *pool; /* The beginning of the pre-allocated buffer pool */ - const int prealloc; /* The number of pre-allocated buffers */ - const int dynalloc; /* The number per dynamic allocations */ - const int nodesize; /* The size of each node in the pool */ + int prealloc; /* The number of pre-allocated buffers */ + int dynalloc; /* The number per dynamic allocations */ + int nodesize; /* The size of each node in the pool */ sem_t sem; /* The semaphore for waiting for free buffers */ @@ -367,19 +367,6 @@ FAR void *net_ipv6_payload(FAR struct ipv6_hdr_s *ipv6, FAR uint8_t *proto); uint16_t net_iob_concat(FAR struct iob_s **iob1, FAR struct iob_s **iob2); #endif -/**************************************************************************** - * Name: net_bufpool_init - * - * Description: - * Initialize a network buffer pool. - * - * Input Parameters: - * pool - The pool to be initialized - * - ****************************************************************************/ - -void net_bufpool_init(FAR struct net_bufpool_s *pool); - /**************************************************************************** * Name: net_bufpool_timedalloc *