Remove the unused reference queuebufs, as they only make the code more complex than it needs to be
This commit is contained in:
parent
060bc8f8d7
commit
c9c6688524
|
@ -43,18 +43,13 @@
|
|||
*/
|
||||
|
||||
#include "contiki-net.h"
|
||||
|
||||
#if WITH_SWAP
|
||||
#include "cfs/cfs.h"
|
||||
#endif
|
||||
|
||||
#include <string.h> /* for memcpy() */
|
||||
|
||||
#ifdef QUEUEBUF_CONF_REF_NUM
|
||||
#define QUEUEBUF_REF_NUM QUEUEBUF_CONF_REF_NUM
|
||||
#else
|
||||
#define QUEUEBUF_REF_NUM 2
|
||||
#endif
|
||||
|
||||
/* Structure pointing to a buffer either stored
|
||||
in RAM or swapped in CFS */
|
||||
struct queuebuf {
|
||||
|
@ -83,15 +78,7 @@ struct queuebuf_data {
|
|||
struct packetbuf_addr addrs[PACKETBUF_NUM_ADDRS];
|
||||
};
|
||||
|
||||
struct queuebuf_ref {
|
||||
uint16_t len;
|
||||
uint8_t *ref;
|
||||
uint8_t hdr[PACKETBUF_HDR_SIZE];
|
||||
uint8_t hdrlen;
|
||||
};
|
||||
|
||||
MEMB(bufmem, struct queuebuf, QUEUEBUF_NUM);
|
||||
MEMB(refbufmem, struct queuebuf_ref, QUEUEBUF_REF_NUM);
|
||||
MEMB(buframmem, struct queuebuf_data, QUEUEBUFRAM_NUM);
|
||||
|
||||
#if WITH_SWAP
|
||||
|
@ -144,7 +131,7 @@ LIST(queuebuf_list);
|
|||
#endif /* QUEUEBUF_CONF_STATS */
|
||||
|
||||
#if QUEUEBUF_STATS
|
||||
uint8_t queuebuf_len, queuebuf_ref_len, queuebuf_max_len;
|
||||
uint8_t queuebuf_len, queuebuf_max_len;
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
|
||||
#if WITH_SWAP
|
||||
|
@ -301,21 +288,16 @@ queuebuf_init(void)
|
|||
#endif
|
||||
memb_init(&buframmem);
|
||||
memb_init(&bufmem);
|
||||
memb_init(&refbufmem);
|
||||
#if QUEUEBUF_STATS
|
||||
queuebuf_max_len = QUEUEBUF_NUM;
|
||||
queuebuf_max_len = 0;
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
queuebuf_numfree(void)
|
||||
{
|
||||
if(packetbuf_is_reference()) {
|
||||
return memb_numfree(&refbufmem);
|
||||
} else {
|
||||
return memb_numfree(&bufmem);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if QUEUEBUF_DEBUG
|
||||
struct queuebuf *
|
||||
|
@ -326,22 +308,7 @@ queuebuf_new_from_packetbuf(void)
|
|||
#endif /* QUEUEBUF_DEBUG */
|
||||
{
|
||||
struct queuebuf *buf;
|
||||
struct queuebuf_ref *rbuf;
|
||||
|
||||
if(packetbuf_is_reference()) {
|
||||
rbuf = memb_alloc(&refbufmem);
|
||||
if(rbuf != NULL) {
|
||||
#if QUEUEBUF_STATS
|
||||
++queuebuf_ref_len;
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
rbuf->len = packetbuf_datalen();
|
||||
rbuf->ref = packetbuf_reference_ptr();
|
||||
rbuf->hdrlen = packetbuf_copyto_hdr(rbuf->hdr);
|
||||
} else {
|
||||
PRINTF("queuebuf_new_from_packetbuf: could not allocate a reference queuebuf\n");
|
||||
}
|
||||
return (struct queuebuf *)rbuf;
|
||||
} else {
|
||||
struct queuebuf_data *buframptr;
|
||||
buf = memb_alloc(&bufmem);
|
||||
if(buf != NULL) {
|
||||
|
@ -387,12 +354,9 @@ queuebuf_new_from_packetbuf(void)
|
|||
|
||||
#if QUEUEBUF_STATS
|
||||
++queuebuf_len;
|
||||
PRINTF("queuebuf len %d\n", queuebuf_len);
|
||||
printf("#A q=%d\n", queuebuf_len);
|
||||
if(queuebuf_len == queuebuf_max_len + 1) {
|
||||
queuebuf_free(buf);
|
||||
queuebuf_len--;
|
||||
return NULL;
|
||||
PRINTF("#A q=%d\n", queuebuf_len);
|
||||
if(queuebuf_len > queuebuf_max_len) {
|
||||
queuebuf_max_len = queuebuf_len;
|
||||
}
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
|
||||
|
@ -401,7 +365,6 @@ queuebuf_new_from_packetbuf(void)
|
|||
}
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
queuebuf_update_attr_from_packetbuf(struct queuebuf *buf)
|
||||
|
@ -444,47 +407,30 @@ queuebuf_free(struct queuebuf *buf)
|
|||
memb_free(&bufmem, buf);
|
||||
#if QUEUEBUF_STATS
|
||||
--queuebuf_len;
|
||||
printf("#A q=%d\n", queuebuf_len);
|
||||
PRINTF("#A q=%d\n", queuebuf_len);
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
#if QUEUEBUF_DEBUG
|
||||
list_remove(queuebuf_list, buf);
|
||||
#endif /* QUEUEBUF_DEBUG */
|
||||
} else if(memb_inmemb(&refbufmem, buf)) {
|
||||
memb_free(&refbufmem, buf);
|
||||
#if QUEUEBUF_STATS
|
||||
--queuebuf_ref_len;
|
||||
#endif /* QUEUEBUF_STATS */
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
queuebuf_to_packetbuf(struct queuebuf *b)
|
||||
{
|
||||
struct queuebuf_ref *r;
|
||||
if(memb_inmemb(&bufmem, b)) {
|
||||
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
||||
packetbuf_copyfrom(buframptr->data, buframptr->len);
|
||||
packetbuf_attr_copyfrom(buframptr->attrs, buframptr->addrs);
|
||||
} else if(memb_inmemb(&refbufmem, b)) {
|
||||
r = (struct queuebuf_ref *)b;
|
||||
packetbuf_clear();
|
||||
packetbuf_copyfrom(r->ref, r->len);
|
||||
packetbuf_hdralloc(r->hdrlen);
|
||||
memcpy(packetbuf_hdrptr(), r->hdr, r->hdrlen);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void *
|
||||
queuebuf_dataptr(struct queuebuf *b)
|
||||
{
|
||||
struct queuebuf_ref *r;
|
||||
|
||||
if(memb_inmemb(&bufmem, b)) {
|
||||
struct queuebuf_data *buframptr = queuebuf_load_to_ram(b);
|
||||
return buframptr->data;
|
||||
} else if(memb_inmemb(&refbufmem, b)) {
|
||||
r = (struct queuebuf_ref *)b;
|
||||
return r->ref;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue