Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
a1d37602
R
rocksdb
项目概览
kvdb
/
rocksdb
11 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a1d37602
编写于
10月 12, 2015
作者:
P
Praveen Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixing mutex to not use unique_lock
上级
9eaff629
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
45 deletion
+60
-45
port/win/port_win.cc
port/win/port_win.cc
+18
-33
port/win/port_win.h
port/win/port_win.h
+42
-12
未找到文件。
port/win/port_win.cc
浏览文件 @
a1d37602
...
...
@@ -43,65 +43,50 @@ void gettimeofday(struct timeval* tv, struct timezone* /* tz */) {
tv
->
tv_usec
=
usNow
.
count
()
-
duration_cast
<
microseconds
>
(
secNow
).
count
();
}
Mutex
::
Mutex
(
bool
adaptive
)
:
lock
(
m_mutex
,
std
::
defer_lock
)
{}
Mutex
::~
Mutex
()
{}
void
Mutex
::
Lock
()
{
lock
.
lock
();
#ifndef NDEBUG
locked_
=
true
;
#endif
}
void
Mutex
::
Unlock
()
{
#ifndef NDEBUG
locked_
=
false
;
#endif
lock
.
unlock
();
}
void
Mutex
::
AssertHeld
()
{
#ifndef NDEBUG
assert
(
locked_
);
#endif
}
CondVar
::
CondVar
(
Mutex
*
mu
)
:
mu_
(
mu
)
{}
CondVar
::~
CondVar
()
{}
void
CondVar
::
Wait
()
{
// Caller must ensure that mutex is held prior to calling this method
std
::
unique_lock
<
std
::
mutex
>
lk
(
mu_
->
getLock
(),
std
::
adopt_lock
);
#ifndef NDEBUG
mu_
->
locked_
=
false
;
#endif
cv_
.
wait
(
mu_
->
getLock
()
);
cv_
.
wait
(
lk
);
#ifndef NDEBUG
mu_
->
locked_
=
true
;
#endif
// Release ownership of the lock as we don't want it to be unlocked when
// it goes out of scope (as we adopted the lock and didn't lock it ourselves)
lk
.
release
();
}
bool
CondVar
::
TimedWait
(
uint64_t
abs_time_us
)
{
#ifndef NDEBUG
mu_
->
locked_
=
false
;
#endif
using
namespace
std
::
chrono
;
// MSVC++ library implements wait_until in terms of wait_for so
//
there is not an absolute wait anyway
.
//
we need to convert absoulte wait into relative wait
.
microseconds
usAbsTime
(
abs_time_us
);
microseconds
usNow
(
duration_cast
<
microseconds
>
(
system_clock
::
now
().
time_since_epoch
()));
duration_cast
<
microseconds
>
(
system_clock
::
now
().
time_since_epoch
()));
microseconds
relTimeUs
=
(
usAbsTime
>
usNow
)
?
(
usAbsTime
-
usNow
)
:
microseconds
::
zero
();
std
::
cv_status
cvStatus
=
cv_
.
wait_for
(
mu_
->
getLock
(),
relTimeUs
);
(
usAbsTime
>
usNow
)
?
(
usAbsTime
-
usNow
)
:
microseconds
::
zero
();
// Caller must ensure that mutex is held prior to calling this method
std
::
unique_lock
<
std
::
mutex
>
lk
(
mu_
->
getLock
(),
std
::
adopt_lock
);
#ifndef NDEBUG
mu_
->
locked_
=
false
;
#endif
std
::
cv_status
cvStatus
=
cv_
.
wait_for
(
lk
,
relTimeUs
);
#ifndef NDEBUG
mu_
->
locked_
=
true
;
#endif
// Release ownership of the lock as we don't want it to be unlocked when
// it goes out of scope (as we adopted the lock and didn't lock it ourselves)
lk
.
release
();
if
(
cvStatus
==
std
::
cv_status
::
timeout
)
{
return
true
;
...
...
port/win/port_win.h
浏览文件 @
a1d37602
...
...
@@ -113,29 +113,50 @@ class CondVar;
class
Mutex
{
public:
/* implicit */
Mutex
(
bool
adaptive
=
false
);
/* implicit */
Mutex
(
bool
adaptive
=
false
)
:
locked_
(
false
)
{
}
~
Mutex
();
void
Lock
();
void
Unlock
();
void
Lock
()
{
mutex_
.
lock
();
#ifndef NDEBUG
locked_
=
true
;
#endif
}
void
Unlock
()
{
#ifndef NDEBUG
locked_
=
false
;
#endif
mutex_
.
unlock
();
}
// this will assert if the mutex is not locked
// it does NOT verify that mutex is held by a calling thread
void
AssertHeld
();
void
AssertHeld
()
{
#ifndef NDEBUG
assert
(
locked_
);
#endif
}
std
::
unique_lock
<
std
::
mutex
>&
getLock
()
{
return
lock
;
}
// Mutex is move only with lock ownership transfer
Mutex
(
const
Mutex
&
)
=
delete
;
void
operator
=
(
const
Mutex
&
)
=
delete
;
private:
friend
class
CondVar
;
std
::
mutex
m_mutex
;
std
::
unique_lock
<
std
::
mutex
>
lock
;
std
::
mutex
&
getLock
()
{
return
mutex_
;
}
std
::
mutex
mutex_
;
#ifndef NDEBUG
bool
locked_
;
#endif
// No copying
Mutex
(
const
Mutex
&
);
void
operator
=
(
const
Mutex
&
);
};
class
RWMutex
{
...
...
@@ -162,13 +183,22 @@ class RWMutex {
class
CondVar
{
public:
explicit
CondVar
(
Mutex
*
mu
);
explicit
CondVar
(
Mutex
*
mu
)
:
mu_
(
mu
)
{
}
~
CondVar
();
void
Wait
();
bool
TimedWait
(
uint64_t
expiration_time
);
void
Signal
();
void
SignalAll
();
// Condition var is not copy/move constructible
CondVar
(
const
CondVar
&
)
=
delete
;
CondVar
&
operator
=
(
const
CondVar
&
)
=
delete
;
CondVar
(
CondVar
&&
)
=
delete
;
CondVar
&
operator
=
(
CondVar
&&
)
=
delete
;
private:
std
::
condition_variable
cv_
;
Mutex
*
mu_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录