From 3b74613f636d3a08f12f4c3110ee4a5b46ecdb0b Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 14 Jul 2010 03:30:43 +0000 Subject: Fix preallocation logic git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2798 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/net/uip/uip_igmpgroup.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'nuttx') diff --git a/nuttx/net/uip/uip_igmpgroup.c b/nuttx/net/uip/uip_igmpgroup.c index 8b5398aac..495713e30 100755 --- a/nuttx/net/uip/uip_igmpgroup.c +++ b/nuttx/net/uip/uip_igmpgroup.c @@ -119,8 +119,10 @@ * handling logic. */ +#if CONFIG_PREALLOC_IGMPGROUPS > 0 static struct igmp_group_s g_preallocgrps[CONFIG_PREALLOC_IGMPGROUPS]; static FAR sq_queue_t g_freelist; +#endif /**************************************************************************** * Public Data @@ -158,6 +160,7 @@ static inline FAR struct igmp_group_s *uip_grpheapalloc(void) * ****************************************************************************/ +#if CONFIG_PREALLOC_IGMPGROUPS > 0 static inline FAR struct igmp_group_s *uip_grpprealloc(void) { FAR struct igmp_group_s *group = (FAR struct igmp_group_s *)sq_remfirst(&g_freelist); @@ -168,6 +171,7 @@ static inline FAR struct igmp_group_s *uip_grpprealloc(void) } return group; } +#endif /**************************************************************************** * Public Functions @@ -191,11 +195,13 @@ void uip_grpinit(void) grplldbg("Initializing\n"); +#if CONFIG_PREALLOC_IGMPGROUPS > 0 for (i = 0; i < CONFIG_PREALLOC_IGMPGROUPS; i++) { group = &g_preallocgrps[i]; sq_addfirst((FAR sq_entry_t *)group, &g_freelist); } +#endif } /**************************************************************************** @@ -216,15 +222,17 @@ FAR struct igmp_group_s *uip_grpalloc(FAR struct uip_driver_s *dev, irqstate_t flags; nllvdbg("addr: %08x dev: %p\n", *addr, dev); +#if CONFIG_PREALLOC_IGMPGROUPS > 0 if (up_interrupt_context()) { - grplldbg("Allocate from the heap\n"); - group = uip_grpheapalloc(); + grplldbg("Use a pre-allocated group entry\n"); + group = uip_grpprealloc(); } else +#endif { - grplldbg("Use a pre-allocated group entry\n"); - group = uip_grpprealloc(); + grplldbg("Allocate from the heap\n"); + group = uip_grpheapalloc(); } grplldbg("group: %p\n", group); @@ -357,6 +365,7 @@ void uip_grpfree(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group) * of the pre-allocated group structures that we will retain in a free list. */ +#if CONFIG_PREALLOC_IGMPGROUPS > 0 if (IS_PREALLOCATED(group->flags)) { grplldbg("Put back on free list\n"); @@ -364,6 +373,7 @@ void uip_grpfree(FAR struct uip_driver_s *dev, FAR struct igmp_group_s *group) irqrestore(flags); } else +#endif { /* No.. deallocate the group structure. Use sched_free() just in case * this function is executing within an interrupt handler. -- cgit v1.2.3