/[lwip]/lwip/src/core/pbuf.c
ViewVC logotype

Diff of /lwip/src/core/pbuf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by davidhaas, Thu Feb 6 22:18:56 2003 UTC revision 1.14 by davidhaas, Wed Feb 12 22:00:18 2003 UTC
# Line 117  pbuf_pool_alloc(void) Line 117  pbuf_pool_alloc(void)
117  {  {
118    struct pbuf *p = NULL;    struct pbuf *p = NULL;
119    
120  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_DECL_PROTECT(old_level);
121    u32_t old_level;    SYS_ARCH_PROTECT(old_level);
   
   old_level = sys_arch_protect();  
 #endif /* SYS_LIGHTWEIGHT_PROT */  
     
122    /* First, see if there are pbufs in the cache. */    /* First, see if there are pbufs in the cache. */
123    if(pbuf_pool_alloc_cache) {    if(pbuf_pool_alloc_cache) {
124      p = pbuf_pool_alloc_cache;      p = pbuf_pool_alloc_cache;
# Line 165  pbuf_pool_alloc(void) Line 161  pbuf_pool_alloc(void)
161    }    }
162  #endif /* PBUF_STATS */  #endif /* PBUF_STATS */
163    
164  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_UNPROTECT(old_level);
   sys_arch_unprotect(old_level);  
 #endif /* SYS_LIGHTWEIGHT_PROT */    
   
165    return p;      return p;  
166  }  }
167  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
# Line 176  static void Line 169  static void
169  pbuf_pool_free(struct pbuf *p)  pbuf_pool_free(struct pbuf *p)
170  {  {
171    struct pbuf *q;    struct pbuf *q;
172  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_DECL_PROTECT(old_level);
173    u32_t old_level;    SYS_ARCH_PROTECT(old_level);
 #endif /* SYS_LIGHTWEIGHT_PROT */  
     
   
 #ifdef SYS_LIGHTWEIGHT_PROT  
     old_level = sys_arch_protect();  
 #endif /* SYS_LIGHTWEIGHT_PROT */  
174    
175  #ifdef PBUF_STATS  #ifdef PBUF_STATS
176      for(q = p; q != NULL; q = q->next) {      for(q = p; q != NULL; q = q->next) {
# Line 197  pbuf_pool_free(struct pbuf *p) Line 184  pbuf_pool_free(struct pbuf *p)
184      for(q = pbuf_pool_alloc_cache; q->next != NULL; q = q->next);      for(q = pbuf_pool_alloc_cache; q->next != NULL; q = q->next);
185      q->next = p;          q->next = p;    
186    }    }
187  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_UNPROTECT(old_level);
   sys_arch_unprotect(old_level);  
 #endif /* SYS_LIGHTWEIGHT_PROT */    
188  }  }
189  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
190  /* pbuf_alloc():  /* pbuf_alloc():
# Line 343  void Line 328  void
328  pbuf_refresh(void)  pbuf_refresh(void)
329  {  {
330    struct pbuf *p;    struct pbuf *p;
331  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_DECL_PROTECT(old_level);
332    u32_t old_level;    SYS_ARCH_PROTECT(old_level);
333    
334    old_level = sys_arch_protect();  #ifndef SYS_LIGHTWEIGHT_PROT
 #else /* SYS_LIGHTWEIGHT_PROT */    
335    sys_sem_wait(pbuf_pool_free_sem);    sys_sem_wait(pbuf_pool_free_sem);
336  #endif /* else SYS_LIGHTWEIGHT_PROT */  #endif /* else SYS_LIGHTWEIGHT_PROT */
337        
# Line 373  pbuf_refresh(void) Line 357  pbuf_refresh(void)
357      pbuf_pool_free_lock = 0;      pbuf_pool_free_lock = 0;
358  #endif /* SYS_LIGHTWEIGHT_PROT */      #endif /* SYS_LIGHTWEIGHT_PROT */    
359    }    }
360  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_UNPROTECT(old_level);
361    sys_arch_unprotect(old_level);  #ifndef SYS_LIGHTWEIGHT_PROT      
 #else  /* SYS_LIGHTWEIGHT_PROT */  
362    sys_sem_signal(pbuf_pool_free_sem);    sys_sem_signal(pbuf_pool_free_sem);
363  #endif /* SYS_LIGHTWEIGHT_PROT */    #endif /* SYS_LIGHTWEIGHT_PROT */  
364  }  }
# Line 393  pbuf_refresh(void) Line 376  pbuf_refresh(void)
376                                  } while (0)                                  } while (0)
377    
378  #ifdef SYS_LIGHTWEIGHT_PROT  #ifdef SYS_LIGHTWEIGHT_PROT
379  #define PBUF_POOL_FREE(p)  do {                                                 \  #define PBUF_POOL_FREE(p)  do {                                         \
380                               u32_t old_level = sys_arch_protect();        \                                  SYS_ARCH_DECL_PROTECT(old_level);       \
381                               PBUF_POOL_FAST_FREE(p);                            \                                  SYS_ARCH_PROTECT(old_level);            \
382                               sys_arch_unprotect(old_level);                 \                                  PBUF_POOL_FAST_FREE(p);                 \
383                             } while(0)                                  SYS_ARCH_UNPROTECT(old_level);          \
384                                   } while(0)
385  #else /* SYS_LIGHTWEIGHT_PROT */  #else /* SYS_LIGHTWEIGHT_PROT */
386  #define PBUF_POOL_FREE(p)  do {                                         \  #define PBUF_POOL_FREE(p)  do {                                         \
387                               sys_sem_wait(pbuf_pool_free_sem);          \                               sys_sem_wait(pbuf_pool_free_sem);          \
# Line 536  pbuf_free(struct pbuf *p) Line 520  pbuf_free(struct pbuf *p)
520  {  {
521    struct pbuf *q;    struct pbuf *q;
522    u8_t count = 0;    u8_t count = 0;
523  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_DECL_PROTECT(old_level);
   u32_t old_level;  
 #endif /* SYS_LIGHTWEIGHT_PROT */  
524        
525    if(p == NULL) {    if(p == NULL) {
526      return 0;      return 0;
# Line 552  pbuf_free(struct pbuf *p) Line 534  pbuf_free(struct pbuf *p)
534        
535    LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);    LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
536    
 #ifdef SYS_LIGHTWEIGHT_PROT  
537    /* Since decrementing ref cannot be guarranteed to be a single machine operation    /* Since decrementing ref cannot be guarranteed to be a single machine operation
538       we must protect it. Also, the later test of ref must be protected.       we must protect it. Also, the later test of ref must be protected.
539    */    */
540    old_level = sys_arch_protect();    SYS_ARCH_PROTECT(old_level);
 #endif /* SYS_LIGHTWEIGHT_PROT */    
541    /* Decrement reference count. */      /* Decrement reference count. */  
542    p->ref--;    p->ref--;
543    
544    /*q = NULL;           DJH: Unnecessary statement*/    /*q = NULL;           DJH: Unnecessary statement*/
545    /* If reference count == 0, actually deallocate pbuf. */    /* If reference count == 0, actually deallocate pbuf. */
546    if(p->ref == 0) {    if(p->ref == 0) {
547  #ifdef SYS_LIGHTWEIGHT_PROT        SYS_ARCH_UNPROTECT(old_level);
       sys_arch_unprotect(old_level);  
 #endif      
548                
549      while(p != NULL) {        while(p != NULL) {
550        /* Check if this is a pbuf from the pool. */            /* Check if this is a pbuf from the pool. */
551        if(p->flags == PBUF_FLAG_POOL) {            if(p->flags == PBUF_FLAG_POOL) {
552          p->len = p->tot_len = PBUF_POOL_BUFSIZE;                p->len = p->tot_len = PBUF_POOL_BUFSIZE;
553          p->payload = (void *)((u8_t *)p + sizeof(struct pbuf));                p->payload = (void *)((u8_t *)p + sizeof(struct pbuf));
         q = p->next;  
         PBUF_POOL_FREE(p);  
       } else {  
           if(p->flags == PBUF_FLAG_ROM) {  
554                q = p->next;                q = p->next;
555                memp_freep(MEMP_PBUF, p);                PBUF_POOL_FREE(p);
556            } else {            } else {
557                q = p->next;                if(p->flags == PBUF_FLAG_ROM) {
558                mem_free(p);                    q = p->next;
559                      memp_freep(MEMP_PBUF, p);
560                  } else {
561                      q = p->next;
562                      mem_free(p);
563                  }
564            }            }
565              
566              p = q;
567              ++count;
568        }        }
569                pbuf_refresh();
       p = q;  
       ++count;  
     }  
     pbuf_refresh();  
570    }    }
 #ifdef SYS_LIGHTWEIGHT_PROT  
571    else    else
572        sys_arch_unprotect(old_level);        SYS_ARCH_UNPROTECT(old_level);
 #endif /* SYS_LIGHTWEIGHT_PROT */    
573    
574    PERF_STOP("pbuf_free");    PERF_STOP("pbuf_free");
575        
# Line 628  pbuf_clen(struct pbuf *p) Line 604  pbuf_clen(struct pbuf *p)
604  void  void
605  pbuf_ref(struct pbuf *p)  pbuf_ref(struct pbuf *p)
606  {  {
607  #ifdef SYS_LIGHTWEIGHT_PROT      SYS_ARCH_DECL_PROTECT(old_level);
     u32_t old_level;  
 #endif /* SYS_LIGHTWEIGHT_PROT */  
608            
609    if(p == NULL) {    if(p == NULL) {
610      return;      return;
611    }    }
612    
613  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_PROTECT(old_level);
   old_level = sys_arch_protect();  
 #endif /* SYS_LIGHTWEIGHT_PROT */    
614    ++(p->ref);    ++(p->ref);
615  #ifdef SYS_LIGHTWEIGHT_PROT    SYS_ARCH_UNPROTECT(old_level);
   sys_arch_unprotect(old_level);  
 #endif /* SYS_LIGHTWEIGHT_PROT */    
616  }  }
617    
618  /*------------------------------------------------------------------------------*/  /*------------------------------------------------------------------------------*/
# Line 653  pbuf_ref(struct pbuf *p) Line 623  pbuf_ref(struct pbuf *p)
623  void  void
624  pbuf_ref_chain(struct pbuf *p)  pbuf_ref_chain(struct pbuf *p)
625  {  {
626  #ifdef SYS_LIGHTWEIGHT_PROT      SYS_ARCH_DECL_PROTECT(old_level);
627      u32_t old_level = sys_arch_protect();      SYS_ARCH_PROTECT(old_level);
 #endif /* SYS_LIGHTWEIGHT_PROT */  
628            
629    while (p != NULL) {      while (p != NULL) {
630      p->ref++;          p->ref++;
631      p=p->next;          p=p->next;
632    }      }
633    
634  #ifdef SYS_LIGHTWEIGHT_PROT      SYS_ARCH_UNPROTECT(old_level);
   sys_arch_unprotect(old_level);  
 #endif /* SYS_LIGHTWEIGHT_PROT */    
635  }  }
636  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
637  /* pbuf_chain():  /* pbuf_chain():

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26