-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] optimize stage function, with template stage.
- Loading branch information
1 parent
ccbe0e4
commit 772818c
Showing
12 changed files
with
156 additions
and
39 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 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
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,52 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: GStage.cpp | ||
@Time: 2024/12/28 23:02 | ||
@Desc: | ||
***************************/ | ||
|
||
#include "GStage.h" | ||
|
||
CGRAPH_NAMESPACE_BEGIN | ||
|
||
CVoid GStage::launch(GStageParamPtr param) { | ||
} | ||
|
||
|
||
GStage::GStage() { | ||
session_ = URandom<>::generateSession(CGRAPH_STR_STAGE); | ||
} | ||
|
||
|
||
GStage::~GStage() { | ||
CGRAPH_DELETE_PTR(param_); | ||
} | ||
|
||
|
||
GStagePtr GStage::setThreshold(CInt threshold) { | ||
threshold_ = threshold; | ||
return this; | ||
} | ||
|
||
|
||
CVoid GStage::waiting() { | ||
{ | ||
CGRAPH_LOCK_GUARD wm(waiting_mutex_); | ||
cur_value_++; | ||
if (cur_value_ >= threshold_) { | ||
// 如果超过了 threshold,则打开全部 | ||
launch(param_); | ||
cur_value_ = 0; | ||
locker_.cv_.notify_all(); | ||
return; | ||
} | ||
} | ||
|
||
CGRAPH_UNIQUE_LOCK lk(locker_.mtx_); | ||
locker_.cv_.wait(lk, [this] { | ||
return 0 == cur_value_ || cur_value_ >= threshold_; | ||
}); | ||
} | ||
|
||
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
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,30 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: GStage.inl | ||
@Time: 2024/12/30 9:46 下午 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_GSTAGE_INL | ||
#define CGRAPH_GSTAGE_INL | ||
|
||
#include "GStage.h" | ||
|
||
CGRAPH_NAMESPACE_BEGIN | ||
|
||
template <typename T, | ||
c_enable_if_t<std::is_base_of<GStageParam, T>::value, int>> | ||
GStagePtr GStage::setSParam(T* param) { | ||
if (param) { | ||
CGRAPH_DELETE_PTR(param_); | ||
param_ = CGRAPH_SAFE_MALLOC_COBJECT(T); | ||
param_->clone(static_cast<T *>(param)); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
CGRAPH_NAMESPACE_END | ||
|
||
#endif //CGRAPH_GSTAGE_INL |
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