Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6a46022b
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6a46022b
编写于
5月 02, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use a local function.
上级
da9aaf8e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
41 deletion
+37
-41
src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs
...Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs
+37
-41
未找到文件。
src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorage_WriteBatching.cs
浏览文件 @
6a46022b
...
...
@@ -68,62 +68,58 @@ internal partial class SQLitePersistentStorage
private
async
Task
FlushSpecificWritesAsync
<
TKey
>(
SqlConnection
connection
,
MultiDictionary
<
TKey
,
Action
<
SqlConnection
>>
keyToWriteActions
,
Dictionary
<
TKey
,
Task
>
keyToWriteTask
,
TKey
key
,
Dictionary
<
TKey
,
Task
>
keyToWriteTask
,
TKey
key
,
ArrayBuilder
<
Action
<
SqlConnection
>>
writesToProcess
,
CancellationToken
cancellationToken
)
{
// Get the task that is responsible for doing the writes for this queue.
// This task will complete when all previously enqueued writes for this queue
// complete, and all the currently enqueued writes for this queue complete as well.
var
writeTask
=
await
GetWriteTask
(
connection
,
keyToWriteActions
,
keyToWriteTask
,
key
,
writesToProcess
,
cancellationToken
).
ConfigureAwait
(
false
);
var
writeTask
=
await
GetWriteTask
().
ConfigureAwait
(
false
);
await
writeTask
.
ConfigureAwait
(
false
);
}
private
async
Task
<
Task
>
GetWriteTask
<
TKey
>(
SqlConnection
connection
,
MultiDictionary
<
TKey
,
Action
<
SqlConnection
>>
keyToWriteActions
,
Dictionary
<
TKey
,
Task
>
keyToWriteTask
,
TKey
key
,
ArrayBuilder
<
Action
<
SqlConnection
>>
writesToProcess
,
CancellationToken
cancellationToken
)
{
// Have to acqure the semaphore. We're going to mutate the shared 'keyToWriteActions' and
// 'keyToWriteTask' collections.
using
(
await
_writeQueueGate
.
DisposableWaitAsync
(
cancellationToken
).
ConfigureAwait
(
false
))
return
;
// Local functions
async
Task
<
Task
>
GetWriteTask
()
{
// Get the writes we need to process.
writesToProcess
.
AddRange
(
keyToWriteActions
[
key
]);
// Have to acquire the semaphore. We're going to mutate the shared 'keyToWriteActions'
// and 'keyToWriteTask' collections.
using
(
await
_writeQueueGate
.
DisposableWaitAsync
(
cancellationToken
).
ConfigureAwait
(
false
))
{
// Get the writes we need to process.
writesToProcess
.
AddRange
(
keyToWriteActions
[
key
]);
// and clear them from the queues so we don't process things multiple times.
keyToWriteActions
.
Remove
(
key
);
// and clear them from the queues so we don't process things multiple times.
keyToWriteActions
.
Remove
(
key
);
// Find the existing task responsible for writing to this queue.
var
existingWriteTask
=
keyToWriteTask
.
TryGetValue
(
key
,
out
var
task
)
?
task
:
SpecializedTasks
.
EmptyTask
;
// Find the existing task responsible for writing to this queue.
var
existingWriteTask
=
keyToWriteTask
.
TryGetValue
(
key
,
out
var
task
)
?
task
:
SpecializedTasks
.
EmptyTask
;
if
(
writesToProcess
.
Count
==
0
)
{
// We have no writes of our own. But there may be an existing task that
// is writing out this queue. Return this so our caller can wait for
// all existing writes to complete.
return
existingWriteTask
;
}
if
(
writesToProcess
.
Count
==
0
)
{
// We have no writes of our own. But there may be an existing task that
// is writing out this queue. Return this so our caller can wait for
// all existing writes to complete.
return
existingWriteTask
;
}
// We have our own writes to process. Enqueue the task to write
// these out after the existing write-task for this queue completes.
var
nextTask
=
existingWriteTask
.
ContinueWith
(
_
=>
ProcessWriteQueue
(
connection
,
writesToProcess
),
cancellationToken
,
TaskContinuationOptions
.
RunContinuationsAsynchronously
,
TaskScheduler
.
Default
);
// We have our own writes to process. Enqueue the task to write
// these out after the existing write-task for this queue completes.
var
nextTask
=
existingWriteTask
.
ContinueWith
(
_
=>
ProcessWriteQueue
(
connection
,
writesToProcess
),
cancellationToken
,
TaskContinuationOptions
.
RunContinuationsAsynchronously
,
TaskScheduler
.
Default
);
// Store this for the next flush call to see.
keyToWriteTask
[
key
]
=
nextTask
;
// Store this for the next flush call to see.
keyToWriteTask
[
key
]
=
nextTask
;
// And return this to our caller so it can 'await' all these writes completing.
return
nextTask
;
// And return this to our caller so it can 'await' all these writes completing.
return
nextTask
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录