Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
3e7c413f
提交
3e7c413f
2月 10, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
operator new and delete
上级
0b9edac9
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
183 行增加
和
6 行删除
+183
-6
Makefile
Makefile
+2
-1
cpprt.cc
cpprt.cc
+16
-0
kernel.h
kernel.h
+0
-1
ns.cc
ns.cc
+0
-4
ns.hh
ns.hh
+165
-0
没有找到文件。
Makefile
浏览文件 @
3e7c413f
...
@@ -26,7 +26,7 @@ COMFLAGS := -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall \
...
@@ -26,7 +26,7 @@ COMFLAGS := -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall \
-DHW_
$(HW)
-include
param.h
-include
compiler.h
-DHW_
$(HW)
-include
param.h
-include
compiler.h
COMFLAGS
+=
$(
shell
$(CC)
-fno-stack-protector
-E
-x
c /dev/null
>
/dev/null 2>&1
&&
echo
-fno-stack-protector
)
COMFLAGS
+=
$(
shell
$(CC)
-fno-stack-protector
-E
-x
c /dev/null
>
/dev/null 2>&1
&&
echo
-fno-stack-protector
)
CFLAGS
:=
$(COMFLAGS)
-std
=
c99
CFLAGS
:=
$(COMFLAGS)
-std
=
c99
CXXFLAGS
:=
$(COMFLAGS)
-std
=
c++0x
-Wno-sign-compare
CXXFLAGS
:=
$(COMFLAGS)
-std
=
c++0x
-Wno-sign-compare
-fno-exceptions
ASFLAGS
=
-m64
-gdwarf-2
-MD
ASFLAGS
=
-m64
-gdwarf-2
-MD
LDFLAGS
+=
-m
elf_x86_64
LDFLAGS
+=
-m
elf_x86_64
...
@@ -36,6 +36,7 @@ OBJS = \
...
@@ -36,6 +36,7 @@ OBJS = \
cilk.o
\
cilk.o
\
condvar.o
\
condvar.o
\
console.o
\
console.o
\
cpprt.o
\
crange.o
\
crange.o
\
e1000.o
\
e1000.o
\
exec.o
\
exec.o
\
...
...
cpprt.cc
0 → 100644
浏览文件 @
3e7c413f
extern
"C"
{
#include "types.h"
#include "kernel.h"
}
void
*
operator
new
(
unsigned
long
nbytes
)
{
return
kmalloc
(
nbytes
);
}
void
operator
delete
(
void
*
p
)
{
kmfree
(
p
);
}
kernel.h
浏览文件 @
3e7c413f
...
@@ -216,7 +216,6 @@ struct nskey {
...
@@ -216,7 +216,6 @@ struct nskey {
.u.iis.b=y, \
.u.iis.b=y, \
.u.iis.s=z}
.u.iis.s=z}
void
nsinit
(
void
);
struct
ns
*
nsalloc
(
int
allowdup
);
struct
ns
*
nsalloc
(
int
allowdup
);
void
nsfree
(
struct
ns
*
);
void
nsfree
(
struct
ns
*
);
u64
ns_allockey
(
struct
ns
*
);
u64
ns_allockey
(
struct
ns
*
);
...
...
ns.cc
浏览文件 @
3e7c413f
...
@@ -45,10 +45,6 @@ struct ns {
...
@@ -45,10 +45,6 @@ struct ns {
struct
bucket
table
[
NHASH
];
struct
bucket
table
[
NHASH
];
};
};
void
nsinit
(
void
)
{
}
// XXX should be using our missing scalable allocator module
// XXX should be using our missing scalable allocator module
struct
ns
*
struct
ns
*
...
...
ns.hh
0 → 100644
浏览文件 @
3e7c413f
#pragma once
// name spaces
// XXX maybe use open hash table, no chain, better cache locality
#if SPINLOCK_DEBUG
#define NHASH 10
#else
#define NHASH 100
#endif
class
scoped_gc_epoch
{
public
:
scoped_gc_epoch
()
{
gc_begin_epoch
();
}
~
scoped_gc_epoch
()
{
gc_end_epoch
();
}
};
template
<
class
K
,
class
V
>
class
xelem
{
public
:
V
val
;
int
next_lock
;
xelem
<
K
,
V
>
*
volatile
next
;
K
key
;
xelem
(
const
K
&
k
,
const
V
&
v
)
:
val
(
v
),
key
(
k
)
{}
};
template
<
class
K
,
class
V
>
struct
xbucket
{
xelem
<
K
,
V
>
*
volatile
chain
;
}
__attribute__
((
aligned
(
CACHELINE
)));
template
<
class
K
,
class
V
>
class
xns
{
private
:
bool
allowdup
;
u64
nextkey
;
xbucket
<
K
,
V
>
table
[
NHASH
];
public
:
xns
(
bool
dup
)
{
allowdup
=
dup
;
nextkey
=
1
;
for
(
int
i
=
0
;
i
<
NHASH
;
i
++
)
table
[
i
].
chain
=
0
;
}
~
xns
()
{
for
(
int
i
=
0
;
i
<
NHASH
;
i
++
)
if
(
table
[
i
].
chain
)
panic
(
"~xns: not empty"
);
}
u64
allockey
()
{
return
__sync_fetch_and_add
(
&
nextkey
,
1
);
}
u64
h
(
const
K
&
key
)
{
return
key
%
NHASH
;
}
int
insert
(
const
K
&
key
,
const
V
&
val
)
{
auto
e
=
new
xelem
<
K
,
V
>
(
key
,
val
);
if
(
!
e
)
return
-
1
;
u64
i
=
h
(
key
);
scoped_gc_epoch
gc
;
for
(;;)
{
auto
root
=
table
[
i
].
chain
;
if
(
!
allowdup
)
{
for
(
auto
x
=
root
;
x
;
x
=
x
->
next
)
{
if
(
x
->
key
==
key
)
{
// XXX delete e;
return
-
1
;
}
}
}
e
->
next
=
root
;
if
(
__sync_bool_compare_and_swap
(
&
table
[
i
].
chain
,
root
,
e
))
return
0
;
}
}
V
lookup
(
const
K
&
key
)
{
u64
i
=
h
(
key
);
scoped_gc_epoch
gc
;
auto
e
=
table
[
i
].
chain
;
while
(
e
)
{
if
(
e
->
key
==
key
)
return
e
->
val
;
e
=
e
->
next
;
}
return
0
;
}
bool
remove
(
const
K
&
key
,
const
V
*
vp
=
0
)
{
u64
i
=
h
(
key
);
scoped_gc_epoch
gc
;
for
(;;)
{
int
fakelock
=
0
;
int
*
pelock
=
&
fakelock
;
auto
pe
=
&
table
[
i
].
chain
;
for
(;;)
{
auto
e
=
*
pe
;
if
(
!
e
)
return
false
;
if
(
e
->
key
==
key
&&
(
!
vp
||
e
->
val
==
*
vp
))
{
if
(
!
__sync_bool_compare_and_swap
(
&
e
->
next_lock
,
0
,
1
))
break
;
if
(
!
__sync_bool_compare_and_swap
(
pelock
,
0
,
1
))
{
e
->
next_lock
=
0
;
break
;
}
if
(
!
__sync_bool_compare_and_swap
(
pe
,
e
,
e
->
next
))
{
*
pelock
=
0
;
e
->
next_lock
=
0
;
break
;
}
*
pelock
=
0
;
// XXX delete e;
return
true
;
}
pe
=
&
e
->
next
;
pelock
=
&
e
->
next_lock
;
}
}
}
template
<
class
CB
>
void
enumerate
(
CB
cb
)
{
scoped_gc_epoch
gc
;
for
(
int
i
=
0
;
i
<
NHASH
;
i
++
)
{
auto
e
=
table
[
i
].
chain
;
while
(
e
)
{
if
(
cb
(
e
->
key
,
e
->
val
))
return
;
e
=
e
->
next
;
}
}
}
template
<
class
CB
>
void
enumerate_key
(
const
K
&
key
,
CB
cb
)
{
scoped_gc_epoch
gc
;
u64
i
=
h
(
key
);
auto
e
=
table
[
i
].
chain
;
while
(
e
)
{
if
(
e
->
key
==
key
&&
cb
(
e
->
key
,
e
->
val
))
return
;
e
=
e
->
next
;
}
}
};
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论