Skip to content

Commit aec86c1

Browse files
author
jun01.feng
committed
[perf] delete status current path.
1 parent 88bb058 commit aec86c1

File tree

8 files changed

+34
-53
lines changed

8 files changed

+34
-53
lines changed

src/CBasic/CFuncType.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ enum class CFunctionType {
5656
* 这里这样实现,是为了符合 CStatus 类似写法
5757
* */
5858
#define CErrStatus(info) \
59-
CStatus(info, CGRAPH_GET_LOCATE) \
59+
CStatus(info) \
6060

6161
/** 返回异常信息和状态 */
6262
#define CGRAPH_RETURN_ERROR_STATUS(info) \
@@ -88,7 +88,6 @@ enum class CFunctionType {
8888
#define CGRAPH_THROW_EXCEPTION_BY_CONDITION(cond, info) \
8989
if (unlikely(cond)) { CGRAPH_THROW_EXCEPTION(info); } \
9090

91-
9291
CGRAPH_NAMESPACE_END
9392

9493
#endif //CGRAPH_CFUNCTYPE_H

src/CBasic/CStatus.h

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,14 @@ class CSTATUS {
3131
public:
3232
explicit CSTATUS() = default;
3333

34-
explicit CSTATUS(const std::string &errorInfo,
35-
const std::string &locateInfo = CGRAPH_EMPTY) {
34+
explicit CSTATUS(const std::string &errorInfo) {
3635
this->error_code_ = STATUS_ERR; // 默认的error code信息
3736
this->error_info_ = errorInfo;
38-
this->error_locate_ = locateInfo;
3937
}
4038

41-
explicit CSTATUS(int errorCode, const std::string &errorInfo,
42-
const std::string &locateInfo = CGRAPH_EMPTY) {
39+
explicit CSTATUS(int errorCode, const std::string &errorInfo) {
4340
this->error_code_ = errorCode;
4441
this->error_info_ = errorInfo;
45-
this->error_locate_ = locateInfo;
4642
}
4743

4844
CSTATUS(const CSTATUS &status) {
@@ -52,7 +48,6 @@ class CSTATUS {
5248

5349
this->error_code_ = status.error_code_;
5450
this->error_info_ = status.error_info_;
55-
this->error_locate_ = status.error_locate_;
5651
}
5752

5853
CSTATUS(const CSTATUS &&status) noexcept {
@@ -62,15 +57,13 @@ class CSTATUS {
6257

6358
this->error_code_ = status.error_code_;
6459
this->error_info_ = status.error_info_;
65-
this->error_locate_ = status.error_locate_;
6660
}
6761

6862
CSTATUS& operator=(const CSTATUS& status) {
6963
if (this->error_code_ != status.error_code_) {
7064
// 如果status是正常的话,则所有数据保持不变
7165
this->error_code_ = status.error_code_;
7266
this->error_info_ = status.error_info_;
73-
this->error_locate_ = status.error_locate_;
7467
}
7568
return (*this);
7669
}
@@ -83,7 +76,6 @@ class CSTATUS {
8376
if (!this->isErr() && cur.isErr()) {
8477
this->error_code_ = cur.error_code_;
8578
this->error_info_ = cur.error_info_;
86-
this->error_locate_ = cur.error_locate_;
8779
}
8880

8981
return (*this);
@@ -96,7 +88,6 @@ class CSTATUS {
9688
if (this->error_code_ != STATUS_OK) {
9789
this->error_code_ = STATUS_OK;
9890
this->error_info_.clear();
99-
this->error_locate_.clear();
10091
}
10192
}
10293

@@ -116,14 +107,6 @@ class CSTATUS {
116107
return this->error_info_;
117108
}
118109

119-
/**
120-
* 获取报错位置
121-
* @return
122-
*/
123-
const std::string& getLocate() const {
124-
return this->error_locate_;
125-
}
126-
127110
/**
128111
* 判断当前状态是否可行
129112
* @return
@@ -174,7 +157,6 @@ class CSTATUS {
174157
private:
175158
int error_code_ = STATUS_OK; // 错误码信息
176159
std::string error_info_; // 错误信息描述
177-
std::string error_locate_; // 错误发生的具体位置,形如:file|function|line
178160
};
179161

180162
CGRAPH_INTERNAL_NAMESPACE_END

src/GraphCtrl/GraphElement/GElement.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,13 @@ CBool GElement::isMacro() const {
344344

345345

346346
CStatus GElement::crashed(const CException& ex) {
347-
return CStatus(internal::STATUS_CRASH, ex.what(), CGRAPH_GET_LOCATE);
347+
return CStatus(internal::STATUS_CRASH, ex.what());
348348
}
349349

350350

351351
CIndex GElement::getThreadIndex() {
352352
CGRAPH_THROW_EXCEPTION_BY_CONDITION((nullptr == thread_pool_), \
353-
this->getName() + " getThreadIndex with no threadpool") // 理论不可能出现的情况
353+
this->getName() + " getThreadIndex with no thread pool") // 理论不可能出现的情况
354354

355355
auto tid = (CSize)std::hash<std::thread::id>{}(std::this_thread::get_id());
356356
return thread_pool_->getThreadIndex(tid);
@@ -561,4 +561,9 @@ GElementPtrArr GElement::getDeepPath(CBool reverse) const {
561561
return path;
562562
}
563563

564+
565+
CBool GElement::isDefaultBinding() const {
566+
return CGRAPH_DEFAULT_BINDING_INDEX == binding_index_;
567+
}
568+
564569
CGRAPH_NAMESPACE_END

src/GraphCtrl/GraphElement/GElement.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ class GElement : public GElementObject,
416416
*/
417417
std::vector<GElement *> getDeepPath(CBool reverse) const;
418418

419+
/**
420+
* 判断是否是默认绑定策略
421+
* @return
422+
*/
423+
CBool isDefaultBinding() const;
424+
419425
private:
420426
/** 状态相关信息 */
421427
CBool done_ { false }; // 判定被执行结束

src/GraphCtrl/GraphElement/GGroup/GCondition/GMultiCondition.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ CStatus GMultiCondition<type>::parallelRun() {
6464
continue; // 不满足条件,则不执行
6565
}
6666

67-
futures.emplace_back(this->thread_pool_->commit([cur] {
67+
futures.emplace_back(std::move(this->thread_pool_->commit([cur] {
6868
return cur->fatProcessor(CFunctionType::RUN);
69-
}, cur->getBindingIndex()));
69+
}, cur->binding_index_)));
7070
}
7171

7272
for (auto& fut: futures) {

src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ CVoid GDynamicEngine::process(GElementPtr element, CBool affinity) {
133133
afterElementRun(element);
134134
};
135135

136-
if (affinity
137-
&& CGRAPH_DEFAULT_BINDING_INDEX == element->getBindingIndex()) {
136+
if (affinity && element->isDefaultBinding()) {
138137
// 如果 affinity=true,表示用当前的线程,执行这个逻辑。以便增加亲和性
139138
exec();
140139
} else {
@@ -234,9 +233,9 @@ CVoid GDynamicEngine::parallelRunAll() {
234233
std::vector<std::future<CStatus>> futures;
235234
futures.reserve(total_end_size_);
236235
for (int i = 0; i < total_end_size_; i++) {
237-
futures.emplace_back(thread_pool_->commit([this, i] {
236+
futures.emplace_back(std::move(thread_pool_->commit([this, i] {
238237
return total_element_arr_[i]->fatProcessor(CFunctionType::RUN);
239-
}, calcIndex(total_element_arr_[i])));
238+
}, calcIndex(total_element_arr_[i]))));
240239
}
241240

242241
for (auto& fut : futures) {

src/GraphCtrl/GraphElement/_GEngine/GEngine.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ class GEngine : public GElementObject {
3939
* @param element
4040
* @return
4141
*/
42-
inline CIndex calcIndex(GElementPtr element) const {
42+
CIndex calcIndex(GElementCPtr element) const {
4343
/**
4444
* 如果没有设定绑定线程的话,就用默认调度策略
4545
* 否则的话,会走绑定的thread。
4646
* 如果设定的 binding_index_ >= thread 总数,会在 threadpool 层做统一判定
4747
*/
48-
auto bindingIndex = element->getBindingIndex();
49-
return CGRAPH_DEFAULT_BINDING_INDEX == bindingIndex
50-
? schedule_strategy_ : bindingIndex;
48+
return element->isDefaultBinding()
49+
? schedule_strategy_ : element->binding_index_;
5150
}
5251

5352
/**
@@ -68,7 +67,7 @@ class GEngine : public GElementObject {
6867
element->linkable_ = false; // 防止出现之前的留存逻辑。确保只有当前链接关系下,需要设置 linkable的,才会设置为 true
6968
if (1 == element->dependence_.size()
7069
&& 1 == (*element->dependence_.begin())->run_before_.size()
71-
&& element->getBindingIndex() == (*(element->dependence_.begin()))->getBindingIndex()) {
70+
&& element->binding_index_ == (*(element->dependence_.begin()))->binding_index_) {
7271
element->linkable_ = true;
7372
linked_size_++;
7473
}

src/UtilsCtrl/UtilsDefine.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ CGRAPH_NAMESPACE_BEGIN
3535
using CGRAPH_LOCK_GUARD = std::lock_guard<std::mutex>;
3636
using CGRAPH_UNIQUE_LOCK = std::unique_lock<std::mutex>;
3737

38-
/* 判断函数流程是否可以继续 */
39-
CGRAPH_INTERNAL_NAMESPACE_BEGIN
40-
static std::mutex g_check_status_mtx;
41-
static std::mutex g_echo_mtx;
42-
CGRAPH_INTERNAL_NAMESPACE_END
43-
4438
#if __cplusplus >= 201703L
4539
using CGRAPH_READ_LOCK = std::shared_lock<std::shared_mutex>;
4640
using CGRAPH_WRITE_LOCK = std::unique_lock<std::shared_mutex>;
@@ -49,7 +43,6 @@ CGRAPH_INTERNAL_NAMESPACE_END
4943
using CGRAPH_WRITE_LOCK = CGRAPH_LOCK_GUARD;
5044
#endif
5145

52-
5346
template<typename T>
5447
CStatus __ASSERT_NOT_NULL(T t) {
5548
return (unlikely(nullptr == t))
@@ -82,15 +75,13 @@ CVoid __ASSERT_NOT_NULL_THROW_EXCEPTION(T t, Args... args) {
8275
__ASSERT_NOT_NULL_THROW_EXCEPTION(args...);
8376
}
8477

85-
8678
/** 判断传入的多个指针信息,是否为空 */
8779
#define CGRAPH_ASSERT_NOT_NULL(ptr, ...) \
8880
{ \
8981
const CStatus& __cur_status__ = __ASSERT_NOT_NULL(ptr, ##__VA_ARGS__); \
9082
if (unlikely(__cur_status__.isErr())) { return __cur_status__; } \
9183
} \
9284

93-
9485
/** 判断传入的多个指针,是否为空。如果为空,则抛出异常信息 */
9586
#define CGRAPH_ASSERT_NOT_NULL_THROW_ERROR(ptr, ...) \
9687
__ASSERT_NOT_NULL_THROW_EXCEPTION(ptr, ##__VA_ARGS__); \
@@ -128,14 +119,13 @@ CVoid __ASSERT_NOT_NULL_THROW_EXCEPTION(T t, Args... args) {
128119
#define CGRAPH_SLEEP_MILLISECOND(ms) \
129120
std::this_thread::sleep_for(std::chrono::milliseconds(ms)); \
130121

131-
#define CGRAPH_FUNCTION_CHECK_STATUS \
132-
if (unlikely(status.isErr())) { \
133-
if (status.isCrash()) { throw CException(status.getInfo()); } \
134-
CGRAPH_LOCK_GUARD lock{ internal::g_check_status_mtx }; \
135-
CGRAPH_ECHO("%s, errorCode = [%d], errorInfo = [%s].", \
136-
status.getLocate().c_str(), status.getCode(), status.getInfo().c_str()); \
137-
return status; \
138-
} \
122+
#define CGRAPH_FUNCTION_CHECK_STATUS \
123+
if (unlikely(status.isErr())) { \
124+
if (status.isCrash()) { throw CException(status.getInfo()); } \
125+
CGRAPH_ECHO("errorCode = [%d], errorInfo = [%s].", \
126+
status.getCode(), status.getInfo().c_str()); \
127+
return status; \
128+
} \
139129

140130
/**
141131
* 定制化输出
@@ -148,7 +138,8 @@ inline CVoid CGRAPH_ECHO(const char *cmd, ...) {
148138
return;
149139
#endif
150140

151-
std::lock_guard<std::mutex> lock{ internal::g_echo_mtx };
141+
static std::mutex echo_mtx;
142+
std::lock_guard<std::mutex> lock{ echo_mtx };
152143
auto now = std::chrono::system_clock::now();
153144
auto time = std::chrono::system_clock::to_time_t(now);
154145
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() % 1000;

0 commit comments

Comments
 (0)