From 3f2d9a2405f6e390b67905c880e723fd355e8b32 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 1 Aug 2011 21:56:16 +0200 Subject: [PATCH] add support of LwIP's "lightweight" synchronization mechanisms --- lwip/src/arch/sys_arch.c | 22 +++++++++++++++++++++- lwip/src/include/arch/sys_arch.h | 21 +++++++++++++++++++++ lwip/src/include/lwipopts.h | 7 +++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lwip/src/arch/sys_arch.c b/lwip/src/arch/sys_arch.c index 2eef4727..47c6e6ec 100644 --- a/lwip/src/arch/sys_arch.c +++ b/lwip/src/arch/sys_arch.c @@ -74,13 +74,16 @@ sys_msleep(u32_t ms) } } -/* sys_thread_new(): Spawns a new thread with given attributes as supportet +/* sys_thread_new(): Spawns a new thread with given attributes as supported * Note: In MetalSVM this is realized as kernel tasks */ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) { tid_t tmp; + + kprintf("Create LWIP task %s\n", name); create_kernel_task(&tmp,thread,arg); + return tmp; } @@ -252,4 +255,21 @@ err_t sys_mutex_new(sys_mutex_t * mutex) return 0; } +#if SYS_LIGHTWEIGHT_PROT +#if MAX_CORES > 1 +static spinlock_irqsave_t lwprot_lock = SPINLOCK_IRQSAVE_INIT; + +sys_prot_t sys_arch_protect(void) +{ + spinlock_irqsave_lock(&lwprot_lock); + return 0; +} + +void sys_arch_unprotect(sys_prot_t pval) +{ + spinlock_irqsave_unlock(&lwprot_lock); +} +#endif +#endif + #endif /* !NO_SYS */ diff --git a/lwip/src/include/arch/sys_arch.h b/lwip/src/include/arch/sys_arch.h index fde4fbc2..eab88cb5 100644 --- a/lwip/src/include/arch/sys_arch.h +++ b/lwip/src/include/arch/sys_arch.h @@ -4,6 +4,7 @@ #include #include #include +#include #define EWOULDBLOCK EAGAIN /* Operation would block */ @@ -22,4 +23,24 @@ typedef struct typedef tid_t* sys_thread_t; +#if SYS_LIGHTWEIGHT_PROT +#if MAX_CORES > 1 +typedef uint32_t sys_prot_t; +sys_prot_t sys_arch_protect(void); +void sys_arch_unprotect(sys_prot_t pval); +#else +typedef uint32_t sys_prot_t; + +static inline sys_prot_t sys_arch_protect(void) +{ + return irq_nested_disable(); +} + +static inline void sys_arch_unprotect(sys_prot_t pval) +{ + irq_nested_enable(pval); +} +#endif +#endif + #endif /* __ARCH_SYS_ARCH_H__ */ diff --git a/lwip/src/include/lwipopts.h b/lwip/src/include/lwipopts.h index 46ac691a..4be7eb4c 100644 --- a/lwip/src/include/lwipopts.h +++ b/lwip/src/include/lwipopts.h @@ -3,6 +3,13 @@ #ifndef __LWIPOPTS_H__ #define __LWIPOPTS_H_ +/** + * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain + * critical regions during buffer allocation, deallocation and memory + * allocation and deallocation. + */ +#define SYS_LIGHTWEIGHT_PROT 1 + /** * NO_SYS==1: Provides VERY minimal functionality. Otherwise, * use lwIP facilities.