Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
2710b226
提交
2710b226
5月 31, 2011
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
name individual proc locks
上级
b11c28b9
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
175 行增加
和
70 行删除
+175
-70
console.c
console.c
+95
-41
defs.h
defs.h
+4
-0
forktree.c
forktree.c
+3
-3
printf.c
printf.c
+68
-24
proc.c
proc.c
+4
-2
proc.h
proc.h
+1
-0
没有找到文件。
console.c
浏览文件 @
2710b226
...
...
@@ -15,6 +15,8 @@
#include "proc.h"
#include "x86.h"
#include <stdarg.h>
static
void
consputc
(
int
);
static
int
panicked
=
0
;
...
...
@@ -25,7 +27,8 @@ static struct {
}
cons
;
static
void
printint
(
int
xx
,
int
base
,
int
sign
)
printint
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
int
xx
,
int
base
,
int
sign
)
{
static
char
digits
[]
=
"0123456789abcdef"
;
char
buf
[
16
];
...
...
@@ -46,61 +49,112 @@ printint(int xx, int base, int sign)
buf
[
i
++
]
=
'-'
;
while
(
--
i
>=
0
)
consputc
(
buf
[
i
]);
putch
(
putarg
,
buf
[
i
]);
}
//PAGEBREAK: 50
//
Print to the console. o
nly understands %d, %x, %p, %s.
//
O
nly understands %d, %x, %p, %s.
void
cprintf
(
char
*
fmt
,
...)
vprintfmt
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
char
*
fmt
,
va_list
ap
)
{
int
i
,
c
,
state
,
locking
;
uint
*
argp
;
char
*
s
;
int
c
,
i
,
state
;
locking
=
cons
.
locking
;
if
(
locking
)
acquire
(
&
cons
.
lock
);
argp
=
(
uint
*
)(
void
*
)(
&
fmt
+
1
);
state
=
0
;
for
(
i
=
0
;
(
c
=
fmt
[
i
]
&
0xff
)
!=
0
;
i
++
){
if
(
c
!=
'%'
){
consputc
(
c
);
continue
;
}
c
=
fmt
[
++
i
]
&
0xff
;
if
(
c
==
0
)
break
;
switch
(
c
){
case
'd'
:
printint
(
*
argp
++
,
10
,
1
);
break
;
case
'x'
:
case
'p'
:
printint
(
*
argp
++
,
16
,
0
);
break
;
case
's'
:
if
((
s
=
(
char
*
)
*
argp
++
)
==
0
)
s
=
"(null)"
;
for
(;
*
s
;
s
++
)
consputc
(
*
s
);
break
;
case
'%'
:
consputc
(
'%'
);
break
;
default:
// Print unknown % sequence to draw attention.
consputc
(
'%'
);
consputc
(
c
);
break
;
for
(
i
=
0
;
fmt
[
i
];
i
++
){
c
=
fmt
[
i
]
&
0xff
;
if
(
state
==
0
){
if
(
c
==
'%'
){
state
=
'%'
;
}
else
{
putch
(
putarg
,
c
);
}
}
else
if
(
state
==
'%'
){
if
(
c
==
'd'
){
printint
(
putch
,
putarg
,
va_arg
(
ap
,
uint
),
10
,
1
);
}
else
if
(
c
==
'x'
||
c
==
'p'
){
printint
(
putch
,
putarg
,
va_arg
(
ap
,
uint
),
16
,
0
);
}
else
if
(
c
==
's'
){
s
=
(
char
*
)
va_arg
(
ap
,
char
*
);
if
(
s
==
0
)
s
=
"(null)"
;
while
(
*
s
!=
0
){
putch
(
putarg
,
*
s
);
s
++
;
}
}
else
if
(
c
==
'c'
){
putch
(
putarg
,
va_arg
(
ap
,
uint
));
}
else
if
(
c
==
'%'
){
putch
(
putarg
,
c
);
}
else
{
// Unknown % sequence. Print it to draw attention.
putch
(
putarg
,
'%'
);
putch
(
putarg
,
c
);
}
state
=
0
;
}
}
}
// Print to the console.
static
void
writecons
(
void
*
arg
,
char
c
)
{
consputc
(
c
);
}
void
cprintf
(
char
*
fmt
,
...)
{
va_list
ap
;
int
locking
=
cons
.
locking
;
if
(
locking
)
acquire
(
&
cons
.
lock
);
va_start
(
ap
,
fmt
);
vprintfmt
(
writecons
,
0
,
fmt
,
ap
);
va_end
(
ap
);
if
(
locking
)
release
(
&
cons
.
lock
);
}
// Print to a buffer.
struct
bufstate
{
char
*
p
;
char
*
e
;
};
static
void
writebuf
(
void
*
arg
,
char
c
)
{
struct
bufstate
*
bs
=
arg
;
if
(
bs
->
p
<
bs
->
e
)
{
bs
->
p
[
0
]
=
c
;
bs
->
p
++
;
}
}
void
vsnprintf
(
char
*
buf
,
uint
n
,
char
*
fmt
,
va_list
ap
)
{
struct
bufstate
bs
=
{
buf
,
buf
+
n
-
1
};
vprintfmt
(
writebuf
,
(
void
*
)
&
bs
,
fmt
,
ap
);
bs
.
p
[
0
]
=
'\0'
;
}
void
snprintf
(
char
*
buf
,
uint
n
,
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
vsnprintf
(
buf
,
n
,
fmt
,
ap
);
va_end
(
ap
);
}
void
panic
(
char
*
s
)
{
...
...
defs.h
浏览文件 @
2710b226
#include <stdarg.h>
struct
buf
;
struct
context
;
struct
file
;
...
...
@@ -24,6 +26,8 @@ void cv_wakeup(struct condvar *cv);
// console.c
void
consoleinit
(
void
);
void
cprintf
(
char
*
,
...);
void
vsnprintf
(
char
*
buf
,
uint
n
,
char
*
fmt
,
va_list
ap
);
void
snprintf
(
char
*
buf
,
uint
n
,
char
*
fmt
,
...);
void
consoleintr
(
int
(
*
)(
void
));
void
panic
(
char
*
)
__attribute__
((
noreturn
));
...
...
forktree.c
浏览文件 @
2710b226
...
...
@@ -4,7 +4,7 @@
#include "xv6-mtrace.h"
#define NCHILD 2
#define NDEPTH
6
#define NDEPTH
5
char
*
strncpy
(
char
*
s
,
const
char
*
t
,
int
n
)
...
...
@@ -27,7 +27,7 @@ forktree(void)
{
uint
depth
=
0
;
printf
(
1
,
"
fork tree
\n
"
);
printf
(
1
,
"
%d: fork tree
\n
"
,
getpid
()
);
mtrace_enable_set
(
1
,
"xv6-forktree"
);
next_level:
...
...
@@ -68,7 +68,7 @@ forktree(void)
mtrace_appdata_register
(
&
entry
);
mtrace_enable_set
(
0
,
"xv6-forktree"
);
printf
(
1
,
"
fork tree OK
\n
"
);
printf
(
1
,
"
%d: fork tree OK
\n
"
,
getpid
()
);
halt
();
}
...
...
printf.c
浏览文件 @
2710b226
...
...
@@ -2,14 +2,11 @@
#include "stat.h"
#include "user.h"
static
void
putc
(
int
fd
,
char
c
)
{
write
(
fd
,
&
c
,
1
);
}
#include <stdarg.h>
static
void
printint
(
int
fd
,
int
xx
,
int
base
,
int
sgn
)
printint
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
int
xx
,
int
base
,
int
sgn
)
{
static
char
digits
[]
=
"0123456789ABCDEF"
;
char
buf
[
16
];
...
...
@@ -32,54 +29,101 @@ printint(int fd, int xx, int base, int sgn)
buf
[
i
++
]
=
'-'
;
while
(
--
i
>=
0
)
putc
(
fd
,
buf
[
i
]);
putc
h
(
putarg
,
buf
[
i
]);
}
//
Print to the given fd.
Only understands %d, %x, %p, %s.
// Only understands %d, %x, %p, %s.
void
printf
(
int
fd
,
char
*
fmt
,
...)
vprintfmt
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
char
*
fmt
,
va_list
ap
)
{
char
*
s
;
int
c
,
i
,
state
;
uint
*
ap
;
state
=
0
;
ap
=
(
uint
*
)(
void
*
)
&
fmt
+
1
;
for
(
i
=
0
;
fmt
[
i
];
i
++
){
c
=
fmt
[
i
]
&
0xff
;
if
(
state
==
0
){
if
(
c
==
'%'
){
state
=
'%'
;
}
else
{
putc
(
fd
,
c
);
putc
h
(
putarg
,
c
);
}
}
else
if
(
state
==
'%'
){
if
(
c
==
'd'
){
printint
(
fd
,
*
ap
,
10
,
1
);
ap
++
;
printint
(
putch
,
putarg
,
va_arg
(
ap
,
uint
),
10
,
1
);
}
else
if
(
c
==
'x'
||
c
==
'p'
){
printint
(
fd
,
*
ap
,
16
,
0
);
ap
++
;
printint
(
putch
,
putarg
,
va_arg
(
ap
,
uint
),
16
,
0
);
}
else
if
(
c
==
's'
){
s
=
(
char
*
)
*
ap
;
ap
++
;
s
=
(
char
*
)
va_arg
(
ap
,
char
*
);
if
(
s
==
0
)
s
=
"(null)"
;
while
(
*
s
!=
0
){
putc
(
fd
,
*
s
);
putc
h
(
putarg
,
*
s
);
s
++
;
}
}
else
if
(
c
==
'c'
){
putc
(
fd
,
*
ap
);
ap
++
;
putch
(
putarg
,
va_arg
(
ap
,
uint
));
}
else
if
(
c
==
'%'
){
putc
(
fd
,
c
);
putc
h
(
putarg
,
c
);
}
else
{
// Unknown % sequence. Print it to draw attention.
putc
(
fd
,
'%'
);
putc
(
fd
,
c
);
putc
h
(
putarg
,
'%'
);
putc
h
(
putarg
,
c
);
}
state
=
0
;
}
}
}
// Print to the given fd.
static
void
writec
(
void
*
arg
,
char
c
)
{
int
fd
=
(
int
)
arg
;
write
(
fd
,
&
c
,
1
);
}
void
printf
(
int
fd
,
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
vprintfmt
(
writec
,
(
void
*
)
fd
,
fmt
,
ap
);
va_end
(
ap
);
}
// Print to a buffer.
struct
bufstate
{
char
*
p
;
char
*
e
;
};
static
void
writebuf
(
void
*
arg
,
char
c
)
{
struct
bufstate
*
bs
=
arg
;
if
(
bs
->
p
<
bs
->
e
)
{
bs
->
p
[
0
]
=
c
;
bs
->
p
++
;
}
}
void
vsnprintf
(
char
*
buf
,
uint
n
,
char
*
fmt
,
va_list
ap
)
{
struct
bufstate
bs
=
{
buf
,
buf
+
n
-
1
};
vprintfmt
(
writebuf
,
(
void
*
)
&
bs
,
fmt
,
ap
);
bs
.
p
[
0
]
=
'\0'
;
}
void
snprintf
(
char
*
buf
,
uint
n
,
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
vsnprintf
(
buf
,
n
,
fmt
,
ap
);
va_end
(
ap
);
}
proc.c
浏览文件 @
2710b226
...
...
@@ -50,14 +50,16 @@ allocproc(void)
if
(
p
==
0
)
return
0
;
memset
(
p
,
0
,
sizeof
(
*
p
));
p
->
state
=
EMBRYO
;
initlock
(
&
p
->
lock
,
"proc"
);
initcondvar
(
&
p
->
cv
,
"proc"
);
p
->
state
=
EMBRYO
;
p
->
pid
=
ns_allockey
(
nspid
);
p
->
epoch
=
INF
;
p
->
cpuid
=
cpu
->
id
;
snprintf
(
p
->
lockname
,
sizeof
(
p
->
lockname
),
"proc%d"
,
p
->
pid
);
initlock
(
&
p
->
lock
,
p
->
lockname
);
initcondvar
(
&
p
->
cv
,
p
->
lockname
);
if
(
ns_insert
(
nspid
,
p
->
pid
,
(
void
*
)
p
)
<
0
)
panic
(
"allocproc: ns_insert"
);
...
...
proc.h
浏览文件 @
2710b226
...
...
@@ -89,6 +89,7 @@ struct proc {
SLIST_ENTRY
(
proc
)
child_next
;
struct
condvar
cv
;
uint
epoch
;
char
lockname
[
16
];
};
// Process memory is laid out contiguously, low addresses first:
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论