forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFence.cpp
More file actions
75 lines (55 loc) · 1.71 KB
/
GFence.cpp
File metadata and controls
75 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: GFence.cpp
@Time: 2023/9/6 21:54
@Desc:
***************************/
#include "GFence.h"
CGRAPH_NAMESPACE_BEGIN
GFence::GFence() {
element_type_ = GElementType::FENCE;
session_ = URandom<>::generateSession(CGRAPH_STR_FENCE);
}
GFencePtr GFence::waitGElement(GElementPtr element) {
CGRAPH_ASSERT_INIT_THROW_ERROR(false)
CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(element)
CGRAPH_THROW_EXCEPTION_BY_CONDITION(!element->isAsync(), \
"fence can add async element only. please set timeout value for [" + element->getName() + "] if you need.")
fence_elements_.insert(element);
return this;
}
GFencePtr GFence::waitGElements(const std::set<GElementPtr>& elements) {
CGRAPH_ASSERT_INIT_THROW_ERROR(false)
for (auto* element : elements) {
waitGElement(element);
}
return this;
}
CVoid GFence::clear() {
CGRAPH_ASSERT_INIT_THROW_ERROR(false)
fence_elements_.clear();
}
CStatus GFence::checkSuitable() {
CGRAPH_FUNCTION_BEGIN
for (auto* element : fence_elements_) {
CGRAPH_ASSERT_NOT_NULL(element)
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION(!element->isAsync(), \
"[" + element->name_ + "] is not async node. please set timeout value if you want to fence it")
}
CGRAPH_FUNCTION_END
}
CVoid GFence::dumpElement(std::ostream& oss) {
dumpElementHeader(oss);
dumpPerfInfo(oss);
oss << "\", shape=box]\n";
}
CStatus GFence::run() {
CGRAPH_FUNCTION_BEGIN
for (auto* element : fence_elements_) {
// 等待全部到达之后,判断错误信息
status += element->getAsyncResult();
}
CGRAPH_FUNCTION_END
}
CGRAPH_NAMESPACE_END