Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
8d36d9e2
提交
8d36d9e2
12月 29, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some lwIP locking that fixes multithreaded issues
上级
726fa62d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
96 行增加
和
39 行删除
+96
-39
net.c
net.c
+38
-3
sys_arch.h
net/arch/sys_arch.h
+4
-0
lwipopts.h
net/lwipopts.h
+1
-2
sys_arch.c
net/sys_arch.c
+53
-34
没有找到文件。
net.c
浏览文件 @
8d36d9e2
...
...
@@ -14,8 +14,10 @@
#include "types.h"
#include "kernel.h"
#include "queue.h"
#ifndef LWIP
#include "spinlock.h"
#include "condvar.h"
#endif
#include "proc.h"
#include "fs.h"
#include "file.h"
...
...
@@ -61,7 +63,10 @@ void
netrx
(
void
*
va
,
u16
len
)
{
extern
void
if_input
(
struct
netif
*
netif
,
void
*
buf
,
u16
len
);
lwip_core_lock
();
if_input
(
&
nif
,
va
,
len
);
lwip_core_unlock
();
}
static
void
__attribute__
((
noreturn
))
...
...
@@ -72,7 +77,9 @@ net_timer(void *x)
for
(;;)
{
u64
cur
=
nsectime
();
lwip_core_lock
();
t
->
func
();
lwip_core_unlock
();
acquire
(
&
t
->
waitlk
);
cv_sleepto
(
&
t
->
waitcv
,
&
t
->
waitlk
,
cur
+
t
->
nsec
);
release
(
&
t
->
waitlk
);
...
...
@@ -134,10 +141,15 @@ initnet_worker(void *x)
static
struct
timer_thread
t_arp
,
t_tcpf
,
t_tcps
,
t_dhcpf
,
t_dhcpc
;
volatile
long
tcpip_done
=
0
;
lwip_core_init
();
lwip_core_lock
();
tcpip_init
(
&
tcpip_init_done
,
(
void
*
)
&
tcpip_done
);
lwip_core_unlock
();
while
(
!
tcpip_done
)
yield
();
lwip_core_lock
();
memset
(
&
nif
,
0
,
sizeof
(
nif
));
lwip_init
(
&
nif
,
NULL
,
0
,
0
,
0
);
...
...
@@ -181,10 +193,12 @@ initnet_worker(void *x)
(
ip
&
0x000000ff
));
}
}
lwip_core_unlock
();
acquire
(
&
lk
);
cv_sleepto
(
&
cv
,
&
lk
,
nsectime
()
+
1000000000
);
release
(
&
lk
);
lwip_core_lock
();
}
}
...
...
@@ -206,7 +220,11 @@ initnet(void)
long
netsocket
(
int
domain
,
int
type
,
int
protocol
)
{
return
lwip_socket
(
domain
,
type
,
protocol
);
int
r
;
lwip_core_lock
();
r
=
lwip_socket
(
domain
,
type
,
protocol
);
lwip_core_unlock
();
return
r
;
}
long
...
...
@@ -222,7 +240,9 @@ netbind(int sock, void *xaddr, int xaddrlen)
if
(
umemcpy
(
addr
,
xaddr
,
xaddrlen
))
return
-
1
;
lwip_core_lock
();
r
=
lwip_bind
(
sock
,
addr
,
xaddrlen
);
lwip_core_unlock
();
kmfree
(
addr
);
return
r
;
}
...
...
@@ -230,7 +250,12 @@ netbind(int sock, void *xaddr, int xaddrlen)
long
netlisten
(
int
sock
,
int
backlog
)
{
return
lwip_listen
(
sock
,
backlog
);
int
r
;
lwip_core_lock
();
r
=
lwip_listen
(
sock
,
backlog
);
lwip_core_unlock
();
return
r
;
}
long
...
...
@@ -248,14 +273,18 @@ netaccept(int sock, void *xaddr, void *xaddrlen)
if
(
addr
==
NULL
)
return
-
1
;
lwip_core_lock
();
ss
=
lwip_accept
(
sock
,
addr
,
&
len
);
lwip_core_unlock
();
if
(
ss
<
0
)
{
kmfree
(
addr
);
return
ss
;
}
if
(
kmemcpy
(
xaddrlen
,
&
len
,
sizeof
(
len
))
||
kmemcpy
(
xaddr
,
addr
,
len
))
{
lwip_core_lock
();
lwip_close
(
ss
);
lwip_core_unlock
();
kmfree
(
addr
);
return
-
1
;
}
...
...
@@ -266,7 +295,9 @@ netaccept(int sock, void *xaddr, void *xaddrlen)
void
netclose
(
int
sock
)
{
lwip_core_lock
();
lwip_close
(
sock
);
lwip_core_unlock
();
}
int
...
...
@@ -285,7 +316,9 @@ netwrite(int sock, char *ubuf, int len)
kfree
(
kbuf
);
return
-
1
;
}
lwip_core_lock
();
r
=
lwip_write
(
sock
,
kbuf
,
cc
);
lwip_core_unlock
();
kfree
(
kbuf
);
return
r
;
}
...
...
@@ -302,7 +335,9 @@ netread(int sock, char *ubuf, int len)
return
-
1
;
cc
=
MIN
(
len
,
PGSIZE
);
lwip_core_lock
();
r
=
lwip_read
(
sock
,
kbuf
,
cc
);
lwip_core_unlock
();
if
(
r
<
0
)
{
kfree
(
kbuf
);
return
r
;
...
...
net/arch/sys_arch.h
浏览文件 @
8d36d9e2
...
...
@@ -27,4 +27,8 @@ typedef struct sys_sem {
#define SYS_ARCH_NOWAIT 0xfffffffe
extern
void
lwip_core_unlock
(
void
);
extern
void
lwip_core_lock
(
void
);
extern
void
lwip_core_init
(
void
);
#endif
net/lwipopts.h
浏览文件 @
8d36d9e2
...
...
@@ -6,7 +6,7 @@
#define LWIP_DHCP 1
#define LWIP_COMPAT_SOCKETS 0
#define LWIP_COMPAT_MUTEX 1
#define SYS_LIGHTWEIGHT_PROT
1
#define SYS_LIGHTWEIGHT_PROT
0
#define LWIP_PROVIDE_ERRNO 1
#define MEM_ALIGNMENT 4
...
...
@@ -40,7 +40,6 @@
#if 0
#define ETHARP_DEBUG LWIP_DBG_ON
#define NETIF_DEBUG LWIP_DBG_ON
#define IP_DEBUG LWIP_DBG_ON
#define DHCP_DEBUG LWIP_DBG_ON
#define UDP_DEBUG LWIP_DBG_ON
#define IP_DEBUG LWIP_DBG_ON
...
...
net/sys_arch.c
浏览文件 @
8d36d9e2
...
...
@@ -66,8 +66,11 @@ void
sys_mbox_post
(
sys_mbox_t
*
mbox
,
void
*
msg
)
{
acquire
(
&
mbox
->
s
);
while
(
mbox
->
head
-
mbox
->
tail
==
MBOXSLOTS
)
while
(
mbox
->
head
-
mbox
->
tail
==
MBOXSLOTS
)
{
lwip_core_unlock
();
cv_sleep
(
&
mbox
->
c
,
&
mbox
->
s
);
lwip_core_lock
();
}
mbox
->
msg
[
mbox
->
head
%
MBOXSLOTS
]
=
msg
;
mbox
->
head
++
;
cv_wakeup
(
&
mbox
->
c
);
...
...
@@ -96,9 +99,13 @@ sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
r
=
SYS_ARCH_TIMEOUT
;
goto
done
;
}
lwip_core_unlock
();
cv_sleepto
(
&
mbox
->
c
,
&
mbox
->
s
,
to
);
lwip_core_lock
();
}
else
{
lwip_core_unlock
();
cv_sleep
(
&
mbox
->
c
,
&
mbox
->
s
);
lwip_core_lock
();
}
}
r
=
nsectime
()
-
start
;
...
...
@@ -181,9 +188,13 @@ sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
r
=
SYS_ARCH_TIMEOUT
;
goto
done
;
}
lwip_core_unlock
();
cv_sleepto
(
&
sem
->
c
,
&
sem
->
s
,
to
);
lwip_core_lock
();
}
else
{
lwip_core_unlock
();
cv_sleep
(
&
sem
->
c
,
&
sem
->
s
);
lwip_core_lock
();
}
}
r
=
nsectime
()
-
start
;
...
...
@@ -195,48 +206,37 @@ done:
}
//
//
protect
//
thread
//
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
();
struct
lwip_thread
{
lwip_thread_fn
thread
;
void
*
arg
;
};
return
r
;
}
void
sys_arch_unprotect
(
sys_prot_t
pval
)
static
void
lwip_thread
(
void
*
x
)
{
if
(
lwprot
.
cpu
!=
mycpu
()
||
lwprot
.
depth
==
0
)
panic
(
"sys_arch_unprotect"
);
lwprot
.
depth
--
;
if
(
lwprot
.
depth
==
0
)
{
lwprot
.
cpu
=
NULL
;
release
(
&
lwprot
.
lk
);
}
struct
lwip_thread
*
lt
=
x
;
lwip_core_lock
();
lt
->
thread
(
lt
->
arg
);
lwip_core_unlock
();
kmfree
(
lt
);
}
//
// thread
//
sys_thread_t
sys_thread_new
(
const
char
*
name
,
lwip_thread_fn
thread
,
void
*
arg
,
int
stacksize
,
int
prio
)
{
struct
lwip_thread
*
lt
;
struct
proc
*
p
;
p
=
threadalloc
(
thread
,
arg
);
lt
=
kmalloc
(
sizeof
(
*
lt
));
if
(
lt
==
NULL
)
return
NULL
;
lt
->
thread
=
thread
;
lt
->
arg
=
arg
;
p
=
threadalloc
(
lwip_thread
,
lt
);
if
(
p
==
NULL
)
panic
(
"lwip: sys_thread_new"
);
safestrcpy
(
p
->
name
,
name
,
sizeof
(
p
->
name
));
...
...
@@ -255,6 +255,25 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
void
sys_init
(
void
)
{
initlock
(
&
lwprot
.
lk
,
"lwIP lwprot"
);
}
//
// serialization
//
void
lwip_core_unlock
(
void
)
{
release
(
&
lwprot
.
lk
);
}
void
lwip_core_lock
(
void
)
{
acquire
(
&
lwprot
.
lk
);
}
void
lwip_core_init
(
void
)
{
initlock
(
&
lwprot
.
lk
,
"lwIP lwprot"
);
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论