Index: core/dhcp.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/dhcp.c,v
retrieving revision 1.65
diff -u -r1.65 dhcp.c
--- core/dhcp.c	4 Apr 2007 19:54:23 -0000	1.65
+++ core/dhcp.c	11 Apr 2007 18:31:22 -0000
@@ -89,6 +89,12 @@
  *  with this value (easy to match with a packet analyzer) */
 static u32_t xid = 0xABCD0000;
 
+#if LWIP_DHCP_AUTOTIMER
+/* global counter of netifs with active dhcp.
+   if this counter is 0, dhcp timers are not needed. */
+static u8_t dhcp_count = 0;
+#endif /* LWIP_DHCP_AUTOTIMER */
+
 /** DHCP client state machine functions */
 static void dhcp_handle_ack(struct netif *netif);
 static void dhcp_handle_nak(struct netif *netif);
@@ -132,6 +138,36 @@
 /** always add the DHCP options trailer to end and pad */
 static void dhcp_option_trailer(struct dhcp *dhcp);
 
+#if LWIP_DHCP_AUTOTIMER
+static void dhcp_autotimer_coarse(void *arg)
+{
+  dhcp_coarse_tmr();
+  if (dhcp_count > 0) {
+    sys_timeout(DHCP_COARSE_TIMER_SECS*1000, dhcp_autotimer_coarse, NULL);
+  }
+}
+
+static void dhcp_autotimer_fine(void *arg)
+{
+  dhcp_fine_tmr();
+  if (dhcp_count > 0) {
+    sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_autotimer_fine, NULL);
+  }
+}
+
+static void dhcp_start_timers()
+{
+  sys_timeout(DHCP_COARSE_TIMER_SECS*1000, dhcp_autotimer_coarse, NULL);
+  sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_autotimer_fine, NULL);
+}
+
+static void dhcp_stop_timers()
+{
+  sys_untimeout(dhcp_autotimer_coarse, NULL);
+  sys_untimeout(dhcp_autotimer_fine, NULL);
+}
+#endif /* LWIP_DHCP_AUTOTIMER */
+
 /**
  * Back-off the DHCP client (because of a received NAK response).
  *
@@ -537,6 +573,9 @@
 {
   struct dhcp *dhcp = netif->dhcp;
   err_t result = ERR_OK;
+#if LWIP_DHCP_AUTOTIMER
+  int new_active = 0;
+#endif /* LWIP_DHCP_AUTOTIMER */
 
   LWIP_ASSERT("netif != NULL", netif != NULL);
   LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
@@ -553,6 +592,10 @@
     /* store this dhcp client in the netif */
     netif->dhcp = dhcp;
     LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp"));
+#if LWIP_DHCP_AUTOTIMER
+    /* dhcp newly started -> start timers */
+    new_active = 1;
+#endif /* LWIP_DHCP_AUTOTIMER */
   /* already has DHCP client attached */
   } else {
     LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | 3, ("dhcp_start(): restarting DHCP configuration\n"));
@@ -577,6 +620,15 @@
     return ERR_MEM;
   }
   netif->flags |= NETIF_FLAG_DHCP;
+#if LWIP_DHCP_AUTOTIMER
+  if (new_active != 0) {
+    dhcp_count++;
+    if (dhcp_count == 1) {
+      /* the first interface with dhcp active -> start the timers */
+      dhcp_start_timers();
+    }
+  }
+#endif /* LWIP_DHCP_AUTOTIMER */
   return result;
 }
 
@@ -1022,6 +1074,13 @@
   /* netif is DHCP configured? */
   if (dhcp != NULL)
   {
+#if LWIP_DHCP_AUTOTIMER
+    dhcp_count--;
+    if (dhcp_count == 0) {
+      /* the first interface with dhcp active -> start the timers */
+      dhcp_stop_timers();
+    }
+#endif /* LWIP_DHCP_AUTOTIMER */
     if (dhcp->pcb != NULL)
     {
       udp_remove(dhcp->pcb);
Index: core/pbuf.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/pbuf.c,v
retrieving revision 1.91
diff -u -r1.91 pbuf.c
--- core/pbuf.c	17 Apr 2007 17:48:35 -0000	1.91
+++ core/pbuf.c	19 Apr 2007 18:22:09 -0000
@@ -75,11 +75,6 @@
 
 static u8_t pbuf_pool_memory[MEM_ALIGNMENT - 1 + PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE + sizeof(struct pbuf))];
 
-#if !SYS_LIGHTWEIGHT_PROT
-static volatile u8_t pbuf_pool_free_lock, pbuf_pool_alloc_lock;
-static sys_sem_t pbuf_pool_free_sem;
-#endif
-
 static struct pbuf *pbuf_pool = NULL;
 
 /**
@@ -127,11 +122,6 @@
      are no more pbufs in the pool */
   q->next = NULL;
 
-#if !SYS_LIGHTWEIGHT_PROT
-  pbuf_pool_alloc_lock = 0;
-  pbuf_pool_free_lock = 0;
-  pbuf_pool_free_sem = sys_sem_new(1);
-#endif
 }
 
 /**
@@ -145,30 +135,10 @@
   SYS_ARCH_DECL_PROTECT(old_level);
   SYS_ARCH_PROTECT(old_level);
 
-#if !SYS_LIGHTWEIGHT_PROT
-  /* Next, check the actual pbuf pool, but if the pool is locked, we
-     pretend to be out of buffers and return NULL. */
-  if (pbuf_pool_free_lock) {
-#if PBUF_STATS
-    ++lwip_stats.pbuf.alloc_locked;
-#endif /* PBUF_STATS */
-    return NULL;
-  }
-  pbuf_pool_alloc_lock = 1;
-  if (!pbuf_pool_free_lock) {
-#endif /* SYS_LIGHTWEIGHT_PROT */
-    p = pbuf_pool;
-    if (p) {
-      pbuf_pool = p->next;
-    }
-#if !SYS_LIGHTWEIGHT_PROT
-#if PBUF_STATS
-  } else {
-    ++lwip_stats.pbuf.alloc_locked;
-#endif /* PBUF_STATS */
+  p = pbuf_pool;
+  if (p) {
+    pbuf_pool = p->next;
   }
-  pbuf_pool_alloc_lock = 0;
-#endif /* SYS_LIGHTWEIGHT_PROT */
 
 #if PBUF_STATS
   if (p != NULL) {
@@ -176,6 +146,8 @@
     if (lwip_stats.pbuf.used > lwip_stats.pbuf.max) {
       lwip_stats.pbuf.max = lwip_stats.pbuf.used;
     }
+  } else {
+    ++lwip_stats.pbuf.err;
   }
 #endif /* PBUF_STATS */
 
@@ -249,9 +221,6 @@
     p = pbuf_pool_alloc();
     LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE | 3, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
     if (p == NULL) {
-#if PBUF_STATS
-      ++lwip_stats.pbuf.err;
-#endif /* PBUF_STATS */
       return NULL;
     }
     p->next = NULL;
@@ -278,9 +247,6 @@
       q = pbuf_pool_alloc();
       if (q == NULL) {
        LWIP_DEBUGF(PBUF_DEBUG | 2, ("pbuf_alloc: Out of pbufs in pool.\n"));
-#if PBUF_STATS
-        ++lwip_stats.pbuf.err;
-#endif /* PBUF_STATS */
         /* free chain so far allocated */
         pbuf_free(p);
         /* bail out unsuccesfully */
@@ -348,33 +314,6 @@
 }
 
 
-#if PBUF_STATS
-#define DEC_PBUF_STATS do { --lwip_stats.pbuf.used; } while (0)
-#else /* PBUF_STATS */
-#define DEC_PBUF_STATS
-#endif /* PBUF_STATS */
-
-#define PBUF_POOL_FAST_FREE(p)  do {                                    \
-                                  p->next = pbuf_pool;                  \
-                                  pbuf_pool = p;                        \
-                                  DEC_PBUF_STATS;                       \
-                                } while (0)
-
-#if SYS_LIGHTWEIGHT_PROT
-#define PBUF_POOL_FREE(p)  do {                                         \
-                                SYS_ARCH_DECL_PROTECT(old_level);       \
-                                SYS_ARCH_PROTECT(old_level);            \
-                                PBUF_POOL_FAST_FREE(p);                 \
-                                SYS_ARCH_UNPROTECT(old_level);          \
-                               } while (0)
-#else /* SYS_LIGHTWEIGHT_PROT */
-#define PBUF_POOL_FREE(p)  do {                                         \
-                             sys_sem_wait(pbuf_pool_free_sem);          \
-                             PBUF_POOL_FAST_FREE(p);                    \
-                             sys_sem_signal(pbuf_pool_free_sem);        \
-                           } while (0)
-#endif /* SYS_LIGHTWEIGHT_PROT */
-
 /**
  * Shrink a pbuf chain to a desired length.
  *
@@ -617,7 +556,12 @@
       if (flags == PBUF_FLAG_POOL) {
         p->len = p->tot_len = PBUF_POOL_BUFSIZE;
         p->payload = (void *)((u8_t *)p + sizeof(struct pbuf));
-        PBUF_POOL_FREE(p);
+        /* put p at the front of the pool */
+        p->next = pbuf_pool;
+        pbuf_pool = p;
+#if PBUF_STATS
+        --lwip_stats.pbuf.used;
+#endif
       /* is this a ROM or RAM referencing pbuf? */
       } else if (flags == PBUF_FLAG_ROM || flags == PBUF_FLAG_REF) {
         memp_free(MEMP_PBUF, p);
Index: core/stats.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/stats.c,v
retrieving revision 1.16
diff -u -r1.16 stats.c
--- core/stats.c	22 Mar 2007 16:36:45 -0000	1.16
+++ core/stats.c	19 Apr 2007 18:23:17 -0000
@@ -76,8 +76,6 @@
   LWIP_PLATFORM_DIAG(("used: %"STAT_COUNTER_F"\n\t", pbuf->used)); 
   LWIP_PLATFORM_DIAG(("max: %"STAT_COUNTER_F"\n\t", pbuf->max)); 
   LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", pbuf->err)); 
-  LWIP_PLATFORM_DIAG(("alloc_locked: %"STAT_COUNTER_F"\n\t", pbuf->alloc_locked)); 
-  LWIP_PLATFORM_DIAG(("refresh_locked: %"STAT_COUNTER_F"\n", pbuf->refresh_locked));  
 }
 
 void
Index: include/lwip/stats.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/lwip/stats.h,v
retrieving revision 1.12
diff -u -r1.12 stats.h
--- include/lwip/stats.h	22 Mar 2007 16:36:46 -0000	1.12
+++ include/lwip/stats.h	19 Apr 2007 18:22:22 -0000
@@ -80,9 +80,6 @@
   STAT_COUNTER used;
   STAT_COUNTER max;  
   STAT_COUNTER err;
-
-  STAT_COUNTER alloc_locked;
-  STAT_COUNTER refresh_locked;
 };
 
 struct stats_syselem {
