add support of LwIP's "lightweight" synchronization mechanisms

This commit is contained in:
Stefan Lankes 2011-08-01 21:56:16 +02:00
parent 253ec92ca0
commit 3f2d9a2405
3 changed files with 49 additions and 1 deletions

View file

@ -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 */

View file

@ -4,6 +4,7 @@
#include <asm/tasks.h>
#include <metalsvm/mailbox.h>
#include <metalsvm/errno.h>
#include <asm/irqflags.h>
#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__ */

View file

@ -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.