529 |
*/ |
*/ |
530 |
SYS_ARCH_PROTECT(old_level); |
SYS_ARCH_PROTECT(old_level); |
531 |
/* de-allocate all consecutive pbufs from the head of the chain that |
/* de-allocate all consecutive pbufs from the head of the chain that |
532 |
* obtain a zero reference count */ |
* obtain a zero reference count after decrementing*/ |
533 |
while (p != NULL) { |
while (p != NULL) { |
534 |
/* all pbufs in a chain are referenced at least once */ |
/* all pbufs in a chain are referenced at least once */ |
535 |
LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0); |
LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0); |
536 |
|
/* decrease reference count (number of pointers to pbuf) */ |
537 |
p->ref--; |
p->ref--; |
538 |
/* this pbuf is no longer referenced to? */ |
/* this pbuf is no longer referenced to? */ |
539 |
if (p->ref == 0) { |
if (p->ref == 0) { |
544 |
p->len = p->tot_len = PBUF_POOL_BUFSIZE; |
p->len = p->tot_len = PBUF_POOL_BUFSIZE; |
545 |
p->payload = (void *)((u8_t *)p + sizeof(struct pbuf)); |
p->payload = (void *)((u8_t *)p + sizeof(struct pbuf)); |
546 |
PBUF_POOL_FREE(p); |
PBUF_POOL_FREE(p); |
547 |
/* a RAM/ROM referencing pbuf */ |
/* a ROM or RAM referencing pbuf */ |
548 |
} else if (p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) { |
} else if (p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) { |
549 |
memp_freep(MEMP_PBUF, p); |
memp_freep(MEMP_PBUF, p); |
550 |
/* pbuf with data */ |
/* p->flags == PBUF_FLAG_RAM */ |
551 |
} else { |
} else { |
552 |
mem_free(p); |
mem_free(p); |
553 |
} |
} |
555 |
/* proceed to next pbuf */ |
/* proceed to next pbuf */ |
556 |
p = q; |
p = q; |
557 |
/* p->ref > 0, this pbuf is still referenced to */ |
/* p->ref > 0, this pbuf is still referenced to */ |
558 |
/* (so the remaining pbufs in chain as well) */ |
/* (and so the remaining pbufs in chain as well) */ |
559 |
} else { |
} else { |
560 |
/* stop walking through chain */ |
/* stop walking through chain */ |
561 |
p = NULL; |
p = NULL; |