-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad957a1
commit ccbe0e4
Showing
22 changed files
with
405 additions
and
17 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
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,70 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: GStage.h | ||
@Time: 2024/12/13 19:25 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_GSTAGE_H | ||
#define CGRAPH_GSTAGE_H | ||
|
||
#include <atomic> | ||
#include <mutex> | ||
#include <condition_variable> | ||
|
||
#include "GStageObject.h" | ||
|
||
CGRAPH_NAMESPACE_BEGIN | ||
|
||
class GStage : public GStageObject { | ||
private: | ||
GStage() = default; | ||
|
||
/** | ||
* 设置阈值信息 | ||
* @param threshold | ||
* @return | ||
*/ | ||
GStage* setThreshold(CInt threshold) { | ||
threshold_ = threshold; | ||
return this; | ||
} | ||
|
||
/** | ||
* 进入等待区域 | ||
* @return | ||
*/ | ||
CVoid waiting() { | ||
{ | ||
CGRAPH_LOCK_GUARD wm(waiting_mutex_); | ||
cur_value_++; | ||
if (cur_value_ >= threshold_) { | ||
// 如果超过了 threshold,则打开全部 | ||
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_; | ||
}); | ||
} | ||
|
||
private: | ||
CInt threshold_ { 0 }; // 阈值信息 | ||
CInt cur_value_ { 0 }; // 当前值 | ||
UCvMutex locker_; | ||
std::mutex waiting_mutex_; | ||
|
||
friend class GStageManager; | ||
friend class CAllocator; | ||
}; | ||
|
||
using GStagePtr = GStage *; | ||
|
||
CGRAPH_NAMESPACE_END | ||
|
||
#endif //CGRAPH_GSTAGE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*************************** | ||
@Author: Chunel | ||
@Contact: [email protected] | ||
@File: GStageInclude.h | ||
@Time: 2024/12/15 16:52 | ||
@Desc: | ||
***************************/ | ||
|
||
#ifndef CGRAPH_GSTAGEINCLUDE_H | ||
#define CGRAPH_GSTAGEINCLUDE_H | ||
|
||
#include "GStage.h" | ||
#include "GStageManager.h" | ||
#include "GStageManagerWrapper.h" | ||
|
||
#endif //CGRAPH_GSTAGEINCLUDE_H |
Oops, something went wrong.