-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[perf] add element repo class, to store all elements
- Loading branch information
1 parent
ab23535
commit 17f2711
Showing
10 changed files
with
170 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: chunel@foxmail.com | ||
@File: GElementRepository.cpp | ||
@Time: 2023/6/24 17:51 | ||
@Desc: | ||
***************************/ | ||
|
||
#include "GElementRepository.h" | ||
|
||
CGRAPH_NAMESPACE_BEGIN | ||
|
||
CVoid GElementRepository::insert(GElementPtr ptr) { | ||
if (nullptr != ptr) { | ||
elements_.insert(ptr); | ||
} | ||
} | ||
|
||
|
||
CBool GElementRepository::find(GElementPtr ptr) { | ||
if (nullptr == ptr) { | ||
return false; | ||
} | ||
return elements_.find(ptr) != elements_.end(); | ||
} | ||
|
||
|
||
GElementRepositoryPtr GElementRepository::setThreadPool(UThreadPoolPtr ptr) { | ||
CGRAPH_ASSERT_NOT_NULL_RETURN_NULL(ptr) | ||
for (auto& cur : this->elements_) { | ||
cur->setThreadPool(ptr); | ||
} | ||
return this; | ||
} | ||
|
||
|
||
CStatus GElementRepository::setup() { | ||
CGRAPH_FUNCTION_BEGIN | ||
if (elements_.empty() | ||
|| GElementState::NORMAL != (*elements_.begin())->cur_state_.load()) { | ||
return status; | ||
} | ||
|
||
status = pushAllState(GElementState::NORMAL); | ||
CGRAPH_FUNCTION_END | ||
} | ||
|
||
|
||
CStatus GElementRepository::pushAllState(GElementState state) { | ||
CGRAPH_FUNCTION_BEGIN | ||
|
||
for (auto* cur : elements_) { | ||
cur->cur_state_.store(state); | ||
if (GElementState::YIELD != state) { | ||
// 目前仅非yield状态,需要切换的。如果一直处于 yield状态,是不需要被通知的 | ||
cur->yield_cv_.notify_one(); | ||
} | ||
} | ||
CGRAPH_FUNCTION_END | ||
} | ||
|
||
|
||
GElementRepository::~GElementRepository() { | ||
// 删除所有内部的element信息 | ||
for (GElementPtr element : elements_) { | ||
CGRAPH_DELETE_PTR(element) | ||
} | ||
} | ||
|
||
|
||
CStatus GElementRepository::run() { | ||
CGRAPH_NO_SUPPORT | ||
} | ||
|
||
CGRAPH_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: chunel@foxmail.com | ||
@File: GElementRepository.h | ||
@Time: 2023/6/24 16:42 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_GELEMENTREPOSITORY_H | ||
#define CGRAPH_GELEMENTREPOSITORY_H | ||
|
||
#include "GElementObject.h" | ||
#include "GElement.h" | ||
|
||
CGRAPH_NAMESPACE_BEGIN | ||
|
||
class GElementRepository : public GElementObject { | ||
private: | ||
/** | ||
* 插入一个element | ||
* @param ptr | ||
* @return | ||
*/ | ||
CVoid insert(GElementPtr ptr); | ||
|
||
/** | ||
* 查找对应的element | ||
* @param ptr | ||
* @return | ||
*/ | ||
CBool find(GElementPtr ptr); | ||
|
||
/** | ||
* 给所有的element,设定线程池 | ||
* @param ptr | ||
* @return | ||
*/ | ||
GElementRepository* setThreadPool(UThreadPoolPtr ptr); | ||
|
||
/** | ||
* 准备执行流程 | ||
* @return | ||
*/ | ||
CStatus setup(); | ||
|
||
/** | ||
* 设置所有内部的element状态 | ||
* @param state | ||
* @return | ||
*/ | ||
CStatus pushAllState(GElementState state); | ||
|
||
~GElementRepository() override; | ||
|
||
CStatus run() override; | ||
|
||
private: | ||
GElementPtrSet elements_; // 用于记录所有的element信息 | ||
|
||
friend class GPipeline; | ||
}; | ||
|
||
using GElementRepositoryPtr = GElementRepository *; | ||
|
||
CGRAPH_NAMESPACE_END | ||
|
||
#endif //CGRAPH_GELEMENTREPOSITORY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.