1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #4771 from Yonezawa-T2/rbuf_gc_improvement

rbuf: does not remove oldest entry if we have entry for current fragment
This commit is contained in:
Martine Lenders 2016-03-04 05:40:00 +01:00
commit 4504e40fe0

View File

@ -248,15 +248,12 @@ static bool _rbuf_update_ints(rbuf_t *entry, uint16_t offset, size_t frag_size)
static void _rbuf_gc(void)
{
rbuf_t *oldest = NULL;
uint32_t now_usec = xtimer_now();
unsigned int i;
for (i = 0; i < RBUF_SIZE; i++) {
if (rbuf[i].pkt == NULL) { /* leave GC early if there is still room */
return;
}
else if ((rbuf[i].pkt != NULL) &&
/* since pkt occupies pktbuf, aggressivly collect garbage */
if ((rbuf[i].pkt != NULL) &&
((now_usec - rbuf[i].arrival) > RBUF_TIMEOUT)) {
DEBUG("6lo rfrag: entry (%s, ", gnrc_netif_addr_to_str(l2addr_str,
sizeof(l2addr_str), rbuf[i].src, rbuf[i].src_len));
@ -268,15 +265,6 @@ static void _rbuf_gc(void)
gnrc_pktbuf_release(rbuf[i].pkt);
_rbuf_rem(&(rbuf[i]));
}
else if ((oldest == NULL) || ((oldest->arrival - rbuf[i].arrival) < (UINT32_MAX / 2))) {
oldest = &(rbuf[i]);
}
}
if ((i >= RBUF_SIZE) && (oldest != NULL) && (oldest->pkt != NULL)) {
DEBUG("6lo rfrag: reassembly buffer full, remove oldest entry\n");
gnrc_pktbuf_release(oldest->pkt);
_rbuf_rem(oldest);
}
}
@ -284,7 +272,7 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len,
const void *dst, size_t dst_len,
size_t size, uint16_t tag)
{
rbuf_t *res = NULL;
rbuf_t *res = NULL, *oldest = NULL;
uint32_t now_usec = xtimer_now();
for (unsigned int i = 0; i < RBUF_SIZE; i++) {
@ -309,9 +297,26 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len,
if ((res == NULL) && (rbuf[i].pkt == NULL)) {
res = &(rbuf[i]);
}
/* remember oldest slot */
/* note that xtimer_now will overflow in ~1.2 hours */
if ((oldest == NULL) || (oldest->arrival - rbuf[i].arrival < UINT32_MAX / 2)) {
oldest = &(rbuf[i]);
}
}
if (res != NULL) { /* entry not in buffer but found empty spot */
/* entry not in buffer and no empty spot found */
if (res == NULL) {
assert(oldest != NULL);
assert(oldest->pkt != NULL); /* if oldest->pkt == NULL, res must not be NULL */
DEBUG("6lo rfrag: reassembly buffer full, remove oldest entry\n");
gnrc_pktbuf_release(oldest->pkt);
_rbuf_rem(oldest);
res = oldest;
}
/* now we have an empty spot */
res->pkt = gnrc_pktbuf_add(NULL, NULL, size, GNRC_NETTYPE_SIXLOWPAN);
if (res->pkt == NULL) {
DEBUG("6lo rfrag: can not allocate reassembly buffer space.\n");
@ -335,7 +340,6 @@ static rbuf_t *_rbuf_get(const void *src, size_t src_len,
gnrc_netif_addr_to_str(l2addr_str, sizeof(l2addr_str), res->dst,
res->dst_len), (unsigned)res->pkt->size,
res->tag);
}
return res;
}