Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
557f43f9
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
557f43f9
编写于
8月 17, 2016
作者:
C
Chinmay Garde
提交者:
GitHub
8月 17, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add flutter::Pipeline to //synchronization. (#2939)
上级
4eeaa074
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
125 addition
and
0 deletion
+125
-0
synchronization/BUILD.gn
synchronization/BUILD.gn
+3
-0
synchronization/pipeline.cc
synchronization/pipeline.cc
+11
-0
synchronization/pipeline.h
synchronization/pipeline.h
+111
-0
未找到文件。
synchronization/BUILD.gn
浏览文件 @
557f43f9
...
...
@@ -4,11 +4,14 @@
source_set("synchronization") {
sources = [
"pipeline.cc",
"pipeline.h",
"semaphore.cc",
"semaphore.h",
]
deps = [
"//flutter/glue",
"//lib/ftl",
]
}
synchronization/pipeline.cc
0 → 100644
浏览文件 @
557f43f9
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/synchronization/pipeline.h"
namespace
flutter
{
//
}
// namespace flutter
synchronization/pipeline.h
0 → 100644
浏览文件 @
557f43f9
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SYNCHRONIZATION_PIPELINE_H_
#define SYNCHRONIZATION_PIPELINE_H_
#include "lib/ftl/macros.h"
#include "lib/ftl/synchronization/mutex.h"
#include "lib/ftl/functional/closure.h"
#include "flutter/synchronization/semaphore.h"
#include "flutter/synchronization/pipeline.h"
#include "flutter/glue/trace_event.h"
#include <memory>
#include <queue>
namespace
flutter
{
enum
class
PipelineConsumeResult
{
NoneAvailable
,
Done
,
MoreAvailable
,
};
template
<
class
R
>
class
Pipeline
{
public:
using
Resource
=
R
;
using
ResourcePtr
=
std
::
unique_ptr
<
Resource
>
;
explicit
Pipeline
(
uint32_t
depth
)
:
empty_
(
depth
),
available_
(
0
)
{}
~
Pipeline
()
{}
bool
IsValid
()
const
{
return
empty_
.
IsValid
()
&&
available_
.
IsValid
();
}
using
Producer
=
std
::
function
<
ResourcePtr
(
void
)
>
;
FTL_WARN_UNUSED_RESULT
bool
Produce
(
Producer
producer
)
{
if
(
producer
==
nullptr
)
{
return
false
;
}
if
(
!
empty_
.
TryWait
())
{
return
false
;
}
ResourcePtr
resource
;
{
TRACE_EVENT0
(
"flutter"
,
"PipelineProduce"
);
resource
=
producer
();
}
{
ftl
::
MutexLocker
lock
(
&
queue_mutex_
);
queue_
.
emplace
(
std
::
move
(
resource
));
}
available_
.
Signal
();
return
true
;
}
using
Consumer
=
std
::
function
<
void
(
ResourcePtr
)
>
;
FTL_WARN_UNUSED_RESULT
PipelineConsumeResult
Consume
(
Consumer
consumer
)
{
if
(
consumer
==
nullptr
)
{
return
PipelineConsumeResult
::
NoneAvailable
;
}
if
(
!
available_
.
TryWait
())
{
return
PipelineConsumeResult
::
NoneAvailable
;
}
ResourcePtr
resource
;
size_t
items_count
=
0
;
{
ftl
::
MutexLocker
lock
(
&
queue_mutex_
);
resource
=
std
::
move
(
queue_
.
front
());
queue_
.
pop
();
items_count
=
queue_
.
size
();
}
{
TRACE_EVENT0
(
"flutter"
,
"PipelineConsume"
);
consumer
(
std
::
move
(
resource
));
}
empty_
.
Signal
();
return
items_count
>
0
?
PipelineConsumeResult
::
MoreAvailable
:
PipelineConsumeResult
::
Done
;
}
private:
Semaphore
empty_
;
Semaphore
available_
;
ftl
::
Mutex
queue_mutex_
;
std
::
queue
<
ResourcePtr
>
queue_
;
FTL_DISALLOW_COPY_AND_ASSIGN
(
Pipeline
);
};
}
// namespace flutter
#endif // SYNCHRONIZATION_PIPELINE_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录