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

Implement SYS_LIGHTWEIGHT_PROT, and use LWIP_COMPAT_MUTEX

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