提交 75e7f93c 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Implement SYS_LIGHTWEIGHT_PROT, and use LWIP_COMPAT_MUTEX

上级 440a6621
......@@ -6,6 +6,8 @@
typedef struct proc* sys_thread_t;
typedef u64 sys_prot_t;
typedef struct sys_mbox {
#define MBOXSLOTS 32
struct spinlock s;
......@@ -21,21 +23,6 @@ typedef struct sys_sem {
u8 count;
} sys_sem_t;
typedef struct sys_mutex {
struct spinlock s;
} sys_mutex_t;
#define SYS_MBOX_NULL (-1)
#define SYS_SEM_NULL (-1)
void lwip_core_lock(void);
void lwip_core_unlock(void);
void lwip_core_init(void);
#define SYS_ARCH_DECL_PROTECT(lev)
#define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_UNPROTECT(lev)
#define SYS_ARCH_NOWAIT 0xfffffffe
#endif
......@@ -5,7 +5,8 @@
#define LWIP_STATS_DISPLAY 0
#define LWIP_DHCP 1
#define LWIP_COMPAT_SOCKETS 0
//#define SYS_LIGHTWEIGHT_PROT 1
#define LWIP_COMPAT_MUTEX 1
#define SYS_LIGHTWEIGHT_PROT 1
#define LWIP_PROVIDE_ERRNO 1
#define MEM_ALIGNMENT 4
......
......@@ -4,9 +4,16 @@
#include "queue.h"
#include "kernel.h"
#include "proc.h"
#include "cpu.h"
#define DIE panic(__func__)
static struct {
struct spinlock lk;
struct cpu *cpu;
u64 depth;
} lwprot;
//
// mbox
//
......@@ -129,31 +136,36 @@ sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
}
//
// mutex
// protect
//
err_t
sys_mutex_new(sys_mutex_t *mutex)
{
initlock(&mutex->s, "lwIP mutex");
return ERR_OK;
}
void
sys_mutex_lock(sys_mutex_t *mutex)
{
DIE;
}
sys_prot_t
sys_arch_protect(void)
{
sys_prot_t r;
pushcli();
if (lwprot.cpu == mycpu())
r = lwprot.depth++;
else {
acquire(&lwprot.lk);
r = lwprot.depth++;
lwprot.cpu = mycpu();
}
popcli();
void
sys_mutex_unlock(sys_mutex_t *mutex)
{
DIE;
return r;
}
void
sys_mutex_free(sys_mutex_t *mutex)
{
DIE;
sys_arch_unprotect(sys_prot_t pval)
{
if (lwprot.cpu != mycpu() || lwprot.depth == 0)
panic("sys_arch_unprotect");
lwprot.depth--;
if (lwprot.depth == 0) {
lwprot.cpu = NULL;
release(&lwprot.lk);
}
}
//
......@@ -184,6 +196,6 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
void
sys_init(void)
{
initlock(&lwprot.lk, "lwIP lwprot");
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论