mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-12-10 08:46:40 +08:00
only set pbuf pool flag once at pool init not at every allocation. Correct some comments
This commit is contained in:
parent
fbc0ce9214
commit
ceb956140e
@ -113,6 +113,7 @@ pbuf_init(void)
|
|||||||
p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
|
p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
|
||||||
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
|
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
|
||||||
p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf)));
|
p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf)));
|
||||||
|
p->flags = PBUF_FLAG_POOL;
|
||||||
q = p;
|
q = p;
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
@ -258,8 +259,6 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
|
|||||||
p->tot_len = length;
|
p->tot_len = length;
|
||||||
/* set the length of the first pbuf in the chain */
|
/* set the length of the first pbuf in the chain */
|
||||||
p->len = length > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: length;
|
p->len = length > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: length;
|
||||||
/* set pbuf type */
|
|
||||||
p->flags = PBUF_FLAG_POOL;
|
|
||||||
/* set reference count (needed here in case we fail) */
|
/* set reference count (needed here in case we fail) */
|
||||||
p->ref = 1;
|
p->ref = 1;
|
||||||
|
|
||||||
@ -289,7 +288,6 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
|
|||||||
q->tot_len = rem_len;
|
q->tot_len = rem_len;
|
||||||
/* this pbuf length is pool size, unless smaller sized tail */
|
/* this pbuf length is pool size, unless smaller sized tail */
|
||||||
q->len = rem_len > PBUF_POOL_BUFSIZE? PBUF_POOL_BUFSIZE: rem_len;
|
q->len = rem_len > PBUF_POOL_BUFSIZE? PBUF_POOL_BUFSIZE: rem_len;
|
||||||
q->flags = PBUF_FLAG_POOL;
|
|
||||||
q->payload = (void *)((u8_t *)q + sizeof(struct pbuf));
|
q->payload = (void *)((u8_t *)q + sizeof(struct pbuf));
|
||||||
LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
|
LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
|
||||||
((u32_t)q->payload % MEM_ALIGNMENT) == 0);
|
((u32_t)q->payload % MEM_ALIGNMENT) == 0);
|
||||||
@ -412,7 +410,7 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
|
|||||||
/* first, step over any pbufs that should remain in the chain */
|
/* first, step over any pbufs that should remain in the chain */
|
||||||
rem_len = new_len;
|
rem_len = new_len;
|
||||||
q = p;
|
q = p;
|
||||||
/* this pbuf should be kept? */
|
/* should this pbuf be kept? */
|
||||||
while (rem_len > q->len) {
|
while (rem_len > q->len) {
|
||||||
/* decrease remaining length by pbuf length */
|
/* decrease remaining length by pbuf length */
|
||||||
rem_len -= q->len;
|
rem_len -= q->len;
|
||||||
@ -511,9 +509,9 @@ pbuf_header(struct pbuf *p, s16_t header_size)
|
|||||||
* Decrements the pbuf reference count. If it reaches
|
* Decrements the pbuf reference count. If it reaches
|
||||||
* zero, the pbuf is deallocated.
|
* zero, the pbuf is deallocated.
|
||||||
*
|
*
|
||||||
* For a pbuf chain, this is repeated for each pbuf in the chain, until
|
* For a pbuf chain, this is repeated for each pbuf in the chain, up to the
|
||||||
* a non-zero reference count is encountered, or the end of the chain is
|
* pbuf which has a non-zero reference count after decrementing.
|
||||||
* reached.
|
* (This might be the whole chain.)
|
||||||
*
|
*
|
||||||
* @param pbuf pbuf (chain) to be freed from one user.
|
* @param pbuf pbuf (chain) to be freed from one user.
|
||||||
*
|
*
|
||||||
@ -670,7 +668,7 @@ pbuf_chain(struct pbuf *h, struct pbuf *t)
|
|||||||
LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len);
|
LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len);
|
||||||
/* add total length of second chain to last pbuf total of first chain */
|
/* add total length of second chain to last pbuf total of first chain */
|
||||||
p->tot_len += t->tot_len;
|
p->tot_len += t->tot_len;
|
||||||
/* chain last pbuf of h chain (p) with first of tail (t) */
|
/* chain last pbuf of head (p) with first of tail (t) */
|
||||||
p->next = t;
|
p->next = t;
|
||||||
/* t is now referenced to one more time */
|
/* t is now referenced to one more time */
|
||||||
pbuf_ref(t);
|
pbuf_ref(t);
|
||||||
@ -711,9 +709,9 @@ pbuf_queue(struct pbuf *p, struct pbuf *n)
|
|||||||
/* proceed to next packet on queue */
|
/* proceed to next packet on queue */
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
/* chain last pbuf of h chain (p) with first of tail (t) */
|
/* chain last pbuf of queue with n */
|
||||||
p->next = n;
|
p->next = n;
|
||||||
/* t is now referenced to one more time */
|
/* n is now referenced to one more time */
|
||||||
pbuf_ref(n);
|
pbuf_ref(n);
|
||||||
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_queue: referencing queued packet %p\n", (void *)n));
|
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_queue: referencing queued packet %p\n", (void *)n));
|
||||||
}
|
}
|
||||||
@ -764,7 +762,7 @@ pbuf_dequeue(struct pbuf *p)
|
|||||||
* by pbuf_take()!
|
* by pbuf_take()!
|
||||||
*
|
*
|
||||||
* @note Any replaced pbufs will be freed through pbuf_free().
|
* @note Any replaced pbufs will be freed through pbuf_free().
|
||||||
* This may allocate them if they become no longer referenced.
|
* This may deallocate them if they become no longer referenced.
|
||||||
*
|
*
|
||||||
* @param p Head of pbuf chain to process
|
* @param p Head of pbuf chain to process
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user