mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-28 14:54:05 +00:00
By request: moved lightweight protection to macros.
This commit is contained in:
parent
4fc309b1dd
commit
de29a0818e
@ -213,7 +213,8 @@ memp_mallocp(memp_t type)
|
|||||||
{
|
{
|
||||||
void *mem;
|
void *mem;
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
#ifdef SYS_LIGHTWEIGHT_PROT
|
||||||
u32_t old_level = sys_arch_protect();
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
|
SYS_ARCH_PROTECT(old_level);
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
#else /* SYS_LIGHTWEIGHT_PROT */
|
||||||
sys_sem_wait(mutex);
|
sys_sem_wait(mutex);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
@ -221,7 +222,7 @@ memp_mallocp(memp_t type)
|
|||||||
mem = memp_malloc(type);
|
mem = memp_malloc(type);
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
#ifdef SYS_LIGHTWEIGHT_PROT
|
||||||
sys_arch_unprotect(old_level);
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
#else /* SYS_LIGHTWEIGHT_PROT */
|
||||||
sys_sem_signal(mutex);
|
sys_sem_signal(mutex);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
@ -254,7 +255,8 @@ void
|
|||||||
memp_freep(memp_t type, void *mem)
|
memp_freep(memp_t type, void *mem)
|
||||||
{
|
{
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
#ifdef SYS_LIGHTWEIGHT_PROT
|
||||||
u32_t old_level = sys_arch_protect();
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
|
SYS_ARCH_PROTECT(old_level);
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
#else /* SYS_LIGHTWEIGHT_PROT */
|
||||||
sys_sem_wait(mutex);
|
sys_sem_wait(mutex);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
@ -262,7 +264,7 @@ memp_freep(memp_t type, void *mem)
|
|||||||
memp_free(type, mem);
|
memp_free(type, mem);
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
#ifdef SYS_LIGHTWEIGHT_PROT
|
||||||
sys_arch_unprotect(old_level);
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
#else /* SYS_LIGHTWEIGHT_PROT */
|
||||||
sys_sem_signal(mutex);
|
sys_sem_signal(mutex);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
|
131
src/core/pbuf.c
131
src/core/pbuf.c
@ -117,12 +117,8 @@ pbuf_pool_alloc(void)
|
|||||||
{
|
{
|
||||||
struct pbuf *p = NULL;
|
struct pbuf *p = NULL;
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
u32_t old_level;
|
SYS_ARCH_PROTECT(old_level);
|
||||||
|
|
||||||
old_level = sys_arch_protect();
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
|
|
||||||
/* First, see if there are pbufs in the cache. */
|
/* First, see if there are pbufs in the cache. */
|
||||||
if(pbuf_pool_alloc_cache) {
|
if(pbuf_pool_alloc_cache) {
|
||||||
p = pbuf_pool_alloc_cache;
|
p = pbuf_pool_alloc_cache;
|
||||||
@ -165,10 +161,7 @@ pbuf_pool_alloc(void)
|
|||||||
}
|
}
|
||||||
#endif /* PBUF_STATS */
|
#endif /* PBUF_STATS */
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
sys_arch_unprotect(old_level);
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
@ -176,14 +169,8 @@ static void
|
|||||||
pbuf_pool_free(struct pbuf *p)
|
pbuf_pool_free(struct pbuf *p)
|
||||||
{
|
{
|
||||||
struct pbuf *q;
|
struct pbuf *q;
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
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 */
|
|
||||||
|
|
||||||
#ifdef PBUF_STATS
|
#ifdef PBUF_STATS
|
||||||
for(q = p; q != NULL; q = q->next) {
|
for(q = p; q != NULL; q = q->next) {
|
||||||
@ -197,9 +184,7 @@ pbuf_pool_free(struct pbuf *p)
|
|||||||
for(q = pbuf_pool_alloc_cache; q->next != NULL; q = q->next);
|
for(q = pbuf_pool_alloc_cache; q->next != NULL; q = q->next);
|
||||||
q->next = p;
|
q->next = p;
|
||||||
}
|
}
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
sys_arch_unprotect(old_level);
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* pbuf_alloc():
|
/* pbuf_alloc():
|
||||||
@ -343,11 +328,10 @@ void
|
|||||||
pbuf_refresh(void)
|
pbuf_refresh(void)
|
||||||
{
|
{
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
u32_t old_level;
|
SYS_ARCH_PROTECT(old_level);
|
||||||
|
|
||||||
old_level = sys_arch_protect();
|
#ifndef SYS_LIGHTWEIGHT_PROT
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
sys_sem_wait(pbuf_pool_free_sem);
|
sys_sem_wait(pbuf_pool_free_sem);
|
||||||
#endif /* else SYS_LIGHTWEIGHT_PROT */
|
#endif /* else SYS_LIGHTWEIGHT_PROT */
|
||||||
|
|
||||||
@ -373,9 +357,8 @@ pbuf_refresh(void)
|
|||||||
pbuf_pool_free_lock = 0;
|
pbuf_pool_free_lock = 0;
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
}
|
}
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
sys_arch_unprotect(old_level);
|
#ifndef SYS_LIGHTWEIGHT_PROT
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
sys_sem_signal(pbuf_pool_free_sem);
|
sys_sem_signal(pbuf_pool_free_sem);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
}
|
}
|
||||||
@ -393,11 +376,12 @@ pbuf_refresh(void)
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
#ifdef SYS_LIGHTWEIGHT_PROT
|
||||||
#define PBUF_POOL_FREE(p) do { \
|
#define PBUF_POOL_FREE(p) do { \
|
||||||
u32_t old_level = sys_arch_protect(); \
|
SYS_ARCH_DECL_PROTECT(old_level); \
|
||||||
PBUF_POOL_FAST_FREE(p); \
|
SYS_ARCH_PROTECT(old_level); \
|
||||||
sys_arch_unprotect(old_level); \
|
PBUF_POOL_FAST_FREE(p); \
|
||||||
} while(0)
|
SYS_ARCH_UNPROTECT(old_level); \
|
||||||
|
} while(0)
|
||||||
#else /* SYS_LIGHTWEIGHT_PROT */
|
#else /* SYS_LIGHTWEIGHT_PROT */
|
||||||
#define PBUF_POOL_FREE(p) do { \
|
#define PBUF_POOL_FREE(p) do { \
|
||||||
sys_sem_wait(pbuf_pool_free_sem); \
|
sys_sem_wait(pbuf_pool_free_sem); \
|
||||||
@ -536,9 +520,7 @@ pbuf_free(struct pbuf *p)
|
|||||||
{
|
{
|
||||||
struct pbuf *q;
|
struct pbuf *q;
|
||||||
u8_t count = 0;
|
u8_t count = 0;
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
u32_t old_level;
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
|
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -552,48 +534,42 @@ pbuf_free(struct pbuf *p)
|
|||||||
|
|
||||||
LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
|
LWIP_ASSERT("pbuf_free: p->ref > 0", p->ref > 0);
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
|
||||||
/* Since decrementing ref cannot be guarranteed to be a single machine operation
|
/* Since decrementing ref cannot be guarranteed to be a single machine operation
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
old_level = sys_arch_protect();
|
SYS_ARCH_PROTECT(old_level);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
/* Decrement reference count. */
|
/* Decrement reference count. */
|
||||||
p->ref--;
|
p->ref--;
|
||||||
|
|
||||||
/*q = NULL; DJH: Unnecessary statement*/
|
/*q = NULL; DJH: Unnecessary statement*/
|
||||||
/* If reference count == 0, actually deallocate pbuf. */
|
/* If reference count == 0, actually deallocate pbuf. */
|
||||||
if(p->ref == 0) {
|
if(p->ref == 0) {
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
sys_arch_unprotect(old_level);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while(p != NULL) {
|
while(p != NULL) {
|
||||||
/* Check if this is a pbuf from the pool. */
|
/* Check if this is a pbuf from the pool. */
|
||||||
if(p->flags == PBUF_FLAG_POOL) {
|
if(p->flags == PBUF_FLAG_POOL) {
|
||||||
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
|
p->len = p->tot_len = PBUF_POOL_BUFSIZE;
|
||||||
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) {
|
|
||||||
q = p->next;
|
q = p->next;
|
||||||
memp_freep(MEMP_PBUF, p);
|
PBUF_POOL_FREE(p);
|
||||||
} else {
|
} else {
|
||||||
q = p->next;
|
if(p->flags == PBUF_FLAG_ROM) {
|
||||||
mem_free(p);
|
q = p->next;
|
||||||
|
memp_freep(MEMP_PBUF, p);
|
||||||
|
} else {
|
||||||
|
q = p->next;
|
||||||
|
mem_free(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = q;
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
|
pbuf_refresh();
|
||||||
p = q;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
pbuf_refresh();
|
|
||||||
}
|
}
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
|
||||||
else
|
else
|
||||||
sys_arch_unprotect(old_level);
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
|
|
||||||
PERF_STOP("pbuf_free");
|
PERF_STOP("pbuf_free");
|
||||||
|
|
||||||
@ -628,21 +604,15 @@ pbuf_clen(struct pbuf *p)
|
|||||||
void
|
void
|
||||||
pbuf_ref(struct pbuf *p)
|
pbuf_ref(struct pbuf *p)
|
||||||
{
|
{
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
u32_t old_level;
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
|
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_PROTECT(old_level);
|
||||||
old_level = sys_arch_protect();
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
++(p->ref);
|
++(p->ref);
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
sys_arch_unprotect(old_level);
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------------*/
|
||||||
@ -653,18 +623,15 @@ pbuf_ref(struct pbuf *p)
|
|||||||
void
|
void
|
||||||
pbuf_ref_chain(struct pbuf *p)
|
pbuf_ref_chain(struct pbuf *p)
|
||||||
{
|
{
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_DECL_PROTECT(old_level);
|
||||||
u32_t old_level = sys_arch_protect();
|
SYS_ARCH_PROTECT(old_level);
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
|
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
p->ref++;
|
p->ref++;
|
||||||
p=p->next;
|
p=p->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYS_LIGHTWEIGHT_PROT
|
SYS_ARCH_UNPROTECT(old_level);
|
||||||
sys_arch_unprotect(old_level);
|
|
||||||
#endif /* SYS_LIGHTWEIGHT_PROT */
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* pbuf_chain():
|
/* pbuf_chain():
|
||||||
|
@ -110,8 +110,21 @@ void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
|
|||||||
In some implementations they can provide a more light-weight protection
|
In some implementations they can provide a more light-weight protection
|
||||||
mechanism than using semaphores. Otherwise semaphores can be used for
|
mechanism than using semaphores. Otherwise semaphores can be used for
|
||||||
implementation */
|
implementation */
|
||||||
|
#ifndef SYS_ARCH_PROTECT
|
||||||
|
#ifdef SYS_LIGHTWEIGHT_PROT
|
||||||
|
#define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
|
||||||
|
#define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
|
||||||
|
#define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
|
||||||
|
|
||||||
sys_prot_t sys_arch_protect(void);
|
sys_prot_t sys_arch_protect(void);
|
||||||
void sys_arch_unprotect(sys_prot_t pval);
|
void sys_arch_unprotect(sys_prot_t pval);
|
||||||
|
#else /* SYS_LIGHTWEIGHT_PROT */
|
||||||
|
#define SYS_ARCH_DECL_PROTECT(lev)
|
||||||
|
#define SYS_ARCH_PROTECT(lev)
|
||||||
|
#define SYS_ARCH_UNPROTECT(lev)
|
||||||
|
#endif /* SYS_LIGHTWEIGHT_PROT */
|
||||||
|
|
||||||
|
#endif /* SYS_ARCH_PROTECT */
|
||||||
|
|
||||||
/* Thread functions. */
|
/* Thread functions. */
|
||||||
sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg);
|
sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user