Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
52e99f8a
提交
52e99f8a
2月 06, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rejigger spinlock.c
上级
b0ecf098
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
59 行增加
和
56 行删除
+59
-56
spinlock.c
spinlock.c
+59
-56
没有找到文件。
spinlock.c
浏览文件 @
52e99f8a
...
...
@@ -8,6 +8,58 @@
#include "spinlock.h"
#include "mtrace.h"
static
inline
void
locking
(
struct
spinlock
*
lk
)
{
#if SPINLOCK_DEBUG
if
(
holding
(
lk
))
{
cprintf
(
"%p
\n
"
,
__builtin_return_address
(
0
));
panic
(
"acquire"
);
}
#endif
mtlock
(
lk
);
}
static
inline
void
locked
(
struct
spinlock
*
lk
)
{
mtacquired
(
lk
);
#if SPINLOCK_DEBUG
// Record info about lock acquisition for debugging.
lk
->
cpu
=
mycpu
();
getcallerpcs
(
&
lk
,
lk
->
pcs
,
NELEM
(
lk
->
pcs
));
#endif
}
static
inline
void
releasing
(
struct
spinlock
*
lk
)
{
#if SPINLOCK_DEBUG
if
(
!
holding
(
lk
))
{
cprintf
(
"lock: %s
\n
"
,
lk
->
name
);
panic
(
"release"
);
}
#endif
mtunlock
(
lk
);
#if SPINLOCK_DEBUG
lk
->
pcs
[
0
]
=
0
;
lk
->
cpu
=
0
;
#endif
}
// Check whether this cpu is holding the lock.
#if SPINLOCK_DEBUG
int
holding
(
struct
spinlock
*
lock
)
{
return
lock
->
locked
&&
lock
->
cpu
==
mycpu
();
}
#endif
void
initlock
(
struct
spinlock
*
lk
,
const
char
*
name
)
{
...
...
@@ -21,27 +73,13 @@ initlock(struct spinlock *lk, const char *name)
int
tryacquire
(
struct
spinlock
*
lk
)
{
pushcli
();
// disable interrupts to avoid deadlock.
#if SPINLOCK_DEBUG
if
(
holding
(
lk
))
{
cprintf
(
"%p
\n
"
,
__builtin_return_address
(
0
));
panic
(
"acquire"
);
}
#endif
mtlock
(
lk
);
pushcli
();
locking
(
lk
);
if
(
xchg32
(
&
lk
->
locked
,
1
)
!=
0
)
{
popcli
();
return
0
;
}
mtacquired
(
lk
);
#if SPINLOCK_DEBUG
// Record info about lock acquisition for debugging.
lk
->
cpu
=
mycpu
();
getcallerpcs
(
&
lk
,
lk
->
pcs
,
NELEM
(
lk
->
pcs
));
#endif
locked
(
lk
);
return
1
;
}
...
...
@@ -52,47 +90,21 @@ tryacquire(struct spinlock *lk)
void
acquire
(
struct
spinlock
*
lk
)
{
pushcli
();
// disable interrupts to avoid deadlock.
#if SPINLOCK_DEBUG
if
(
holding
(
lk
))
{
cprintf
(
"%p
\n
"
,
__builtin_return_address
(
0
));
panic
(
"acquire"
);
}
#endif
mtlock
(
lk
);
pushcli
();
locking
(
lk
);
// The xchg is atomic.
// It also serializes, so that reads after acquire are not
// reordered before it.
while
(
xchg32
(
&
lk
->
locked
,
1
)
!=
0
)
;
mtacquired
(
lk
);
#if SPINLOCK_DEBUG
// Record info about lock acquisition for debugging.
lk
->
cpu
=
mycpu
();
getcallerpcs
(
&
lk
,
lk
->
pcs
,
NELEM
(
lk
->
pcs
));
#endif
locked
(
lk
);
}
// Release the lock.
void
release
(
struct
spinlock
*
lk
)
{
#if SPINLOCK_DEBUG
if
(
!
holding
(
lk
))
{
cprintf
(
"lock: %s
\n
"
,
lk
->
name
);
panic
(
"release"
);
}
#endif
mtunlock
(
lk
);
#if SPINLOCK_DEBUG
lk
->
pcs
[
0
]
=
0
;
lk
->
cpu
=
0
;
#endif
releasing
(
lk
);
// The xchg serializes, so that reads before release are
// not reordered after it. The 1996 PentiumPro manual (Volume 3,
...
...
@@ -107,12 +119,3 @@ release(struct spinlock *lk)
popcli
();
}
// Check whether this cpu is holding the lock.
#if SPINLOCK_DEBUG
int
holding
(
struct
spinlock
*
lock
)
{
return
lock
->
locked
&&
lock
->
cpu
==
mycpu
();
}
#endif
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论